From patchwork Thu Oct 1 15:50:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 34747 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 EF508B7BCF for ; Fri, 2 Oct 2009 02:20:32 +1000 (EST) Received: from localhost ([127.0.0.1]:58541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MtOOM-00056g-6O for incoming@patchwork.ozlabs.org; Thu, 01 Oct 2009 12:20:30 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MtNwT-0007mT-4u for qemu-devel@nongnu.org; Thu, 01 Oct 2009 11:51:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MtNwR-0007jF-Fh for qemu-devel@nongnu.org; Thu, 01 Oct 2009 11:51:40 -0400 Received: from [199.232.76.173] (port=54697 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MtNwR-0007j2-3i for qemu-devel@nongnu.org; Thu, 01 Oct 2009 11:51:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34773) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MtNwQ-0003fk-JG for qemu-devel@nongnu.org; Thu, 01 Oct 2009 11:51:38 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n91FpbPb003848; Thu, 1 Oct 2009 11:51:37 -0400 Received: from localhost (vpn-12-143.rdu.redhat.com [10.11.12.143]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n91FpaKm008798; Thu, 1 Oct 2009 11:51:37 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 1 Oct 2009 12:50:43 -0300 Message-Id: <1254412245-10452-13-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.18 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 12/14] monitor: Convert do_info_version() to QObject 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 The returned data is always a QString. Also introduces monitor_print_qobject(), which can be used as a standard way to print QObjects in the user protocol format. Signed-off-by: Luiz Capitulino --- monitor.c | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 852e558..1b52355 100644 --- a/monitor.c +++ b/monitor.c @@ -247,6 +247,24 @@ static void monitor_print_parsing_err(Monitor *mon, MonitorError *error) monitor_puts(mon, "\n"); } +static void monitor_print_qobject(Monitor *mon, const QObject *data) +{ + switch (qobject_type(data)) { + case QTYPE_QSTRING: + monitor_printf(mon, "%s",qstring_get_str(qobject_to_qstring(data))); + break; + case QTYPE_QINT: + monitor_printf(mon, "%" PRId64,qint_get_int(qobject_to_qint(data))); + break; + default: + monitor_printf(mon, "ERROR: unsupported type: %d", + qobject_type(data)); + break; + } + + monitor_puts(mon, "\n"); +} + static int compare_cmd(const char *name, const char *list) { const char *p, *pstart; @@ -357,9 +375,13 @@ help: help_cmd(mon, "info"); } -static void do_info_version(Monitor *mon) +/** + * do_info_version(): Show QEMU version + */ +static void do_info_version(Monitor *mon, QObject **ret_data, + MonitorError *error) { - monitor_printf(mon, "%s\n", QEMU_VERSION QEMU_PKGVERSION); + *ret_data = QOBJECT(qstring_from_str(QEMU_VERSION QEMU_PKGVERSION)); } static void do_info_name(Monitor *mon) @@ -1894,8 +1916,8 @@ static const mon_cmd_t info_cmds[] = { .name = "version", .args_type = "", .handler = do_info_version, - .user_print = NULL, - .user_error = NULL, + .user_print = monitor_print_qobject, + .user_error = monitor_error_noop, .params = "", .help = "show the version of QEMU" },