提交 e235cec3 编写于 作者: L Luiz Capitulino

qapi: Convert query-mice

Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
上级 694a099a
......@@ -94,6 +94,26 @@ void hmp_info_chardev(Monitor *mon)
qapi_free_ChardevInfoList(char_info);
}
void hmp_info_mice(Monitor *mon)
{
MouseInfoList *mice_list, *mouse;
mice_list = qmp_query_mice(NULL);
if (!mice_list) {
monitor_printf(mon, "No mouse devices connected\n");
return;
}
for (mouse = mice_list; mouse; mouse = mouse->next) {
monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
mouse->value->current ? '*' : ' ',
mouse->value->index, mouse->value->name,
mouse->value->absolute ? " (absolute)" : "");
}
qapi_free_MouseInfoList(mice_list);
}
void hmp_quit(Monitor *mon, const QDict *qdict)
{
monitor_suspend(mon);
......
......@@ -23,6 +23,7 @@ void hmp_info_kvm(Monitor *mon);
void hmp_info_status(Monitor *mon);
void hmp_info_uuid(Monitor *mon);
void hmp_info_chardev(Monitor *mon);
void hmp_info_mice(Monitor *mon);
void hmp_quit(Monitor *mon, const QDict *qdict);
void hmp_stop(Monitor *mon, const QDict *qdict);
void hmp_system_reset(Monitor *mon, const QDict *qdict);
......
......@@ -26,7 +26,8 @@
#include "net.h"
#include "monitor.h"
#include "console.h"
#include "qjson.h"
#include "error.h"
#include "qmp-commands.h"
static QEMUPutKBDEvent *qemu_put_kbd_event;
static void *qemu_put_kbd_event_opaque;
......@@ -211,60 +212,27 @@ int kbd_mouse_has_absolute(void)
return 0;
}
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%s\n",
(qdict_get_bool(mouse, "current") ? '*' : ' '),
qdict_get_int(mouse, "index"), qdict_get_str(mouse, "name"),
qdict_get_bool(mouse, "absolute") ? " (absolute)" : "");
}
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);
}
void do_info_mice(Monitor *mon, QObject **ret_data)
MouseInfoList *qmp_query_mice(Error **errp)
{
MouseInfoList *mice_list = NULL;
QEMUPutMouseEntry *cursor;
QList *mice_list;
int current;
mice_list = qlist_new();
bool current = true;
if (QTAILQ_EMPTY(&mouse_handlers)) {
goto out;
}
QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
MouseInfoList *info = g_malloc0(sizeof(*info));
info->value = g_malloc0(sizeof(*info->value));
info->value->name = g_strdup(cursor->qemu_put_mouse_event_name);
info->value->index = cursor->index;
info->value->absolute = !!cursor->qemu_put_mouse_event_absolute;
info->value->current = current;
current = QTAILQ_FIRST(&mouse_handlers)->index;
current = false;
QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
QObject *obj;
obj = qobject_from_jsonf("{ 'name': %s,"
" 'index': %d,"
" 'current': %i,"
" 'absolute': %i }",
cursor->qemu_put_mouse_event_name,
cursor->index,
cursor->index == current,
!!cursor->qemu_put_mouse_event_absolute);
qlist_append_obj(mice_list, obj);
info->next = mice_list;
mice_list = info;
}
out:
*ret_data = QOBJECT(mice_list);
return mice_list;
}
void do_mouse_set(Monitor *mon, const QDict *qdict)
......
......@@ -2942,8 +2942,7 @@ static const mon_cmd_t info_cmds[] = {
.args_type = "",
.params = "",
.help = "show which guest mouse is receiving events",
.user_print = do_info_mice_print,
.mhandler.info_new = do_info_mice,
.mhandler.info = hmp_info_mice,
},
{
.name = "vnc",
......@@ -3092,14 +3091,6 @@ static const mon_cmd_t qmp_query_cmds[] = {
.user_print = do_pci_info_print,
.mhandler.info_new = do_pci_info,
},
{
.name = "mice",
.args_type = "",
.params = "",
.help = "show which guest mouse is receiving events",
.user_print = do_info_mice_print,
.mhandler.info_new = do_info_mice,
},
{
.name = "vnc",
.args_type = "",
......
......@@ -225,6 +225,36 @@
##
{ 'command': 'query-commands', 'returns': ['CommandInfo'] }
##
# @MouseInfo:
#
# Information about a mouse device.
#
# @name: the name of the mouse device
#
# @index: the index of the mouse device
#
# @current: true if this device is currently receiving mouse events
#
# @absolute: true if this device supports absolute coordinates as input
#
# Since: 0.14.0
##
{ 'type': 'MouseInfo',
'data': {'name': 'str', 'index': 'int', 'current': 'bool',
'absolute': 'bool'} }
##
# @query-mice:
#
# Returns information about each active mouse device
#
# Returns: a list of @MouseInfo for each device
#
# Since: 0.14.0
##
{ 'command': 'query-mice', 'returns': ['MouseInfo'] }
##
# @quit:
#
......
......@@ -1663,6 +1663,12 @@ Example:
EQMP
{
.name = "query-mice",
.args_type = "",
.mhandler.cmd_new = qmp_marshal_input_query_mice,
},
SQMP
query-vnc
---------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册