From patchwork Wed Sep 16 21:32:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 33745 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 DEBAEB7334 for ; Thu, 17 Sep 2009 07:39:38 +1000 (EST) Received: from localhost ([127.0.0.1]:50031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mo2Dw-0008WI-0o for incoming@patchwork.ozlabs.org; Wed, 16 Sep 2009 17:39:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mo27d-0006nU-8S for qemu-devel@nongnu.org; Wed, 16 Sep 2009 17:33:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mo27Y-0006i2-Bz for qemu-devel@nongnu.org; Wed, 16 Sep 2009 17:33:04 -0400 Received: from [199.232.76.173] (port=58004 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mo27Y-0006hs-49 for qemu-devel@nongnu.org; Wed, 16 Sep 2009 17:33:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7014) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mo27X-0002ir-JX for qemu-devel@nongnu.org; Wed, 16 Sep 2009 17:32:59 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8GLWwnf013978 for ; Wed, 16 Sep 2009 17:32:58 -0400 Received: from localhost (vpn-12-10.rdu.redhat.com [10.11.12.10]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8GLWvoA001008 for ; Wed, 16 Sep 2009 17:32:58 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 16 Sep 2009 18:32:36 -0300 Message-Id: <1253136760-3614-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1253136760-3614-1-git-send-email-lcapitulino@redhat.com> References: <1253136760-3614-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 3/7] monitor: do_info(): handle new and old info 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 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(). Also note that this commit adds a new function called monitor_print_nothing(), which will be used by converted handlers that don't have data to print in the user protocol. Signed-off-by: Luiz Capitulino --- monitor.c | 44 ++++++++++++++++++++++++++++++++------------ qemu-monitor.hx | 2 +- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/monitor.c b/monitor.c index 17754fb..cfbedf8 100644 --- a/monitor.c +++ b/monitor.c @@ -210,6 +210,11 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...) return 0; } +static void monitor_print_nothing(Monitor *mon, const QObject *data) +{ + return; +} + static int monitor_handler_ported(const mon_cmd_t *cmd) { return (cmd->user_print == NULL ? 0 : 1); @@ -284,24 +289,39 @@ static void do_commit(Monitor *mon, const QDict *qdict) } } -static void do_info(Monitor *mon, const QDict *qdict) +static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data) { + int ret = 0; const mon_cmd_t *cmd; const char *item = qdict_get_try_str(qdict, "item"); - void (*handler)(Monitor *); - if (!item) - goto help; - for(cmd = info_cmds; cmd->name != NULL; cmd++) { + if (!item) { + help_cmd(mon, "info"); + return 0; + } + + for (cmd = info_cmds; cmd->name != NULL; cmd++) { if (compare_cmd(item, cmd->name)) - goto found; + break; } - help: - help_cmd(mon, "info"); - return; - found: - handler = cmd->handler; - handler(mon); + + if (cmd->name == NULL) + return -1; + + if (monitor_handler_ported(cmd)) { + int (*handler_new)(Monitor *mon, QObject **ret_data); + + handler_new = cmd->handler; + ret = handler_new(mon, ret_data); + + cmd->user_print(mon, *ret_data); + } else { + void (*handler_old)(Monitor *mon); + handler_old = cmd->handler; + handler_old(mon); + } + + return ret; } static void do_info_version(Monitor *mon) diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 400d2bd..b7217f3 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -40,7 +40,7 @@ ETEXI .name = "info", .args_type = "item:s?", .handler = do_info, - .user_print = NULL, + .user_print = monitor_print_nothing, .params = "[subcommand]", .help = "show various information about the system state" },