From patchwork Thu Dec 10 14:43:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 40824 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 E41E1B6F0C for ; Fri, 11 Dec 2009 02:19:17 +1100 (EST) Received: from localhost ([127.0.0.1]:35572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIknQ-0008EQ-1Z for incoming@patchwork.ozlabs.org; Thu, 10 Dec 2009 10:19:12 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NIkFr-0001by-MF for qemu-devel@nongnu.org; Thu, 10 Dec 2009 09:44:31 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NIkFm-0001YR-Dj for qemu-devel@nongnu.org; Thu, 10 Dec 2009 09:44:30 -0500 Received: from [199.232.76.173] (port=45395 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIkFm-0001YH-9E for qemu-devel@nongnu.org; Thu, 10 Dec 2009 09:44:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29438) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NIkFl-0004Gs-UH for qemu-devel@nongnu.org; Thu, 10 Dec 2009 09:44:26 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBAEiOwm006214 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 Dec 2009 09:44:24 -0500 Received: from localhost (vpn-11-77.rdu.redhat.com [10.11.11.77]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBAEiNee008921; Thu, 10 Dec 2009 09:44:23 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 10 Dec 2009 12:43:33 -0200 Message-Id: <1260456215-31022-19-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1260456215-31022-1-git-send-email-lcapitulino@redhat.com> References: <1260456215-31022-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 18/20] char: Convert qemu_chr_info() 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 Each device is represented by a QDict. The returned QObject is a QList of all devices. This commit should not change user output. Signed-off-by: Luiz Capitulino --- monitor.c | 3 ++- qemu-char.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qemu-char.h | 4 +++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 5c092d0..a74578f 100644 --- a/monitor.c +++ b/monitor.c @@ -2356,7 +2356,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the character devices", - .mhandler.info = qemu_chr_info, + .user_print = qemu_chr_info_print, + .mhandler.info_new = qemu_chr_info, }, { .name = "block", diff --git a/qemu-char.c b/qemu-char.c index da5c15c..c0d1cb0 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -32,6 +32,7 @@ #include "hw/usb.h" #include "hw/baum.h" #include "hw/msmouse.h" +#include "qemu-objects.h" #include #include @@ -2469,13 +2470,51 @@ void qemu_chr_close(CharDriverState *chr) qemu_free(chr); } -void qemu_chr_info(Monitor *mon) +static void qemu_chr_qlist_iter(QObject *obj, void *opaque) { + QDict *chr_dict; + Monitor *mon = opaque; + + chr_dict = qobject_to_qdict(obj); + monitor_printf(mon, "%s: filename=%s\n", qdict_get_str(chr_dict, "label"), + qdict_get_str(chr_dict, "filename")); +} + +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data) +{ + qlist_iter(qobject_to_qlist(ret_data), qemu_chr_qlist_iter, mon); +} + +/** + * qemu_chr_info(): Character devices information + * + * Each device is represented by a QDict. The returned QObject is a QList + * of all devices. + * + * The QDict contains the following: + * + * - "label": device's label + * - "filename": device's file + * + * Example: + * + * [ { "label": "monitor", "filename", "stdio" }, + * { "label": "serial0", "filename": "vc" } ] + */ +void qemu_chr_info(Monitor *mon, QObject **ret_data) +{ + QList *chr_list; CharDriverState *chr; + chr_list = qlist_new(); + QTAILQ_FOREACH(chr, &chardevs, next) { - monitor_printf(mon, "%s: filename=%s\n", chr->label, chr->filename); + QObject *obj = qobject_from_jsonf("{ 'label': %s, 'filename': %s }", + chr->label, chr->filename); + qlist_append_obj(chr_list, obj); } + + *ret_data = QOBJECT(chr_list); } CharDriverState *qemu_chr_find(const char *name) diff --git a/qemu-char.h b/qemu-char.h index 9957db1..48f54d8 100644 --- a/qemu-char.h +++ b/qemu-char.h @@ -5,6 +5,7 @@ #include "qemu-queue.h" #include "qemu-option.h" #include "qemu-config.h" +#include "qobject.h" /* character device */ @@ -87,7 +88,8 @@ int qemu_chr_can_read(CharDriverState *s); void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len); int qemu_chr_get_msgfd(CharDriverState *s); void qemu_chr_accept_input(CharDriverState *s); -void qemu_chr_info(Monitor *mon); +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data); +void qemu_chr_info(Monitor *mon, QObject **ret_data); CharDriverState *qemu_chr_find(const char *name); extern int term_escape_char;