[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/18] monitor: do_info(): handle new and old info h
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 09/18] monitor: do_info(): handle new and old info handlers |
Date: |
Wed, 7 Oct 2009 13:41:55 -0300 |
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().
This commit also introduces a new function called
monitor_user_noop(), it should be used by handlers which do
not have data to print.
This is the case of do_info().
Signed-off-by: Luiz Capitulino <address@hidden>
---
monitor.c | 29 ++++++++++++++++++++++-------
qemu-monitor.hx | 3 ++-
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/monitor.c b/monitor.c
index d545124..cc1b501 100644
--- a/monitor.c
+++ b/monitor.c
@@ -76,6 +76,7 @@ typedef struct mon_cmd_t {
void (*user_print)(Monitor *mon, const QObject *data);
union {
void (*info)(Monitor *mon);
+ void (*info_new)(Monitor *mon, QObject **ret_data);
void (*cmd)(Monitor *mon, const QDict *qdict);
void (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data);
} mhandler;
@@ -215,6 +216,8 @@ static int monitor_fprintf(FILE *stream, const char *fmt,
...)
return 0;
}
+static void monitor_user_noop(Monitor *mon, const QObject *data) { }
+
static inline int monitor_handler_ported(const mon_cmd_t *cmd)
{
return cmd->user_print != NULL;
@@ -289,22 +292,34 @@ static void do_commit(Monitor *mon, const QDict *qdict)
}
}
-static void do_info(Monitor *mon, const QDict *qdict)
+static void do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
const mon_cmd_t *cmd;
const char *item = qdict_get_try_str(qdict, "item");
if (!item)
goto help;
- for(cmd = info_cmds; cmd->name != NULL; cmd++) {
+
+ for (cmd = info_cmds; cmd->name != NULL; cmd++) {
if (compare_cmd(item, cmd->name))
- goto found;
+ break;
}
- help:
- help_cmd(mon, "info");
+
+ if (cmd->name == NULL)
+ goto help;
+
+ if (monitor_handler_ported(cmd)) {
+ cmd->mhandler.info_new(mon, ret_data);
+ if (*ret_data)
+ cmd->user_print(mon, *ret_data);
+ } else {
+ cmd->mhandler.info(mon);
+ }
+
return;
- found:
- cmd->mhandler.info(mon);
+
+help:
+ help_cmd(mon, "info");
}
static void do_info_version(Monitor *mon)
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index c689a07..c37b0cb 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -40,7 +40,8 @@ ETEXI
.args_type = "item:s?",
.params = "[subcommand]",
.help = "show various information about the system state",
- .mhandler.cmd = do_info,
+ .user_print = monitor_user_noop,
+ .mhandler.cmd_new = do_info,
},
STEXI
--
1.6.5.rc2.17.gdbc1b
- [Qemu-devel] [RESEND v3 00/18]: Initial QObject conversion, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 01/18] QObject: Accept NULL, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 03/18] Introduce QList unit-tests, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 02/18] Introduce QList, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 04/18] monitor: Convert mon_cmd_t initializations to C99 style, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 05/18] monitor: union for info handlers, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 06/18] monitor: union for command handlers, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 07/18] monitor: Add user_print() to mon_cmd_t, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 08/18] monitor: Handle new and old style handlers, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 09/18] monitor: do_info(): handle new and old info handlers,
Luiz Capitulino <=
- [Qemu-devel] [PATCH 11/18] monitor: Convert do_stop() to QObject, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 10/18] monitor: Convert do_quit() do QObject, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 13/18] monitor: Convert do_system_powerdown() to QObject, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 12/18] monitor: Convert do_system_reset() to QObject, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 14/18] monitor: Convert do_cont() to QObject, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 15/18] monitor: Convert do_balloon() to QObject, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 16/18] monitor: Convert do_info_version() to QObject, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 17/18] monitor: Convert do_info_balloon() to QObject, Luiz Capitulino, 2009/10/07
- [Qemu-devel] [PATCH 18/18] monitor: Convert do_info_cpus() to QObject, Luiz Capitulino, 2009/10/07