From patchwork Thu Jan 10 08:32:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 210947 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 13FC12C0334 for ; Thu, 10 Jan 2013 19:35:35 +1100 (EST) Received: from localhost ([::1]:42125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtDbp-0007NU-0Q for incoming@patchwork.ozlabs.org; Thu, 10 Jan 2013 03:35:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtDbW-0007DF-CC for qemu-devel@nongnu.org; Thu, 10 Jan 2013 03:35:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TtDbU-0004IX-JY for qemu-devel@nongnu.org; Thu, 10 Jan 2013 03:35:14 -0500 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:59798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtDbT-0004G8-UY for qemu-devel@nongnu.org; Thu, 10 Jan 2013 03:35:12 -0500 Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 Jan 2013 14:03:39 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp06.in.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 10 Jan 2013 14:03:38 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id A8B7AE004B for ; Thu, 10 Jan 2013 14:05:20 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0A8Z48820119614 for ; Thu, 10 Jan 2013 14:05:04 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0A8Z1Is010680 for ; Thu, 10 Jan 2013 19:35:05 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.237]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r0A8XRlX002188; Thu, 10 Jan 2013 19:34:58 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2013 16:32:32 +0800 Message-Id: <1357806754-8552-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1357806754-8552-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1357806754-8552-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13011008-9574-0000-0000-0000061DF5DD X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.6 Cc: aliguori@us.ibm.com, chenwj@iis.sinica.edu.tw, armbru@redhat.com, lcapitulino@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V4 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 | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-) diff --git a/monitor.c b/monitor.c index c7b3014..d49a362 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,22 @@ 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); } +/* + * 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 remaining string, and if not + * found it return NULL. + */ static const mon_cmd_t *monitor_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 +3566,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 monitor_parse_command(mon, p, cmd->sub_table, qdict); + } + /* parse the parameters */ typestr = cmd->args_type; for(;;) { @@ -3925,7 +3940,7 @@ static void handle_user_command(Monitor *mon, const char *cmdline) qdict = qdict_new(); - cmd = monitor_parse_command(mon, cmdline, qdict); + cmd = monitor_parse_command(mon, cmdline, mon_cmds, qdict); if (!cmd) goto out;