From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 3/7] monitor: do_info(): handle new and old info handlers
Date: Wed, 16 Sep 2009 18:32:36 -0300 [thread overview]
Message-ID: <1253136760-3614-4-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1253136760-3614-1-git-send-email-lcapitulino@redhat.com>
do_info() is special, its job is to call 'info handlers'.
This is similar to what monitor_handle_command() does,
therefore do_info() also has to distinguish among new and
old style info handlers.
This commit converts do_info() to the new QObject style and
makes the appropriate changes so that it can handle both
info handlers styles.
In the future, when all handlers are converted to QObject's
style, it will be possible to share more code with
monitor_handle_command().
Also note that this commit adds a new function called
monitor_print_nothing(), which will be used by converted
handlers that don't have data to print in the user protocol.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
monitor.c | 44 ++++++++++++++++++++++++++++++++------------
qemu-monitor.hx | 2 +-
2 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/monitor.c b/monitor.c
index 17754fb..cfbedf8 100644
--- a/monitor.c
+++ b/monitor.c
@@ -210,6 +210,11 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
return 0;
}
+static void monitor_print_nothing(Monitor *mon, const QObject *data)
+{
+ return;
+}
+
static int monitor_handler_ported(const mon_cmd_t *cmd)
{
return (cmd->user_print == NULL ? 0 : 1);
@@ -284,24 +289,39 @@ static void do_commit(Monitor *mon, const QDict *qdict)
}
}
-static void do_info(Monitor *mon, const QDict *qdict)
+static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
+ int ret = 0;
const mon_cmd_t *cmd;
const char *item = qdict_get_try_str(qdict, "item");
- void (*handler)(Monitor *);
- if (!item)
- goto help;
- for(cmd = info_cmds; cmd->name != NULL; cmd++) {
+ if (!item) {
+ help_cmd(mon, "info");
+ return 0;
+ }
+
+ for (cmd = info_cmds; cmd->name != NULL; cmd++) {
if (compare_cmd(item, cmd->name))
- goto found;
+ break;
}
- help:
- help_cmd(mon, "info");
- return;
- found:
- handler = cmd->handler;
- handler(mon);
+
+ if (cmd->name == NULL)
+ return -1;
+
+ if (monitor_handler_ported(cmd)) {
+ int (*handler_new)(Monitor *mon, QObject **ret_data);
+
+ handler_new = cmd->handler;
+ ret = handler_new(mon, ret_data);
+
+ cmd->user_print(mon, *ret_data);
+ } else {
+ void (*handler_old)(Monitor *mon);
+ handler_old = cmd->handler;
+ handler_old(mon);
+ }
+
+ return ret;
}
static void do_info_version(Monitor *mon)
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 400d2bd..b7217f3 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -40,7 +40,7 @@ ETEXI
.name = "info",
.args_type = "item:s?",
.handler = do_info,
- .user_print = NULL,
+ .user_print = monitor_print_nothing,
.params = "[subcommand]",
.help = "show various information about the system state"
},
--
1.6.5.rc0
next prev parent reply other threads:[~2009-09-16 21:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-16 21:32 [Qemu-devel] [PATCH 0/7]: Initial QObject conversion Luiz Capitulino
2009-09-16 21:32 ` [Qemu-devel] [PATCH 1/7] monitor: Add user_print() to mon_cmd_t Luiz Capitulino
2009-09-16 21:32 ` [Qemu-devel] [PATCH 2/7] monitor: Handle new and old style handlers Luiz Capitulino
2009-09-17 6:39 ` [Qemu-devel] " Paolo Bonzini
2009-09-17 13:18 ` Luiz Capitulino
2009-09-17 13:28 ` Paolo Bonzini
2009-09-17 17:16 ` Luiz Capitulino
2009-09-16 21:32 ` Luiz Capitulino [this message]
2009-09-23 15:46 ` [Qemu-devel] [PATCH 3/7] monitor: do_info(): handle new and old info handlers Markus Armbruster
2009-09-23 16:05 ` Luiz Capitulino
2009-09-16 21:32 ` [Qemu-devel] [PATCH 4/7] monitor: Convert do_quit() do QObject Luiz Capitulino
2009-09-16 21:32 ` [Qemu-devel] [PATCH 5/7] monitor: Convert do_stop() to QObject Luiz Capitulino
2009-09-16 21:32 ` [Qemu-devel] [PATCH 6/7] monitor: Convert do_system_reset() " Luiz Capitulino
2009-09-16 21:32 ` [Qemu-devel] [PATCH 7/7] monitor: Convert do_system_powerdown() " Luiz Capitulino
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=1253136760-3614-4-git-send-email-lcapitulino@redhat.com \
--to=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).