diff mbox

[v2,07/12] monitor: implement 'qmp_query_commands' without qmp_cmds

Message ID 20160721140030.28383-8-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau July 21, 2016, 2 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

So we can get rid of the static qmp_cmds table.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 monitor.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

Comments

Eric Blake July 21, 2016, 10:51 p.m. UTC | #1
On 07/21/2016 08:00 AM, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> So we can get rid of the static qmp_cmds table.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  monitor.c | 32 ++++++++++++++------------------
>  1 file changed, 14 insertions(+), 18 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Markus Armbruster Aug. 5, 2016, 1:25 p.m. UTC | #2
marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> So we can get rid of the static qmp_cmds table.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  monitor.c | 32 ++++++++++++++------------------
>  1 file changed, 14 insertions(+), 18 deletions(-)
>
> diff --git a/monitor.c b/monitor.c
> index 642be2e..bd41b4b 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -229,8 +229,6 @@ static int mon_refcount;
>  static mon_cmd_t mon_cmds[];
>  static mon_cmd_t info_cmds[];
>  
> -static const mon_cmd_t qmp_cmds[];
> -
>  Monitor *cur_mon;
>  
>  static QEMUClockType event_clock_type = QEMU_CLOCK_REALTIME;
> @@ -947,21 +945,24 @@ static void hmp_info_help(Monitor *mon, const QDict *qdict)
>      help_cmd(mon, "info");
>  }
>  
> -CommandInfoList *qmp_query_commands(Error **errp)
> +static void query_commands_cb(QmpCommand *cmd, void *opaque)
>  {
> -    CommandInfoList *info, *cmd_list = NULL;
> -    const mon_cmd_t *cmd;
> +    CommandInfoList *info, **list = opaque;
>  
> -    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);
> +    info = g_malloc0(sizeof(*info));
> +    info->value = g_malloc0(sizeof(*info->value));
> +    info->value->name = g_strdup(cmd->name);
> +    info->next = *list;
> +    *list = info;
> +}
>  
> -        info->next = cmd_list;
> -        cmd_list = info;
> -    }
> +CommandInfoList *qmp_query_commands(Error **errp)
> +{
> +    CommandInfoList *list = NULL;
>  
> -    return cmd_list;
> +    qmp_for_each_command(query_commands_cb, &list);
> +
> +    return list;
>  }
>  
>  EventInfoList *qmp_query_events(Error **errp)
> @@ -2166,11 +2167,6 @@ static mon_cmd_t mon_cmds[] = {
>      { NULL, NULL, },
>  };
>  
> -static const mon_cmd_t qmp_cmds[] = {
> -#include "qmp-commands-old.h"
> -    { /* NULL */ },
> -};
> -
>  /*******************************************************************/
>  
>  static const char *pch;

I'm afraid you'll have to rearrange things a bit:

    x86_64-softmmu/monitor.o
/work/armbru/qemu/monitor.c: In function ‘qmp_find_cmd’:
/work/armbru/qemu/monitor.c:2522:34: error: ‘qmp_cmds’ undeclared (first use in this function)
     return search_dispatch_table(qmp_cmds, cmdname);
                                  ^
/work/armbru/qemu/monitor.c:2522:34: note: each undeclared identifier is reported only once for each function it appears in
/work/armbru/qemu/monitor.c:2523:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 642be2e..bd41b4b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -229,8 +229,6 @@  static int mon_refcount;
 static mon_cmd_t mon_cmds[];
 static mon_cmd_t info_cmds[];
 
-static const mon_cmd_t qmp_cmds[];
-
 Monitor *cur_mon;
 
 static QEMUClockType event_clock_type = QEMU_CLOCK_REALTIME;
@@ -947,21 +945,24 @@  static void hmp_info_help(Monitor *mon, const QDict *qdict)
     help_cmd(mon, "info");
 }
 
-CommandInfoList *qmp_query_commands(Error **errp)
+static void query_commands_cb(QmpCommand *cmd, void *opaque)
 {
-    CommandInfoList *info, *cmd_list = NULL;
-    const mon_cmd_t *cmd;
+    CommandInfoList *info, **list = opaque;
 
-    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);
+    info = g_malloc0(sizeof(*info));
+    info->value = g_malloc0(sizeof(*info->value));
+    info->value->name = g_strdup(cmd->name);
+    info->next = *list;
+    *list = info;
+}
 
-        info->next = cmd_list;
-        cmd_list = info;
-    }
+CommandInfoList *qmp_query_commands(Error **errp)
+{
+    CommandInfoList *list = NULL;
 
-    return cmd_list;
+    qmp_for_each_command(query_commands_cb, &list);
+
+    return list;
 }
 
 EventInfoList *qmp_query_events(Error **errp)
@@ -2166,11 +2167,6 @@  static mon_cmd_t mon_cmds[] = {
     { NULL, NULL, },
 };
 
-static const mon_cmd_t qmp_cmds[] = {
-#include "qmp-commands-old.h"
-    { /* NULL */ },
-};
-
 /*******************************************************************/
 
 static const char *pch;