From patchwork Wed Dec 9 16:27:52 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 40748 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 31CB2B7088 for ; Thu, 10 Dec 2009 04:06:09 +1100 (EST) Received: from localhost ([127.0.0.1]:60479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIPzK-0006eb-9m for incoming@patchwork.ozlabs.org; Wed, 09 Dec 2009 12:06:06 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NIPZh-0008W9-Kl for qemu-devel@nongnu.org; Wed, 09 Dec 2009 11:39:37 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NIPZd-0008TI-Ef for qemu-devel@nongnu.org; Wed, 09 Dec 2009 11:39:37 -0500 Received: from [199.232.76.173] (port=48833 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIPZd-0008T9-6X for qemu-devel@nongnu.org; Wed, 09 Dec 2009 11:39:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15299) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NIPZc-0007Nj-Q6 for qemu-devel@nongnu.org; Wed, 09 Dec 2009 11:39:33 -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 nB9GdVmZ024041 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 9 Dec 2009 11:39:31 -0500 Received: from localhost (vpn-9-2.rdu.redhat.com [10.11.9.2]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB9GdUrO000930; Wed, 9 Dec 2009 11:39:31 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 9 Dec 2009 14:27:52 -0200 Message-Id: <1260376078-8694-14-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1260376078-8694-1-git-send-email-lcapitulino@redhat.com> References: <1260376078-8694-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 13/19] 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 f0cb759..d5e8dda 100644 --- a/monitor.c +++ b/monitor.c @@ -2492,7 +2492,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 09a0ec5..73737ee 100644 --- a/vl.c +++ b/vl.c @@ -156,6 +156,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" @@ -458,25 +459,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)