@@ -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);
@@ -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);
@@ -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)