Skip to contentSkip to conversation

add input-send-event command

PATCH Superseded Marcelo Tosatti 3 participants 4 messages Sep 29, 2014 – Sep 30, 2014

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 add input-send-event command

Which allows specification of absolute/relative,
up/down and console parameters.

Suggested by Gerd Hoffman.

---
 qapi-schema.json | 17 +++++++++++++++
 qmp-commands.hx  | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       | 31 ++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
qapi-schema.json +17 -0
index 4bfaf20..2e9e261 100644
@@ -3233,6 +3233,23 @@
               'abs'     : 'InputMoveEvent' } }
 
 ##
+# @input-send-event
+#
+# Send input event(s) to guest.
+#
+# @console: Which console to send event(s) to.
+#
+# @events: List of InputEvent union.
+#
+# Returns: Nothing on success.
+#
+# Since: 2.2
+#
+##
+{ 'command': 'input-send-event',
+  'data': { 'console':'int', 'events': [ 'InputEvent' ] } }
+
+##
 # @NumaOptions
 #
 # A discriminated record of NUMA options. (for OptsVisitor)
qmp-commands.hx +63 -0

66 lines not on this page · raw message

ui/input.c +31 -0
index 89d9db7..66f4108 100644
@@ -122,6 +122,37 @@ qemu_input_find_handler(uint32_t mask, QemuConsole *con)
     return NULL;
 }
 
+void qmp_input_send_event(int64_t console, InputEventList *events,
+                          Error **errp)
+{
+    InputEventList *e;
+    QemuConsole *con;
+
+    con = qemu_console_lookup_by_index(console);
+    if (!con) {
+        error_setg(errp, "console %" PRId64 " not found", console);
+        return;
+    }
+
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+        error_setg(errp, "VM not running");
+        return;
+    }
+
+    for (e = events; e != NULL; e = e->next) {
+        InputEvent *event = e->value;
+
+        if (!qemu_input_find_handler(1 << event->kind, con)) {
+            error_setg(errp, "Input handler not found for "
+                             "event type %s",
+                            InputEventKind_lookup[event->kind]);
+            return;
+        }
+        qemu_input_event_send(con, event);
+    }
+    qemu_input_event_sync();
+}
+
 static void qemu_input_transform_abs_rotate(InputEvent *evt)
 {
     switch (graphic_rotate) {
#1 lore raw
Quoted 27 lines · Marcelo Tosatti

Which allows specification of absolute/relative,
up/down and console parameters.

Suggested by Gerd Hoffman.

---
 qapi-schema.json | 17 +++++++++++++++
 qmp-commands.hx  | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       | 31 ++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
qapi-schema.json +5 -0
index 4bfaf20..2e9e261 100644
@@ -3233,6 +3233,23 @@
               'abs'     : 'InputMoveEvent' } }
 
 ##
+# @input-send-event
+#
+# Send input event(s) to guest.
+#
+# @console: Which console to send event(s) to.

qapi-schema.json line 3250

Quoted 10 lines
qapi-schema.json +10 -0
+#
+# @events: List of InputEvent union.
+#
+# Returns: Nothing on success.
+#
+# Since: 2.2
+#
+##
+{ 'command': 'input-send-event',
+  'data': { 'console':'int', 'events': [ 'InputEvent' ] } }

'console' is mandatory; I guess that's okay.

Are we guaranteed that either all events are sent? Or is there a need to worry about partial success (on a list of 3 events, the first gets sent, then some error is encountered on the second, and the third is not attempted)? Are the only errors due to something that can be detected up front (such as trying to send a mouse event to a console that has only keyboard support)?

qapi-schema.json line 3253

Quoted 3 lines
qapi-schema.json +3 -0
+The consoles are visible in the qom tree, under
+/backend/console[$index]. They have a device link and head property, so
+its possible to map which console belongs to which device and display.

s/its/it's/ (or 'it is')

