[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1][ 17/23] qapi: add QMP dispatch functions
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH v1][ 17/23] qapi: add QMP dispatch functions |
Date: |
Tue, 17 May 2011 19:52:04 -0500 |
Given an object recieved via QMP, this code uses the dispatch table
provided by qmp_registry.c to call the corresponding marshalling/dispatch
function and format return values/errors for delivery to the QMP.
Currently only synchronous QMP functions are supported, but this will
also be used for async QMP functions and QMP guest proxy dispatch as
well.
Signed-off-by: Michael Roth <address@hidden>
---
qapi/qmp-dispatch.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 104 insertions(+), 0 deletions(-)
create mode 100644 qapi/qmp-dispatch.c
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
new file mode 100644
index 0000000..733decf
--- /dev/null
+++ b/qapi/qmp-dispatch.c
@@ -0,0 +1,104 @@
+#include <glib.h>
+#include "qemu-objects.h"
+#include "qapi/qmp-core.h"
+#include "json-parser.h"
+
+static QObject *qmp_dispatch_err(QmpState *state, QObject *request, Error
**errp)
+{
+ const char *command;
+ QDict *args, *dict;
+ //QObject *request;
+ QmpCommand *cmd;
+ QObject *ret = NULL;
+ //Error *err = NULL;
+
+ if (qobject_type(request) != QTYPE_QDICT) {
+ error_set(errp, QERR_JSON_PARSE_ERROR, "request is not a dictionary");
+ goto out;
+ }
+
+ dict = qobject_to_qdict(request);
+ if (!qdict_haskey(dict, "execute")) {
+ error_set(errp, QERR_JSON_PARSE_ERROR, "no execute key");
+ goto out;
+ }
+
+ command = qdict_get_str(dict, "execute");
+ cmd = qmp_find_command(command);
+ if (cmd == NULL) {
+ error_set(errp, QERR_COMMAND_NOT_FOUND, command);
+ goto out;
+ }
+
+ if (!qdict_haskey(dict, "arguments")) {
+ args = qdict_new();
+ } else {
+ args = qdict_get_qdict(dict, "arguments");
+ QINCREF(args);
+ }
+
+ switch (cmd->type) {
+ case QCT_NORMAL:
+ cmd->fn(state, args, &ret, errp);
+ if (ret == NULL) {
+ ret = QOBJECT(qdict_new());
+ }
+ break;
+ case QCT_ASYNC: {
+ QmpCommandState *s = qemu_mallocz(sizeof(*s));
+ // FIXME save async commands and do something
+ // smart if disconnect occurs before completion
+ s->state = state;
+ s->tag = NULL;
+ if (qdict_haskey(dict, "tag")) {
+ s->tag = qdict_get(dict, "tag");
+ qobject_incref(s->tag);
+ }
+ cmd->afn(args, errp, s);
+ ret = NULL;
+ }
+ break;
+ case QCT_PROXY: {
+ QmpCommandState *s = qemu_mallocz(sizeof(*s));
+ // FIXME save async commands and do something
+ // smart if disconnect occurs before completion
+ s->state = state;
+ s->tag = NULL;
+ if (qdict_haskey(dict, "tag")) {
+ s->tag = qdict_get(dict, "tag");
+ qobject_incref(s->tag);
+ }
+ cmd->pfn(args, errp, s);
+ ret = NULL;
+ }
+ break;
+ }
+
+ QDECREF(args);
+
+out:
+
+ return ret;
+}
+
+QObject *qmp_dispatch(QmpState *state, QObject *request)
+{
+ Error *err = NULL;
+ QObject *ret;
+ QDict *rsp;
+
+ ret = qmp_dispatch_err(state, request, &err);
+
+ rsp = qdict_new();
+ if (err) {
+ qdict_put_obj(rsp, "error", error_get_qobject(err));
+ error_free(err);
+ } else if (ret) {
+ qdict_put_obj(rsp, "return", ret);
+ } else {
+ QDECREF(rsp);
+ return NULL;
+ }
+
+ return QOBJECT(rsp);
+}
--
1.7.0.4
- [Qemu-devel] [PATCH v1][ 09/23] qapi: add qapi-visit.py code generator, (continued)
- [Qemu-devel] [PATCH v1][ 09/23] qapi: add qapi-visit.py code generator, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 10/23] qapi: add qapi-commands.py code generator, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 11/23] qapi: add qapi-types-core.h, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 12/23] qapi: add qapi-visit-core.h, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 15/23] qapi: add QAPI dealloc visiter, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 13/23] qapi: add QMP input visiter, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 16/23] qapi: add command registration/lookup functions, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 14/23] qapi: add QMP output visiter, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 17/23] qapi: add QMP dispatch functions,
Michael Roth <=
- [Qemu-devel] [PATCH v1][ 19/23] qapi: test schema used for unit tests, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 20/23] qapi: add test-visiter, tests for gen. visiter code, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 21/23] qapi: Makefile changes to build test-visiter, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 18/23] qapi: add base declaration/types for QMP, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 22/23] qapi: add test-qmp-commands, tests for gen. marshalling/dispatch code, Michael Roth, 2011/05/17
- [Qemu-devel] [PATCH v1][ 23/23] qapi: Makefile changes to build test-qmp-commands, Michael Roth, 2011/05/17
- Re: [Qemu-devel] [PATCH v1 00/23] QAPI Infrastructure Round 1, Luiz Capitulino, 2011/05/18