From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, chenwj@iis.sinica.edu.tw, armbru@redhat.com,
lcapitulino@redhat.com, Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH V4 2/4] HMP: add infrastructure for sub command
Date: Thu, 10 Jan 2013 16:32:32 +0800 [thread overview]
Message-ID: <1357806754-8552-3-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1357806754-8552-1-git-send-email-xiawenc@linux.vnet.ibm.com>
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 <xiawenc@linux.vnet.ibm.com>
---
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;
--
1.7.1
next prev parent reply other threads:[~2013-01-10 8:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-10 8:32 [Qemu-devel] [PATCH V4 0/4] HMP: allow parsing for sub command Wenchao Xia
2013-01-10 8:32 ` [Qemu-devel] [PATCH V4 1/4] HMP: add QDict to info callback handler Wenchao Xia
2013-01-10 13:10 ` Luiz Capitulino
2013-01-11 3:16 ` Wenchao Xia
2013-01-10 8:32 ` Wenchao Xia [this message]
2013-01-10 10:18 ` [Qemu-devel] [PATCH V4 2/4] HMP: add infrastructure for sub command Markus Armbruster
2013-01-11 3:11 ` Wenchao Xia
2013-01-10 10:23 ` Markus Armbruster
2013-01-11 3:11 ` Wenchao Xia
2013-01-10 13:12 ` Luiz Capitulino
2013-01-11 3:17 ` Wenchao Xia
2013-01-10 8:32 ` [Qemu-devel] [PATCH V4 3/4] HMP: move define of mon_cmds Wenchao Xia
2013-01-10 8:32 ` [Qemu-devel] [PATCH V4 4/4] HMP: add sub command table to info Wenchao Xia
2013-01-10 10:24 ` Markus Armbruster
2013-01-11 3:13 ` Wenchao Xia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357806754-8552-3-git-send-email-xiawenc@linux.vnet.ibm.com \
--to=xiawenc@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=chenwj@iis.sinica.edu.tw \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).