From patchwork Thu Dec 27 09:40:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 208288 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 65C672C007E for ; Thu, 27 Dec 2012 20:41:07 +1100 (EST) Received: from localhost ([::1]:45795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1To9xZ-0007Be-LN for incoming@patchwork.ozlabs.org; Thu, 27 Dec 2012 04:41:05 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1To9xN-00075X-TG for qemu-devel@nongnu.org; Thu, 27 Dec 2012 04:40:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1To9xM-0006vE-Ou for qemu-devel@nongnu.org; Thu, 27 Dec 2012 04:40:53 -0500 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:32948) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1To9xM-0006ux-37 for qemu-devel@nongnu.org; Thu, 27 Dec 2012 04:40:52 -0500 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 27 Dec 2012 19:36:22 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 27 Dec 2012 19:36:20 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id EBBC02BB004A for ; Thu, 27 Dec 2012 20:40:47 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qBR9el1U57933990 for ; Thu, 27 Dec 2012 20:40:47 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qBR9elBc026187 for ; Thu, 27 Dec 2012 20:40:47 +1100 Received: from RedHat62GAWSWenchao (wenchaox.cn.ibm.com [9.115.122.122] (may be forged)) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qBR9eFG7025504; Thu, 27 Dec 2012 20:40:45 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 27 Dec 2012 17:40:25 +0800 Message-Id: <1356601227-8707-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1356601227-8707-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1356601227-8707-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12122709-6102-0000-0000-000002C5C4B1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.145 Cc: aliguori@us.ibm.com, chenwj@iis.sinica.edu.tw, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V3 2/4] HMP: add infrastructure for sub command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch make parsing of hmp command aware of that it may have sub command. Also discard simple encapsulation function monitor_find_command() and qmp_find_cmd(). Signed-off-by: Wenchao Xia --- monitor.c | 44 +++++++++++++++++++++++++++----------------- 1 files changed, 27 insertions(+), 17 deletions(-) diff --git a/monitor.c b/monitor.c index c7b3014..e4d4c59 100644 --- a/monitor.c +++ b/monitor.c @@ -130,6 +130,7 @@ typedef struct mon_cmd_t { MonitorCompletion *cb, void *opaque); } mhandler; int flags; + struct mon_cmd_t *sub_table; } mon_cmd_t; /* file descriptors passed via SCM_RIGHTS */ @@ -3534,21 +3535,17 @@ static const mon_cmd_t *search_dispatch_table(const mon_cmd_t *disp_table, return NULL; } -static const mon_cmd_t *monitor_find_command(const char *cmdname) -{ - return search_dispatch_table(mon_cmds, cmdname); -} - -static const mon_cmd_t *qmp_find_cmd(const char *cmdname) -{ - return search_dispatch_table(qmp_cmds, cmdname); -} - -static const mon_cmd_t *monitor_parse_command(Monitor *mon, - const char *cmdline, - QDict *qdict) +/* + * Try find the target mon_cmd_t instance, if it have sub_table and have string + * for it, this function will try search it with remain string, and if not + * found it return NULL. + */ +static const mon_cmd_t *hmp_parse_command(Monitor *mon, + const char *cmdline, + mon_cmd_t *table, + QDict *qdict) { - const char *p, *typestr; + const char *p, *p1, *typestr; int c; const mon_cmd_t *cmd; char cmdname[256]; @@ -3564,12 +3561,25 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, if (!p) return NULL; - cmd = monitor_find_command(cmdname); + cmd = search_dispatch_table(table, cmdname); if (!cmd) { monitor_printf(mon, "unknown command: '%s'\n", cmdname); return NULL; } + /* search sub command */ + if (cmd->sub_table != NULL) { + p1 = p; + /* check if user set additional command */ + while (qemu_isspace(*p1)) { + p1++; + } + if (*p1 == '\0') { + return cmd; + } + return hmp_parse_command(mon, p, cmd->sub_table, qdict); + } + /* parse the parameters */ typestr = cmd->args_type; for(;;) { @@ -3925,7 +3935,7 @@ static void handle_user_command(Monitor *mon, const char *cmdline) qdict = qdict_new(); - cmd = monitor_parse_command(mon, cmdline, qdict); + cmd = hmp_parse_command(mon, cmdline, mon_cmds, qdict); if (!cmd) goto out; @@ -4483,7 +4493,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) goto err_out; } - cmd = qmp_find_cmd(cmd_name); + cmd = search_dispatch_table(qmp_cmds, cmd_name); if (!cmd) { qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name); goto err_out;