[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/14] monitor: Handle new and old style handlers
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 04/14] monitor: Handle new and old style handlers |
Date: |
Thu, 1 Oct 2009 12:50:35 -0300 |
This commit changes monitor_handle_command() to support old style
_and_ new style handlers.
New style handlers are protocol independent, they return their data
to the Monitor, which in turn decides how to print them
(ie. user protocol vs. machine protocol).
Old style handlers are called as usual.
Converted handlers will use both the 'user_print' and 'user_error'
members of 'mon_cmd_t' to define its user protocol functions, which
will be called to print data in the user protocol format.
Also note that we are allocating a MonitoError but not using it
yet, this will be done by the next commits.
Signed-off-by: Luiz Capitulino <address@hidden>
---
monitor.c | 38 ++++++++++++++++++++++++++++++++------
1 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/monitor.c b/monitor.c
index 5cb6e81..3f97926 100644
--- a/monitor.c
+++ b/monitor.c
@@ -212,6 +212,11 @@ static int monitor_fprintf(FILE *stream, const char *fmt,
...)
return 0;
}
+static int monitor_handler_ported(const mon_cmd_t *cmd)
+{
+ return cmd->user_print != NULL;
+}
+
static int compare_cmd(const char *name, const char *list)
{
const char *p, *pstart;
@@ -3075,23 +3080,44 @@ fail:
static void monitor_handle_command(Monitor *mon, const char *cmdline)
{
QDict *qdict;
+ MonitorError *error;
const mon_cmd_t *cmd;
qdict = qdict_new();
+ error = monitor_error_new();
cmd = monitor_parse_command(mon, cmdline, qdict);
- if (cmd) {
- void (*handler)(Monitor *mon, const QDict *qdict);
+ if (!cmd)
+ goto out;
- qemu_errors_to_mon(mon);
+ qemu_errors_to_mon(mon);
- handler = cmd->handler;
- handler(mon, qdict);
+ if (monitor_handler_ported(cmd)) {
+ QObject *data = NULL;
+ void (*handler_new)(Monitor *mon, const QDict *params,
+ QObject **ret_data, MonitorError *error);
- qemu_errors_to_previous();
+ handler_new = cmd->handler;
+ handler_new(mon, qdict, &data, error);
+
+ if (monitor_has_error(error)) {
+ cmd->user_error(mon, error);
+ } else {
+ cmd->user_print(mon, data);
+ }
+
+ qobject_decref(data);
+ } else {
+ void (*handler_old)(Monitor *mon, const QDict *qdict);
+ handler_old = cmd->handler;
+ handler_old(mon, qdict);
}
+ qemu_errors_to_previous();
+
+out:
QDECREF(qdict);
+ monitor_error_free(error);
}
static void cmd_completion(const char *name, const char *list)
--
1.6.5.rc2
- [Qemu-devel] [PATCH v1 00/14]: Initial QObject conversion, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 01/14] QObject: Accept NULL, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 02/14] Introduce monitor-error module, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 03/14] monitor: Add new members to mon_cmd_t, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 04/14] monitor: Handle new and old style handlers,
Luiz Capitulino <=
- [Qemu-devel] [PATCH 06/14] monitor: do_info(): handle new and old info handlers, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 05/14] monitor: Initial MonitorError usage, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 07/14] monitor: Convert do_quit() do QObject, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 08/14] monitor: Convert do_stop() to QObject, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 09/14] monitor: Convert do_system_reset() to QObject, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 10/14] monitor: Convert do_system_powerdown() to QObject, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 12/14] monitor: Convert do_info_version() to QObject, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 11/14] monitor: Convert do_balloon() to QObject, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 13/14] monitor-error: Add do_info_balloon() errors, Luiz Capitulino, 2009/10/01
- [Qemu-devel] [PATCH 14/14] monitor: Convert do_info_balloon() to QObject, Luiz Capitulino, 2009/10/01