diff mbox

[PULL,10/18] monitor: implement 'qmp_query_commands' without qmp_cmds

Message ID 1474303294-13952-11-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Sept. 19, 2016, 4:41 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

One step towards getting rid of the static qmp_cmds table.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20160912091913.15831-11-marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 monitor.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 6e0ae81..f50aa6e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -957,21 +957,28 @@  static void hmp_info_help(Monitor *mon, const QDict *qdict)
     help_cmd(mon, "info");
 }
 
+static void query_commands_cb(QmpCommand *cmd, void *opaque)
+{
+    CommandInfoList *info, **list = opaque;
+
+    if (!cmd->enabled) {
+        return;
+    }
+
+    info = g_malloc0(sizeof(*info));
+    info->value = g_malloc0(sizeof(*info->value));
+    info->value->name = g_strdup(cmd->name);
+    info->next = *list;
+    *list = info;
+}
+
 CommandInfoList *qmp_query_commands(Error **errp)
 {
-    CommandInfoList *info, *cmd_list = NULL;
-    const mon_cmd_t *cmd;
+    CommandInfoList *list = NULL;
 
-    for (cmd = qmp_cmds; cmd->name != NULL; cmd++) {
-        info = g_malloc0(sizeof(*info));
-        info->value = g_malloc0(sizeof(*info->value));
-        info->value->name = g_strdup(cmd->name);
+    qmp_for_each_command(query_commands_cb, &list);
 
-        info->next = cmd_list;
-        cmd_list = info;
-    }
-
-    return cmd_list;
+    return list;
 }
 
 EventInfoList *qmp_query_events(Error **errp)