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>
master
Luiz Capitulino 2009-10-07 13:41:55 -03:00 committed by Anthony Liguori
parent 13917beeac
commit 13c7425e1a
2 changed files with 24 additions and 8 deletions

View File

@ -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)

View File

@ -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