From patchwork Mon Nov 23 20:06:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 39090 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 E90CA1007D7 for ; Tue, 24 Nov 2009 07:25:56 +1100 (EST) Received: from localhost ([127.0.0.1]:59221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCfTs-0007oG-Q3 for incoming@patchwork.ozlabs.org; Mon, 23 Nov 2009 15:25:52 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NCfBZ-0008UD-1H for qemu-devel@nongnu.org; Mon, 23 Nov 2009 15:06:57 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NCfBT-0008RU-RO for qemu-devel@nongnu.org; Mon, 23 Nov 2009 15:06:56 -0500 Received: from [199.232.76.173] (port=42685 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCfBT-0008RO-MT for qemu-devel@nongnu.org; Mon, 23 Nov 2009 15:06:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39485) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NCfBT-0001bq-3j for qemu-devel@nongnu.org; Mon, 23 Nov 2009 15:06:51 -0500 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 nANK6ovE028231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Nov 2009 15:06:50 -0500 Received: from localhost (vpn-9-248.rdu.redhat.com [10.11.9.248]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nANK6nGr027971 for ; Mon, 23 Nov 2009 15:06:49 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 23 Nov 2009 18:06:17 -0200 Message-Id: <1259006783-945-12-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1259006783-945-1-git-send-email-lcapitulino@redhat.com> References: <1259006783-945-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. Subject: [Qemu-devel] [PATCH 11/17] monitor: Convert do_info_mice() 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 mouse is represented by a QDict, the returned QObject is a QList of all mice. This commit should not change user output. Signed-off-by: Luiz Capitulino --- console.h | 3 +- monitor.c | 3 +- vl.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/console.h b/console.h index 9615f56..c7172f6 100644 --- a/console.h +++ b/console.h @@ -44,7 +44,8 @@ struct MouseTransformInfo { int a[7]; }; -void do_info_mice(Monitor *mon); +void do_info_mice_print(Monitor *mon, const QObject *data); +void do_info_mice(Monitor *mon, QObject **ret_data); void do_mouse_set(Monitor *mon, const QDict *qdict); /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx diff --git a/monitor.c b/monitor.c index eb46926..ac0c02c 100644 --- a/monitor.c +++ b/monitor.c @@ -2208,7 +2208,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show which guest mouse is receiving events", - .mhandler.info = do_info_mice, + .user_print = do_info_mice_print, + .mhandler.info_new = do_info_mice, }, { .name = "vnc", diff --git a/vl.c b/vl.c index ee43808..e7d0754 100644 --- a/vl.c +++ b/vl.c @@ -157,6 +157,7 @@ int main(int argc, char **argv) #include "balloon.h" #include "qemu-option.h" #include "qemu-config.h" +#include "qemu-objects.h" #include "disas.h" @@ -459,25 +460,72 @@ int kbd_mouse_is_absolute(void) return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute; } -void do_info_mice(Monitor *mon) +static void info_mice_iter(QObject *data, void *opaque) +{ + QDict *mouse; + Monitor *mon = opaque; + + mouse = qobject_to_qdict(data); + monitor_printf(mon, "%c Mouse #%" PRId64 ": %s\n", + (qdict_get_bool(mouse, "current") ? '*' : ' '), + qdict_get_int(mouse, "index"), qdict_get_str(mouse, "name")); +} + +void do_info_mice_print(Monitor *mon, const QObject *data) +{ + QList *mice_list; + + mice_list = qobject_to_qlist(data); + if (qlist_empty(mice_list)) { + monitor_printf(mon, "No mouse devices connected\n"); + return; + } + + qlist_iter(mice_list, info_mice_iter, mon); +} + +/** + * do_info_mice(): Show VM mice information + * + * Each mouse is represented by a QDict, the returned QObject is a QList of + * all mice. + * + * The mouse QDict contains the following: + * + * - "name": mouse's name + * - "index": mouse's index + * - "current": true if this mouse is receiving events, false otherwise + * + * Example: + * + * [ { "name": "QEMU Microsoft Mouse", "index": 0, "current": false }, + * { "name": "QEMU PS/2 Mouse", "index": 1, "current": true } ] + */ +void do_info_mice(Monitor *mon, QObject **ret_data) { QEMUPutMouseEntry *cursor; + QList *mice_list; int index = 0; + mice_list = qlist_new(); + if (!qemu_put_mouse_event_head) { - monitor_printf(mon, "No mouse devices connected\n"); - return; + goto out; } - monitor_printf(mon, "Mouse devices available:\n"); cursor = qemu_put_mouse_event_head; while (cursor != NULL) { - monitor_printf(mon, "%c Mouse #%d: %s\n", - (cursor == qemu_put_mouse_event_current ? '*' : ' '), - index, cursor->qemu_put_mouse_event_name); + QObject *obj; + obj = qobject_from_jsonf("{ 'name': %s, 'index': %d, 'current': %i }", + cursor->qemu_put_mouse_event_name, + index, cursor == qemu_put_mouse_event_current); + qlist_append_obj(mice_list, obj); index++; cursor = cursor->next; } + +out: + *ret_data = QOBJECT(mice_list); } void do_mouse_set(Monitor *mon, const QDict *qdict)