[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 13/38] qga: process_event() simplification
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v3 13/38] qga: process_event() simplification |
Date: |
Mon, 26 Mar 2018 17:08:51 +0200 |
Simplify the code around qmp_dispatch().
Make qmp_dispatch_check_obj() a pre-requirement, same as qemu monitor.
Have a single send_response() point.
Signed-off-by: Marc-André Lureau <address@hidden>
---
qga/main.c | 67 +++++++++++++++++++-----------------------------------
1 file changed, 23 insertions(+), 44 deletions(-)
diff --git a/qga/main.c b/qga/main.c
index df1888edc1..71468e68c2 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -579,67 +579,46 @@ static int send_response(GAState *s, QObject *payload)
return 0;
}
-static void process_command(GAState *s, QDict *req)
-{
- QObject *rsp = NULL;
- int ret;
-
- g_assert(req);
- g_debug("processing command");
- rsp = qmp_dispatch(&ga_commands, QOBJECT(req));
- if (rsp) {
- ret = send_response(s, rsp);
- if (ret < 0) {
- g_warning("error sending response: %s", strerror(-ret));
- }
- qobject_decref(rsp);
- }
-}
-
/* handle requests/control events coming in over the channel */
static void process_event(JSONMessageParser *parser, GQueue *tokens)
{
GAState *s = container_of(parser, GAState, parser);
- QDict *qdict;
+ QObject *req, *rsp = NULL;
Error *err = NULL;
int ret;
g_assert(s && parser);
g_debug("process_event: called");
- qdict = qobject_to(QDict, json_parser_parse_err(tokens, NULL, &err));
- if (err || !qdict) {
- QDECREF(qdict);
- qdict = qdict_new();
- if (!err) {
- g_warning("failed to parse event: unknown error");
- error_setg(&err, QERR_JSON_PARSING);
- } else {
- g_warning("failed to parse event: %s", error_get_pretty(err));
- }
+
+ req = json_parser_parse_err(tokens, NULL, &err);
+ if (err) {
+ goto end;
+ }
+
+ qmp_dispatch_check_obj(req, &err);
+ if (err) {
+ goto end;
+ }
+
+ g_debug("processing command");
+ rsp = qmp_dispatch(&ga_commands, req);
+
+end:
+ if (err) {
+ QDict *qdict = qdict_new();
qdict_put_obj(qdict, "error", qmp_build_error_object(err));
error_free(err);
+ rsp = QOBJECT(qdict);
}
-
- /* handle host->guest commands */
- if (qdict_haskey(qdict, "execute")) {
- process_command(s, qdict);
- } else {
- if (!qdict_haskey(qdict, "error")) {
- QDECREF(qdict);
- qdict = qdict_new();
- g_warning("unrecognized payload format");
- error_setg(&err, QERR_UNSUPPORTED);
- qdict_put_obj(qdict, "error", qmp_build_error_object(err));
- error_free(err);
- }
- ret = send_response(s, QOBJECT(qdict));
+ if (rsp) {
+ ret = send_response(s, rsp);
if (ret < 0) {
g_warning("error sending error response: %s", strerror(-ret));
}
+ qobject_decref(rsp);
}
-
- QDECREF(qdict);
+ qobject_decref(req);
}
/* false return signals GAChannel to close the current client connection */
--
2.17.0.rc1.1.g4c4f2b46a3
- [Qemu-devel] [PATCH v3 03/38] Revert "qmp: isolate responses into io thread", (continued)
- [Qemu-devel] [PATCH v3 03/38] Revert "qmp: isolate responses into io thread", Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 04/38] monitor: no need to save need_resume, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 02/38] qmp-shell: learn to send commands with quoted arguments, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 01/38] HACK: add back OOB, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 06/38] monitor: no need to remove desc before replacing it, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 05/38] monitor: further simplify previous patch, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 09/38] json: remove useless return value from lexer/parser, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 08/38] json-lexer: make it safe to call multiple times, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 07/38] json-parser: always set an error if return NULL, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 10/38] tests: add a few qemu-qmp tests, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 13/38] qga: process_event() simplification,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v3 14/38] monitor: simplify monitor_qmp_respond(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 11/38] tests: change /0.15/* tests to /qmp/*, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 12/38] tests: add a qmp success-response test, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 15/38] qmp: pass and return a QDict to qmp_dispatch(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 17/38] qmp: constify qmp_is_oob(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 16/38] qmp: move 'id' copy to qmp_dispatch(), Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 18/38] qmp: add QmpSession, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 20/38] QmpSession: add json parser and use it in qga, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 19/38] QmpSession: add a return_cb, Marc-André Lureau, 2018/03/26
- [Qemu-devel] [PATCH v3 21/38] QmpSession: add a dispatch callback, Marc-André Lureau, 2018/03/26