[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 25/36] qmp: introduce async command type
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH 25/36] qmp: introduce async command type |
Date: |
Fri, 25 Sep 2015 16:03:53 +0200 |
From: Marc-André Lureau <address@hidden>
Learn a new type of command, QmpCommandFuncAsync. They can return later
thanks to QmpReturn. This commit introduces the new types and register
functions.
Signed-off-by: Marc-André Lureau <address@hidden>
---
include/qapi/qmp/dispatch.h | 5 +++++
qapi/qmp-dispatch.c | 3 +++
qapi/qmp-registry.c | 26 ++++++++++++++++++++++----
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h
index 747fff9..e45ab9f 100644
--- a/include/qapi/qmp/dispatch.h
+++ b/include/qapi/qmp/dispatch.h
@@ -36,10 +36,12 @@ struct QmpClient {
};
typedef void (QmpCommandFunc)(QDict *, QObject **, Error **);
+typedef void (QmpCommandFuncAsync)(QDict *, QmpReturn *);
typedef enum QmpCommandType
{
QCT_NORMAL,
+ QCT_ASYNC,
} QmpCommandType;
typedef enum QmpCommandOptions
@@ -53,6 +55,7 @@ typedef struct QmpCommand
const char *name;
QmpCommandType type;
QmpCommandFunc *fn;
+ QmpCommandFuncAsync *fn_async;
QmpCommandOptions options;
QTAILQ_ENTRY(QmpCommand) node;
bool enabled;
@@ -60,6 +63,8 @@ typedef struct QmpCommand
void qmp_register_command(const char *name, QmpCommandFunc *fn,
QmpCommandOptions options);
+void qmp_register_async_command(const char *name, QmpCommandFuncAsync *fn,
+ QmpCommandOptions options);
QmpCommand *qmp_find_command(const char *name);
void qmp_client_init(QmpClient *client, QmpDispatchReturn *return_cb);
void qmp_client_destroy(QmpClient *client);
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index d2cc300..83ecab5 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -104,6 +104,9 @@ static QObject *do_qmp_dispatch(QObject *request, QmpReturn
*qret, Error **errp)
ret = QOBJECT(qdict_new());
}
break;
+ case QCT_ASYNC:
+ cmd->fn_async(args, qret);
+ break;
}
QDECREF(args);
diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c
index 3e4498a..90f6a8c 100644
--- a/qapi/qmp-registry.c
+++ b/qapi/qmp-registry.c
@@ -19,17 +19,35 @@
static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
QTAILQ_HEAD_INITIALIZER(qmp_commands);
-void qmp_register_command(const char *name, QmpCommandFunc *fn,
- QmpCommandOptions options)
+static QmpCommand *qmp_command_new(const char *name,
+ QmpCommandOptions options)
{
QmpCommand *cmd = g_malloc0(sizeof(*cmd));
cmd->name = name;
- cmd->type = QCT_NORMAL;
- cmd->fn = fn;
cmd->enabled = true;
cmd->options = options;
QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
+
+ return cmd;
+}
+
+void qmp_register_command(const char *name, QmpCommandFunc *fn,
+ QmpCommandOptions options)
+{
+ QmpCommand *cmd = qmp_command_new(name, options);
+
+ cmd->type = QCT_NORMAL;
+ cmd->fn = fn;
+}
+
+void qmp_register_async_command(const char *name, QmpCommandFuncAsync *fn,
+ QmpCommandOptions options)
+{
+ QmpCommand *cmd = qmp_command_new(name, options);
+
+ cmd->type = QCT_ASYNC;
+ cmd->fn_async = fn;
}
QmpCommand *qmp_find_command(const char *name)
--
2.4.3
- [Qemu-devel] [PATCH 05/36] qapi: move examples to json schema, (continued)
- [Qemu-devel] [PATCH 05/36] qapi: move examples to json schema, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 17/36] qmp: use qmp_dispatch(), marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 23/36] qmp: use a return callback for the command reply, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 20/36] qmp: remove old qmp-commands table, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 22/36] qmp: teach qmp_dispatch() to take a pre-filled QDict, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 24/36] qmp: add QmpClient, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 26/36] qmp: check that async command have an 'id', marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 27/36] scripts: learn 'async' qapi commands, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 25/36] qmp: introduce async command type,
marcandre . lureau <=
- [Qemu-devel] [PATCH 28/36] scripts: ensure -async commands are declared async, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 30/36] tests: change /0.15/* tests to /qmp/*, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 31/36] tests: add /qmp/dispatch_cmd_async test, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 29/36] qapi: take 'id' from request, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 34/36] console: graphic_hw_update return true if async, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 35/36] console: add graphic_hw_update_done(), marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 33/36] monitor: add 'async' capability, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 32/36] qmp: update qmp-spec about async capability, marcandre . lureau, 2015/09/25
- [Qemu-devel] [PATCH 36/36] console: add screendump-async, marcandre . lureau, 2015/09/25