From patchwork Mon Sep 19 16:41:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 671859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sdBp20DC2z9sBX for ; Tue, 20 Sep 2016 02:55:06 +1000 (AEST) Received: from localhost ([::1]:56866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bm1qR-0000cW-DH for incoming@patchwork.ozlabs.org; Mon, 19 Sep 2016 12:55:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bm1dZ-0006K4-S9 for qemu-devel@nongnu.org; Mon, 19 Sep 2016 12:41:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bm1dX-0008NQ-Ni for qemu-devel@nongnu.org; Mon, 19 Sep 2016 12:41:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49058) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bm1dX-0008My-H8 for qemu-devel@nongnu.org; Mon, 19 Sep 2016 12:41:43 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B28731B30F for ; Mon, 19 Sep 2016 16:41:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8JGfdnF022852 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 19 Sep 2016 12:41:42 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B04A911F5F20; Mon, 19 Sep 2016 18:41:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 19 Sep 2016 18:41:26 +0200 Message-Id: <1474303294-13952-11-git-send-email-armbru@redhat.com> In-Reply-To: <1474303294-13952-1-git-send-email-armbru@redhat.com> References: <1474303294-13952-1-git-send-email-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 19 Sep 2016 16:41:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/18] monitor: implement 'qmp_query_commands' without qmp_cmds X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau One step towards getting rid of the static qmp_cmds table. Signed-off-by: Marc-André Lureau Reviewed-by: Eric Blake Message-Id: <20160912091913.15831-11-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- monitor.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) 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)