From patchwork Thu Oct 1 15:50:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 34738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 62B17B7BC2 for ; Fri, 2 Oct 2009 02:03:25 +1000 (EST) Received: from localhost ([127.0.0.1]:38480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MtO7m-000235-Hw for incoming@patchwork.ozlabs.org; Thu, 01 Oct 2009 12:03:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MtNwD-0007NW-T9 for qemu-devel@nongnu.org; Thu, 01 Oct 2009 11:51:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MtNw8-0007GC-A0 for qemu-devel@nongnu.org; Thu, 01 Oct 2009 11:51:24 -0400 Received: from [199.232.76.173] (port=56557 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MtNw7-0007Fr-MY for qemu-devel@nongnu.org; Thu, 01 Oct 2009 11:51:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56550) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MtNw7-0003ci-13 for qemu-devel@nongnu.org; Thu, 01 Oct 2009 11:51:19 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n91FpIg8025455; Thu, 1 Oct 2009 11:51:18 -0400 Received: from localhost (vpn-12-143.rdu.redhat.com [10.11.12.143]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n91FpGxC030360; Thu, 1 Oct 2009 11:51:17 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 1 Oct 2009 12:50:35 -0300 Message-Id: <1254412245-10452-5-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1254412245-10452-1-git-send-email-lcapitulino@redhat.com> References: <1254412245-10452-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com Subject: [Qemu-devel] [PATCH 04/14] monitor: Handle new and old style handlers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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)