Quoted 15 lines
qapi-schema.json +15 -0
+void qmp_input_send_event(int64_t console, InputEventList *events,
+                          Error **errp)
+{
+    InputEventList *e;
+    QemuConsole *con;
+
+    con = qemu_console_lookup_by_index(console);
+    if (!con) {
+        error_setg(errp, "console %" PRId64 " not found", console);
+        return;
+    }
+
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+        error_setg(errp, "VM not running");
+        return;

qapi-schema.json

Quoted 10 lines
qapi-schema.json +10 -0
+    }
+
+    for (e = events; e != NULL; e = e->next) {
+        InputEvent *event = e->value;
+
+        if (!qemu_input_find_handler(1 << event->kind, con)) {
+            error_setg(errp, "Input handler not found for "
+                             "event type %s",
+                            InputEventKind_lookup[event->kind]);
+            return;

Ouch. You can return mid-loop. I'd be more comfortable with a two-pass algorithm (first pass ensures all list elements have a handler, second actually calls qemu_input_event_send) or with a return that gives an integer count of how many list items were processed.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 41 lines · Eric Blake
Quoted 27 lines · Marcelo Tosatti

Which allows specification of absolute/relative,
up/down and console parameters.

Suggested by Gerd Hoffman.

---
 qapi-schema.json | 17 +++++++++++++++
 qmp-commands.hx  | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       | 31 ++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
qapi-schema.json +5 -0
index 4bfaf20..2e9e261 100644
@@ -3233,6 +3233,23 @@
               'abs'     : 'InputMoveEvent' } }
 
 ##
+# @input-send-event
+#
+# Send input event(s) to guest.
+#
+# @console: Which console to send event(s) to.

qapi-schema.json line 3250

Quoted 10 lines
qapi-schema.json +10 -0
+#
+# @events: List of InputEvent union.
+#
+# Returns: Nothing on success.
+#
+# Since: 2.2
+#
+##
+{ 'command': 'input-send-event',
+  'data': { 'console':'int', 'events': [ 'InputEvent' ] } }

'console' is mandatory; I guess that's okay.

Quoted 1 line

Are we guaranteed that either all events are sent? Or is there a need to

Events can be dropped at hardware level if the event queue is full, for example. Would have to modify individual drivers to return error codes, i suppose. Gerd?

Quoted 35 lines

worry about partial success (on a list of 3 events, the first gets sent, then some error is encountered on the second, and the third is not attempted)? Are the only errors due to something that can be detected up front (such as trying to send a mouse event to a console that has only keyboard support)?

qapi-schema.json line 3253

Quoted 3 lines
qapi-schema.json +3 -0
+The consoles are visible in the qom tree, under
+/backend/console[$index]. They have a device link and head property, so
+its possible to map which console belongs to which device and display.

s/its/it's/ (or 'it is')

Quoted 23 lines
qapi-schema.json +23 -0
+void qmp_input_send_event(int64_t console, InputEventList *events,
+                          Error **errp)
+{
+    InputEventList *e;
+    QemuConsole *con;
+
+    con = qemu_console_lookup_by_index(console);
+    if (!con) {
+        error_setg(errp, "console %" PRId64 " not found", console);
+        return;
+    }
+
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+        error_setg(errp, "VM not running");
+        return;
+    }
+
+    for (e = events; e != NULL; e = e->next) {
+        InputEvent *event = e->value;
+
+        if (!qemu_input_find_handler(1 << event->kind, con)) {
+            error_setg(errp, "Input handler not found for "
+                             "event type %s",
Quoted 8 lines

qapi-schema.json

Quoted 2 lines
qapi-schema.json +2 -0
+                            InputEventKind_lookup[event->kind]);
+            return;

Ouch. You can return mid-loop. I'd be more comfortable with a two-pass algorithm (first pass ensures all list elements have a handler, second actually calls qemu_input_event_send) or with a return that gives an integer count of how many list items were processed.

Sure.

#3 lore raw

Hi,

Quoted 7 lines
Quoted 3 lines

'console' is mandatory; I guess that's okay.

Are we guaranteed that either all events are sent? Or is there a need to

Events can be dropped at hardware level if the event queue is full, for example. Would have to modify individual drivers to return error codes, i suppose. Gerd?

Events can be dropped at hardware level indeed. Hard to check beforehand, and we don't even return errors today as the ui code (which would see the error) can't do much about it. Not sure this is worth changing, this usually only happens in case the guest has trouble driving the device, in which case you have bigger problems anyway.

Events can also be dropped because there is no device they can be delivered to. This can easily be checked for the whole event list before you start sending the events, just call qemu_input_find_handler() and see whenever it returns a handler or not. So we can go for a "all-or-nothing" model here. In the x86 world this can happen with absolute mouse moves only because there is always a ps2 kbd+mouse.

cheers,
Gerd