[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1][ 14/21] qapi: add QMP dispatch functions
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH v1][ 14/21] qapi: add QMP dispatch functions |
Date: |
Wed, 1 Jun 2011 12:24:42 -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 | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 73 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..e70af7d
--- /dev/null
+++ b/qapi/qmp-dispatch.c
@@ -0,0 +1,73 @@
+#include "qemu-objects.h"
+#include "qapi/qmp-core.h"
+#include "json-parser.h"
+
+static QObject *qmp_dispatch_err(QObject *request, Error **errp)
+{
+ const char *command;
+ QDict *args, *dict;
+ QmpCommand *cmd;
+ QObject *ret = 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(args, &ret, errp);
+ if (ret == NULL) {
+ ret = QOBJECT(qdict_new());
+ }
+ break;
+ }
+
+ QDECREF(args);
+
+out:
+
+ return ret;
+}
+
+QObject *qmp_dispatch(QObject *request)
+{
+ Error *err = NULL;
+ QObject *ret;
+ QDict *rsp;
+
+ ret = qmp_dispatch_err(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][ 21/21] qapi: add QAPI code generation documentation, (continued)
- [Qemu-devel] [PATCH v1][ 21/21] qapi: add QAPI code generation documentation, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 08/21] qapi: add qapi-types-core.h, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 20/21] qapi: Makefile changes to build test-qmp-commands, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 02/21] qlist: add qlist_first()/qlist_next(), Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 01/21] Add hard build dependency on glib, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 07/21] qapi: add qapi-commands.py code generator, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 03/21] qapi: add module init types for qapi, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 13/21] qapi: add command registration/lookup functions, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 04/21] qapi: add ordereddict/qapi.py helper libraries, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 14/21] qapi: add QMP dispatch functions,
Michael Roth <=
- [Qemu-devel] [PATCH v1][ 12/21] qapi: add QAPI dealloc visiter, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 19/21] qapi: add test-qmp-commands, tests for gen. marshalling/dispatch code, Michael Roth, 2011/06/01