aboutsummaryrefslogtreecommitdiff
path: root/qapi
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-03-03 13:32:25 +0100
committerMarkus Armbruster <armbru@redhat.com>2017-03-05 09:12:25 +0100
commit1527badb954f2d8c17b86e2a258812def5ea3dcc (patch)
tree115c03868efbc08b8149dc738ac0f19be5138ae6 /qapi
parent05875687806b71ae980ca59a46777b742b20ac06 (diff)
qapi: Support multiple command registries per program
The command registry encapsulates a single command list. Give the functions using it a parameter instead. Define suitable command lists in monitor, guest agent and test-qmp-commands. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1488544368-30622-6-git-send-email-armbru@redhat.com> [Debugging turds buried] Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'qapi')
-rw-r--r--qapi/qmp-dispatch.c9
-rw-r--r--qapi/qmp-registry.c37
2 files changed, 23 insertions, 23 deletions
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index 621922ffa2..72827a30ba 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -67,7 +67,8 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
return dict;
}
-static QObject *do_qmp_dispatch(QObject *request, Error **errp)
+static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request,
+ Error **errp)
{
Error *local_err = NULL;
const char *command;
@@ -81,7 +82,7 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp)
}
command = qdict_get_str(dict, "execute");
- cmd = qmp_find_command(command);
+ cmd = qmp_find_command(cmds, command);
if (cmd == NULL) {
error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
"The command %s has not been found", command);
@@ -121,13 +122,13 @@ QObject *qmp_build_error_object(Error *err)
error_get_pretty(err));
}
-QObject *qmp_dispatch(QObject *request)
+QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request)
{
Error *err = NULL;
QObject *ret;
QDict *rsp;
- ret = do_qmp_dispatch(request, &err);
+ ret = do_qmp_dispatch(cmds, request, &err);
rsp = qdict_new();
if (err) {
diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c
index e8053686f3..5af484cd9a 100644
--- a/qapi/qmp-registry.c
+++ b/qapi/qmp-registry.c
@@ -15,11 +15,8 @@
#include "qemu/osdep.h"
#include "qapi/qmp/dispatch.h"
-static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
- QTAILQ_HEAD_INITIALIZER(qmp_commands);
-
-void qmp_register_command(const char *name, QmpCommandFunc *fn,
- QmpCommandOptions options)
+void qmp_register_command(QmpCommandList *cmds, const char *name,
+ QmpCommandFunc *fn, QmpCommandOptions options)
{
QmpCommand *cmd = g_malloc0(sizeof(*cmd));
@@ -27,22 +24,22 @@ void qmp_register_command(const char *name, QmpCommandFunc *fn,
cmd->fn = fn;
cmd->enabled = true;
cmd->options = options;
- QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
+ QTAILQ_INSERT_TAIL(cmds, cmd, node);
}
-void qmp_unregister_command(const char *name)
+void qmp_unregister_command(QmpCommandList *cmds, const char *name)
{
- QmpCommand *cmd = qmp_find_command(name);
+ QmpCommand *cmd = qmp_find_command(cmds, name);
- QTAILQ_REMOVE(&qmp_commands, cmd, node);
+ QTAILQ_REMOVE(cmds, cmd, node);
g_free(cmd);
}
-QmpCommand *qmp_find_command(const char *name)
+QmpCommand *qmp_find_command(QmpCommandList *cmds, const char *name)
{
QmpCommand *cmd;
- QTAILQ_FOREACH(cmd, &qmp_commands, node) {
+ QTAILQ_FOREACH(cmd, cmds, node) {
if (strcmp(cmd->name, name) == 0) {
return cmd;
}
@@ -50,11 +47,12 @@ QmpCommand *qmp_find_command(const char *name)
return NULL;
}
-static void qmp_toggle_command(const char *name, bool enabled)
+static void qmp_toggle_command(QmpCommandList *cmds, const char *name,
+ bool enabled)
{
QmpCommand *cmd;
- QTAILQ_FOREACH(cmd, &qmp_commands, node) {
+ QTAILQ_FOREACH(cmd, cmds, node) {
if (strcmp(cmd->name, name) == 0) {
cmd->enabled = enabled;
return;
@@ -62,14 +60,14 @@ static void qmp_toggle_command(const char *name, bool enabled)
}
}
-void qmp_disable_command(const char *name)
+void qmp_disable_command(QmpCommandList *cmds, const char *name)
{
- qmp_toggle_command(name, false);
+ qmp_toggle_command(cmds, name, false);
}
-void qmp_enable_command(const char *name)
+void qmp_enable_command(QmpCommandList *cmds, const char *name)
{
- qmp_toggle_command(name, true);
+ qmp_toggle_command(cmds, name, true);
}
bool qmp_command_is_enabled(const QmpCommand *cmd)
@@ -87,11 +85,12 @@ bool qmp_has_success_response(const QmpCommand *cmd)
return !(cmd->options & QCO_NO_SUCCESS_RESP);
}
-void qmp_for_each_command(qmp_cmd_callback_fn fn, void *opaque)
+void qmp_for_each_command(QmpCommandList *cmds, qmp_cmd_callback_fn fn,
+ void *opaque)
{
QmpCommand *cmd;
- QTAILQ_FOREACH(cmd, &qmp_commands, node) {
+ QTAILQ_FOREACH(cmd, cmds, node) {
fn(cmd, opaque);
}
}