aboutsummaryrefslogtreecommitdiff
path: root/monitor.c
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2009-10-07 13:41:55 -0300
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-08 21:17:18 -0500
commit13c7425e1a3b1f3503d87aaa765ff0112c6b4dd7 (patch)
tree0d9e711225210acb4a9fe47cd1d8beb1c6a7f2e4 /monitor.c
parent13917beeaca78700a737506d9e1181e83fe41d93 (diff)
monitor: do_info(): handle new and old info handlers
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(). Patchworks-ID: 35341 Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/monitor.c b/monitor.c
index d545124ea2..cc1b501cfe 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)