aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2009-12-10 17:16:04 -0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-12-12 07:59:49 -0600
commite78c48ec4e192ef1b1a210bdf5a8d253d7826c25 (patch)
tree1e6e71fd2373dbb9bbe5333b37a597ffdbd38b32
parent9603ceba2edd1dc7e3823da76d84706d3d1c3d78 (diff)
monitor: Convert do_info_mice() to QObject
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 <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--console.h3
-rw-r--r--monitor.c3
-rw-r--r--vl.c62
3 files changed, 59 insertions, 9 deletions
diff --git a/console.h b/console.h
index 9615f56364..c7172f6d3a 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 daa45fcaa5..aa97f89b3a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2518,7 +2518,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 d02893173c..c0d98f56d4 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"
@@ -490,25 +491,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)