qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] qerror: add QERR_TOO_MANY_PARAMETERS
@ 2012-05-25  3:31 Amos Kong
  2012-05-25  3:32 ` [Qemu-devel] [PATCH 2/3] fix doc of using raw values with sendkey Amos Kong
  2012-05-25  3:32 ` [Qemu-devel] [PATCH 3/3] qapi: convert sendkey Amos Kong
  0 siblings, 2 replies; 15+ messages in thread
From: Amos Kong @ 2012-05-25  3:31 UTC (permalink / raw)
  To: aliguori, eblake, berrange, lcapitulino, qemu-devel; +Cc: Amos Kong

Signed-off-by: Amos Kong <akong@redhat.com>
---
 qerror.c |    4 ++++
 qerror.h |    3 +++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/qerror.c b/qerror.c
index 5092fe7..a5b6fd4 100644
--- a/qerror.c
+++ b/qerror.c
@@ -172,6 +172,10 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Parameter '%(name)' expects %(expected)",
     },
     {
+        .error_fmt = QERR_TOO_MANY_PARAMETERS,
+        .desc      = "Too many parameters",
+    },
+    {
         .error_fmt = QERR_INVALID_PASSWORD,
         .desc      = "Password incorrect",
     },
diff --git a/qerror.h b/qerror.h
index 4cbba48..5341ea6 100644
--- a/qerror.h
+++ b/qerror.h
@@ -151,6 +151,9 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_INVALID_PARAMETER_VALUE \
     "{ 'class': 'InvalidParameterValue', 'data': { 'name': %s, 'expected': %s } }"
 
+#define QERR_TOO_MANY_PARAMETERS \
+    "{ 'class': 'TooManyParameters', 'data': {} }"
+
 #define QERR_INVALID_PASSWORD \
     "{ 'class': 'InvalidPassword', 'data': {} }"
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH 2/3] fix doc of using raw values with sendkey
  2012-05-25  3:31 [Qemu-devel] [PATCH 1/3] qerror: add QERR_TOO_MANY_PARAMETERS Amos Kong
@ 2012-05-25  3:32 ` Amos Kong
  2012-05-25  3:32 ` [Qemu-devel] [PATCH 3/3] qapi: convert sendkey Amos Kong
  1 sibling, 0 replies; 15+ messages in thread
From: Amos Kong @ 2012-05-25  3:32 UTC (permalink / raw)
  To: aliguori, eblake, berrange, lcapitulino, qemu-devel; +Cc: Amos Kong

(qemu) sendkey a
(qemu) sendkey 0x1e
(qemu) sendkey #0x1e
 unknown key: '#0x1e'

The last command doesn't work, '#' is not request before raw values.

Signed-off-by: Amos Kong <akong@redhat.com>
---
 hmp-commands.hx |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 18cb415..af18156 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -513,8 +513,8 @@ STEXI
 @findex sendkey
 
 Send @var{keys} to the emulator. @var{keys} could be the name of the
-key or @code{#} followed by the raw value in either decimal or hexadecimal
-format. Use @code{-} to press several keys simultaneously. Example:
+key or the raw value in either decimal or hexadecimal format. Use
+@code{-} to press several keys simultaneously. Example:
 @example
 sendkey ctrl-alt-f1
 @end example
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  3:31 [Qemu-devel] [PATCH 1/3] qerror: add QERR_TOO_MANY_PARAMETERS Amos Kong
  2012-05-25  3:32 ` [Qemu-devel] [PATCH 2/3] fix doc of using raw values with sendkey Amos Kong
@ 2012-05-25  3:32 ` Amos Kong
  2012-05-25  3:51   ` Eric Blake
  2012-05-25 14:35   ` Luiz Capitulino
  1 sibling, 2 replies; 15+ messages in thread
From: Amos Kong @ 2012-05-25  3:32 UTC (permalink / raw)
  To: aliguori, eblake, berrange, lcapitulino, qemu-devel; +Cc: Amos Kong

Convert 'sendkey' to use. do_sendkey() depends on some variables
in monitor.c, so reserve qmp_sendkey() to monitor.c
Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'

Signed-off-by: Amos Kong <akong@redhat.com>
---
 hmp-commands.hx  |    4 ++--
 hmp.c            |   11 +++++++++++
 hmp.h            |    1 +
 monitor.c        |   21 ++++++++++-----------
 qapi-schema.json |   20 ++++++++++++++++++++
 qmp-commands.hx  |   24 ++++++++++++++++++++++++
 6 files changed, 68 insertions(+), 13 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index af18156..afbfa61 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -502,10 +502,10 @@ ETEXI
 
     {
         .name       = "sendkey",
-        .args_type  = "string:s,hold_time:i?",
+        .args_type  = "keys:s,hold-time:i?",
         .params     = "keys [hold_ms]",
         .help       = "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)",
-        .mhandler.cmd = do_sendkey,
+        .mhandler.cmd = hmp_sendkey,
     },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index bb0952e..abb7b59 100644
--- a/hmp.c
+++ b/hmp.c
@@ -947,3 +947,14 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
     qmp_device_del(id, &err);
     hmp_handle_error(mon, &err);
 }
+
+void hmp_sendkey(Monitor *mon, const QDict *qdict)
+{
+    const char *keys = qdict_get_str(qdict, "keys");
+    int has_hold_time = qdict_haskey(qdict, "hold-time");
+    int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
+    Error *err = NULL;
+
+    qmp_sendkey(keys, has_hold_time, hold_time, &err);
+    hmp_handle_error(mon, &err);
+}
diff --git a/hmp.h b/hmp.h
index 443b812..40de72c 100644
--- a/hmp.h
+++ b/hmp.h
@@ -61,5 +61,6 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate(Monitor *mon, const QDict *qdict);
 void hmp_device_del(Monitor *mon, const QDict *qdict);
+void hmp_sendkey(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 12a6fe2..238f8da 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1377,14 +1377,12 @@ static void release_keys(void *opaque)
     }
 }
 
-static void do_sendkey(Monitor *mon, const QDict *qdict)
+void qmp_sendkey(const char *keys, bool has_hold_time, int64_t hold_time,
+                 Error **err)
 {
     char keyname_buf[16];
     char *separator;
     int keyname_len, keycode, i;
-    const char *string = qdict_get_str(qdict, "string");
-    int has_hold_time = qdict_haskey(qdict, "hold_time");
-    int hold_time = qdict_get_try_int(qdict, "hold_time", -1);
 
     if (nb_pending_keycodes > 0) {
         qemu_del_timer(key_timer);
@@ -1394,29 +1392,30 @@ static void do_sendkey(Monitor *mon, const QDict *qdict)
         hold_time = 100;
     i = 0;
     while (1) {
-        separator = strchr(string, '-');
-        keyname_len = separator ? separator - string : strlen(string);
+        separator = strchr(keys, '-');
+        keyname_len = separator ? separator - keys : strlen(keys);
         if (keyname_len > 0) {
-            pstrcpy(keyname_buf, sizeof(keyname_buf), string);
+            pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
             if (keyname_len > sizeof(keyname_buf) - 1) {
-                monitor_printf(mon, "invalid key: '%s...'\n", keyname_buf);
+                error_set(err, QERR_INVALID_PARAMETER_VALUE, "keyname_buf",
+                          keyname_buf);
                 return;
             }
             if (i == MAX_KEYCODES) {
-                monitor_printf(mon, "too many keys\n");
+                error_set(err, QERR_TOO_MANY_PARAMETERS);
                 return;
             }
             keyname_buf[keyname_len] = 0;
             keycode = get_keycode(keyname_buf);
             if (keycode < 0) {
-                monitor_printf(mon, "unknown key: '%s'\n", keyname_buf);
+                error_set(err, QERR_INVALID_PARAMETER, keyname_buf);
                 return;
             }
             keycodes[i++] = keycode;
         }
         if (!separator)
             break;
-        string = separator + 1;
+        keys = separator + 1;
     }
     nb_pending_keycodes = i;
     /* key down events */
diff --git a/qapi-schema.json b/qapi-schema.json
index 2ca7195..d1799bc 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1755,3 +1755,23 @@
 # Since: 0.14.0
 ##
 { 'command': 'device_del', 'data': {'id': 'str'} }
+
+##
+# @sendkey:
+#
+# Send keys to VM.
+#
+# @keys: key sequence
+# @hold-time: time to delay key up events
+#
+# Returns: Nothing on success
+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
+#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
+#
+# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
+#        key or the raw value in either decimal or hexadecimal  format. Use
+#        @code{-} to press several keys simultaneously.
+#
+# Since: 0.14.0
+##
+{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index db980fa..ad6fc21 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -335,6 +335,30 @@ Example:
 EQMP
 
     {
+        .name       = "sendkey",
+        .args_type  = "keys:s,hold-time:i?",
+        .mhandler.cmd_new = qmp_marshal_input_sendkey,
+    },
+
+SQMP
+sendkey
+----------
+
+Send keys to VM.
+
+Arguments:
+
+- "keys": key sequence (json-string)
+- "hold-time": time to delay key up events (josn-string, optional)
+
+Example:
+
+-> { "execute": "sendkey", "arguments": { "keys": "ctrl-alt-delete", "hold-time": 200 } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "cpu",
         .args_type  = "index:i",
         .mhandler.cmd_new = qmp_marshal_input_cpu,
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  3:32 ` [Qemu-devel] [PATCH 3/3] qapi: convert sendkey Amos Kong
@ 2012-05-25  3:51   ` Eric Blake
  2012-05-25  6:20     ` Amos Kong
  2012-05-25 13:14     ` Anthony Liguori
  2012-05-25 14:35   ` Luiz Capitulino
  1 sibling, 2 replies; 15+ messages in thread
From: Eric Blake @ 2012-05-25  3:51 UTC (permalink / raw)
  To: Amos Kong; +Cc: aliguori, qemu-devel, lcapitulino

[-- Attachment #1: Type: text/plain, Size: 1273 bytes --]

On 05/24/2012 09:32 PM, Amos Kong wrote:
> Convert 'sendkey' to use. do_sendkey() depends on some variables
> in monitor.c, so reserve qmp_sendkey() to monitor.c
> Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
> 
> Signed-off-by: Amos Kong <akong@redhat.com>

> +##
> +# @sendkey:
> +#
> +# Send keys to VM.
> +#
> +# @keys: key sequence
> +# @hold-time: time to delay key up events
> +#
> +# Returns: Nothing on success
> +#          If key is unknown or redundant, QERR_INVALID_PARAMETER
> +#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
> +#
> +# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
> +#        key or the raw value in either decimal or hexadecimal  format. Use
> +#        @code{-} to press several keys simultaneously.
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }

Rather than making 'keys' a free-form string where qemu then has to
parse '-' to separate keys, should we instead make it a JSON array?  For
example,

{ "execute":"sendky", "data":{ "keys":["ctrl", "alt", "del"],
"hold-time":200 } }

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  3:51   ` Eric Blake
@ 2012-05-25  6:20     ` Amos Kong
  2012-05-25  7:34       ` Daniel P. Berrange
  2012-05-25 13:00       ` Luiz Capitulino
  2012-05-25 13:14     ` Anthony Liguori
  1 sibling, 2 replies; 15+ messages in thread
From: Amos Kong @ 2012-05-25  6:20 UTC (permalink / raw)
  To: Eric Blake; +Cc: aliguori, qemu-devel, lcapitulino

On 25/05/12 11:51, Eric Blake wrote:
> On 05/24/2012 09:32 PM, Amos Kong wrote:
>> Convert 'sendkey' to use. do_sendkey() depends on some variables
>> in monitor.c, so reserve qmp_sendkey() to monitor.c
>> Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
>>
>> Signed-off-by: Amos Kong<akong@redhat.com>
>
>> +##
>> +# @sendkey:
>> +#
>> +# Send keys to VM.
>> +#
>> +# @keys: key sequence
>> +# @hold-time: time to delay key up events
>> +#
>> +# Returns: Nothing on success
>> +#          If key is unknown or redundant, QERR_INVALID_PARAMETER
>> +#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
>> +#
>> +# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
>> +#        key or the raw value in either decimal or hexadecimal  format. Use
>> +#        @code{-} to press several keys simultaneously.
>> +#
>> +# Since: 0.14.0
>> +##
>> +{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
>
> Rather than making 'keys' a free-form string where qemu then has to
> parse '-' to separate keys, should we instead make it a JSON array?  For
> example,


Anthony, Luiz, Daniel,  what's your opinion?


> { "execute":"sendkey", "data":{ "keys":["ctrl", "alt", "del"],
> "hold-time":200 } }

How to make it compatible with hum command? Still use 'ctrl-alt-delete'
for hum, separate keys and generate an array in hum_sendkey() before
calling qmp_sendkey()?


And I'm know clear about how to define command in qapi-schema.json,
I didn't find exist example, any clue?

   { 'command': 'sendkey', 'data': { 'keys': [ 'str'], '*hold-time': 
'int'} }
--
   { 'type': 'Key', 'data': {'name': 'str'} }
   { 'command': 'sendkey', 'data': { 'keys': [ 'Key' ], '*hold-time': 
'int'} }


-- 
			Amos.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  6:20     ` Amos Kong
@ 2012-05-25  7:34       ` Daniel P. Berrange
  2012-05-25 12:18         ` Markus Armbruster
  2012-05-25 13:06         ` Luiz Capitulino
  2012-05-25 13:00       ` Luiz Capitulino
  1 sibling, 2 replies; 15+ messages in thread
From: Daniel P. Berrange @ 2012-05-25  7:34 UTC (permalink / raw)
  To: Amos Kong; +Cc: aliguori, Eric Blake, qemu-devel, lcapitulino

On Fri, May 25, 2012 at 02:20:33PM +0800, Amos Kong wrote:
> On 25/05/12 11:51, Eric Blake wrote:
> >On 05/24/2012 09:32 PM, Amos Kong wrote:
> >>Convert 'sendkey' to use. do_sendkey() depends on some variables
> >>in monitor.c, so reserve qmp_sendkey() to monitor.c
> >>Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
> >>
> >>Signed-off-by: Amos Kong<akong@redhat.com>
> >
> >>+##
> >>+# @sendkey:
> >>+#
> >>+# Send keys to VM.
> >>+#
> >>+# @keys: key sequence
> >>+# @hold-time: time to delay key up events
> >>+#
> >>+# Returns: Nothing on success
> >>+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
> >>+#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
> >>+#
> >>+# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
> >>+#        key or the raw value in either decimal or hexadecimal  format. Use
> >>+#        @code{-} to press several keys simultaneously.
> >>+#
> >>+# Since: 0.14.0
> >>+##
> >>+{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
> >
> >Rather than making 'keys' a free-form string where qemu then has to
> >parse '-' to separate keys, should we instead make it a JSON array?  For
> >example,
> 
> 
> Anthony, Luiz, Daniel,  what's your opinion?

Using a JSON array for the key names does seem like the most
natural way to model this. A good rule of thumb is that the
implementation of a command should not need to further
parse the individual parameter values. Using a magic string
encoding instead of the JSON array requires such extra special
case parsing.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  7:34       ` Daniel P. Berrange
@ 2012-05-25 12:18         ` Markus Armbruster
  2012-05-25 13:06         ` Luiz Capitulino
  1 sibling, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2012-05-25 12:18 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: aliguori, Amos Kong, Eric Blake, qemu-devel, lcapitulino

"Daniel P. Berrange" <berrange@redhat.com> writes:

> On Fri, May 25, 2012 at 02:20:33PM +0800, Amos Kong wrote:
>> On 25/05/12 11:51, Eric Blake wrote:
>> >On 05/24/2012 09:32 PM, Amos Kong wrote:
>> >>Convert 'sendkey' to use. do_sendkey() depends on some variables
>> >>in monitor.c, so reserve qmp_sendkey() to monitor.c
>> >>Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
>> >>
>> >>Signed-off-by: Amos Kong<akong@redhat.com>
>> >
>> >>+##
>> >>+# @sendkey:
>> >>+#
>> >>+# Send keys to VM.
>> >>+#
>> >>+# @keys: key sequence
>> >>+# @hold-time: time to delay key up events
>> >>+#
>> >>+# Returns: Nothing on success
>> >>+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
>> >>+#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
>> >>+#
>> >>+# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
>> >>+#        key or the raw value in either decimal or hexadecimal  format. Use
>> >>+#        @code{-} to press several keys simultaneously.
>> >>+#
>> >>+# Since: 0.14.0
>> >>+##
>> >>+{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
>> >
>> >Rather than making 'keys' a free-form string where qemu then has to
>> >parse '-' to separate keys, should we instead make it a JSON array?  For
>> >example,
>> 
>> 
>> Anthony, Luiz, Daniel,  what's your opinion?
>
> Using a JSON array for the key names does seem like the most
> natural way to model this. A good rule of thumb is that the
> implementation of a command should not need to further
> parse the individual parameter values. Using a magic string
> encoding instead of the JSON array requires such extra special
> case parsing.

We've followed this rule in QMP so far.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  6:20     ` Amos Kong
  2012-05-25  7:34       ` Daniel P. Berrange
@ 2012-05-25 13:00       ` Luiz Capitulino
  2012-05-25 14:23         ` Jeff Cody
  1 sibling, 1 reply; 15+ messages in thread
From: Luiz Capitulino @ 2012-05-25 13:00 UTC (permalink / raw)
  To: Amos Kong; +Cc: aliguori, Eric Blake, qemu-devel, Jeffrey Cody

On Fri, 25 May 2012 14:20:33 +0800
Amos Kong <akong@redhat.com> wrote:

> On 25/05/12 11:51, Eric Blake wrote:
> > On 05/24/2012 09:32 PM, Amos Kong wrote:
> >> Convert 'sendkey' to use. do_sendkey() depends on some variables
> >> in monitor.c, so reserve qmp_sendkey() to monitor.c
> >> Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
> >>
> >> Signed-off-by: Amos Kong<akong@redhat.com>
> >
> >> +##
> >> +# @sendkey:
> >> +#
> >> +# Send keys to VM.
> >> +#
> >> +# @keys: key sequence
> >> +# @hold-time: time to delay key up events
> >> +#
> >> +# Returns: Nothing on success
> >> +#          If key is unknown or redundant, QERR_INVALID_PARAMETER
> >> +#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
> >> +#
> >> +# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
> >> +#        key or the raw value in either decimal or hexadecimal  format. Use
> >> +#        @code{-} to press several keys simultaneously.
> >> +#
> >> +# Since: 0.14.0
> >> +##
> >> +{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
> >
> > Rather than making 'keys' a free-form string where qemu then has to
> > parse '-' to separate keys, should we instead make it a JSON array?  For
> > example,
> 
> 
> Anthony, Luiz, Daniel,  what's your opinion?

I agree it's better.

> > { "execute":"sendkey", "data":{ "keys":["ctrl", "alt", "del"],
> > "hold-time":200 } }
> 
> How to make it compatible with hum command? Still use 'ctrl-alt-delete'
> for hum, separate keys and generate an array in hum_sendkey() before
> calling qmp_sendkey()?

Yes. Basically, you'll move the parsing code to hmp_sendkey() and build
a QList to be passed to qmp_sendkey(). You can take a look at
tests/check-qlist.c for examples on how to work with qlists.

> And I'm know clear about how to define command in qapi-schema.json,
> I didn't find exist example, any clue?
> 
>    { 'command': 'sendkey', 'data': { 'keys': [ 'str'], '*hold-time': 
> 'int'} }
> --
>    { 'type': 'Key', 'data': {'name': 'str'} }
>    { 'command': 'sendkey', 'data': { 'keys': [ 'Key' ], '*hold-time': 
> 'int'} }

Jeff, didn't you implement this?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  7:34       ` Daniel P. Berrange
  2012-05-25 12:18         ` Markus Armbruster
@ 2012-05-25 13:06         ` Luiz Capitulino
  2012-05-25 13:12           ` Daniel P. Berrange
  2012-05-25 13:16           ` Anthony Liguori
  1 sibling, 2 replies; 15+ messages in thread
From: Luiz Capitulino @ 2012-05-25 13:06 UTC (permalink / raw)
  To: Daniel P. Berrange; +Cc: aliguori, Amos Kong, Eric Blake, qemu-devel

On Fri, 25 May 2012 08:34:54 +0100
"Daniel P. Berrange" <berrange@redhat.com> wrote:

> On Fri, May 25, 2012 at 02:20:33PM +0800, Amos Kong wrote:
> > On 25/05/12 11:51, Eric Blake wrote:
> > >On 05/24/2012 09:32 PM, Amos Kong wrote:
> > >>Convert 'sendkey' to use. do_sendkey() depends on some variables
> > >>in monitor.c, so reserve qmp_sendkey() to monitor.c
> > >>Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
> > >>
> > >>Signed-off-by: Amos Kong<akong@redhat.com>
> > >
> > >>+##
> > >>+# @sendkey:
> > >>+#
> > >>+# Send keys to VM.
> > >>+#
> > >>+# @keys: key sequence
> > >>+# @hold-time: time to delay key up events
> > >>+#
> > >>+# Returns: Nothing on success
> > >>+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
> > >>+#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
> > >>+#
> > >>+# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
> > >>+#        key or the raw value in either decimal or hexadecimal  format. Use
> > >>+#        @code{-} to press several keys simultaneously.
> > >>+#
> > >>+# Since: 0.14.0
> > >>+##
> > >>+{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
> > >
> > >Rather than making 'keys' a free-form string where qemu then has to
> > >parse '-' to separate keys, should we instead make it a JSON array?  For
> > >example,
> > 
> > 
> > Anthony, Luiz, Daniel,  what's your opinion?
> 
> Using a JSON array for the key names does seem like the most
> natural way to model this. A good rule of thumb is that the
> implementation of a command should not need to further
> parse the individual parameter values. Using a magic string
> encoding instead of the JSON array requires such extra special
> case parsing.

That's true, and I agree this is better.

Just would like to point out that we can't go too far on improving
HMP-inherited commands, as our goal here is to convert most (or every single)
HMP commands to QMP. If we go far on improving commands, we'll get stuck as we
did some time ago.

Btw, I remember someone saying that when libvirt wants to use a HMP command it
first checks if the command exists in QMP before using passthrough. In that case,
how will libvirt behave if we change the arguments?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25 13:06         ` Luiz Capitulino
@ 2012-05-25 13:12           ` Daniel P. Berrange
  2012-05-25 13:15             ` Luiz Capitulino
  2012-05-25 13:16           ` Anthony Liguori
  1 sibling, 1 reply; 15+ messages in thread
From: Daniel P. Berrange @ 2012-05-25 13:12 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: aliguori, Amos Kong, Eric Blake, qemu-devel

On Fri, May 25, 2012 at 10:06:11AM -0300, Luiz Capitulino wrote:
> On Fri, 25 May 2012 08:34:54 +0100
> "Daniel P. Berrange" <berrange@redhat.com> wrote:
> 
> > On Fri, May 25, 2012 at 02:20:33PM +0800, Amos Kong wrote:
> > > On 25/05/12 11:51, Eric Blake wrote:
> > > >On 05/24/2012 09:32 PM, Amos Kong wrote:
> > > >>Convert 'sendkey' to use. do_sendkey() depends on some variables
> > > >>in monitor.c, so reserve qmp_sendkey() to monitor.c
> > > >>Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
> > > >>
> > > >>Signed-off-by: Amos Kong<akong@redhat.com>
> > > >
> > > >>+##
> > > >>+# @sendkey:
> > > >>+#
> > > >>+# Send keys to VM.
> > > >>+#
> > > >>+# @keys: key sequence
> > > >>+# @hold-time: time to delay key up events
> > > >>+#
> > > >>+# Returns: Nothing on success
> > > >>+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
> > > >>+#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
> > > >>+#
> > > >>+# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
> > > >>+#        key or the raw value in either decimal or hexadecimal  format. Use
> > > >>+#        @code{-} to press several keys simultaneously.
> > > >>+#
> > > >>+# Since: 0.14.0
> > > >>+##
> > > >>+{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
> > > >
> > > >Rather than making 'keys' a free-form string where qemu then has to
> > > >parse '-' to separate keys, should we instead make it a JSON array?  For
> > > >example,
> > > 
> > > 
> > > Anthony, Luiz, Daniel,  what's your opinion?
> > 
> > Using a JSON array for the key names does seem like the most
> > natural way to model this. A good rule of thumb is that the
> > implementation of a command should not need to further
> > parse the individual parameter values. Using a magic string
> > encoding instead of the JSON array requires such extra special
> > case parsing.
> 
> That's true, and I agree this is better.
> 
> Just would like to point out that we can't go too far on improving
> HMP-inherited commands, as our goal here is to convert most (or every single)
> HMP commands to QMP. If we go far on improving commands, we'll get stuck as we
> did some time ago.
> 
> Btw, I remember someone saying that when libvirt wants to use a HMP command it
> first checks if the command exists in QMP before using passthrough. In that case,
> how will libvirt behave if we change the arguments?

We're not talking about changing the args of the existing HMP command,
and libvirt has no code for a QMP version of sendkey, so there's no
compatibility issue.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  3:51   ` Eric Blake
  2012-05-25  6:20     ` Amos Kong
@ 2012-05-25 13:14     ` Anthony Liguori
  1 sibling, 0 replies; 15+ messages in thread
From: Anthony Liguori @ 2012-05-25 13:14 UTC (permalink / raw)
  To: Eric Blake; +Cc: Amos Kong, qemu-devel, lcapitulino

On 05/24/2012 10:51 PM, Eric Blake wrote:
> On 05/24/2012 09:32 PM, Amos Kong wrote:
>> Convert 'sendkey' to use. do_sendkey() depends on some variables
>> in monitor.c, so reserve qmp_sendkey() to monitor.c
>> Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
>>
>> Signed-off-by: Amos Kong<akong@redhat.com>
>
>> +##
>> +# @sendkey:
>> +#
>> +# Send keys to VM.
>> +#
>> +# @keys: key sequence
>> +# @hold-time: time to delay key up events
>> +#
>> +# Returns: Nothing on success
>> +#          If key is unknown or redundant, QERR_INVALID_PARAMETER
>> +#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
>> +#
>> +# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
>> +#        key or the raw value in either decimal or hexadecimal  format. Use
>> +#        @code{-} to press several keys simultaneously.
>> +#
>> +# Since: 0.14.0
>> +##
>> +{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
>
> Rather than making 'keys' a free-form string where qemu then has to
> parse '-' to separate keys, should we instead make it a JSON array?  For
> example,
>
> { "execute":"sendky", "data":{ "keys":["ctrl", "alt", "del"],
> "hold-time":200 } }

Actually, we should do:

{ 'enum': 'KeyCode',
   'data': [ 'map', 'exclam', 'at', 'numbersign', ...] }

{ 'command': 'sendkey',
   'data': { 'keys': [ 'KeyCode' ], '*hold-time': 'int' } }

That also has the benefit of making it clear what symbolic names of the keycodes 
we support are.

Regards,

Anthony Liguori

>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25 13:12           ` Daniel P. Berrange
@ 2012-05-25 13:15             ` Luiz Capitulino
  0 siblings, 0 replies; 15+ messages in thread
From: Luiz Capitulino @ 2012-05-25 13:15 UTC (permalink / raw)
  To: Daniel P. Berrange; +Cc: aliguori, Amos Kong, Eric Blake, qemu-devel

On Fri, 25 May 2012 14:12:39 +0100
"Daniel P. Berrange" <berrange@redhat.com> wrote:

> On Fri, May 25, 2012 at 10:06:11AM -0300, Luiz Capitulino wrote:
> > On Fri, 25 May 2012 08:34:54 +0100
> > "Daniel P. Berrange" <berrange@redhat.com> wrote:
> > 
> > > On Fri, May 25, 2012 at 02:20:33PM +0800, Amos Kong wrote:
> > > > On 25/05/12 11:51, Eric Blake wrote:
> > > > >On 05/24/2012 09:32 PM, Amos Kong wrote:
> > > > >>Convert 'sendkey' to use. do_sendkey() depends on some variables
> > > > >>in monitor.c, so reserve qmp_sendkey() to monitor.c
> > > > >>Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
> > > > >>
> > > > >>Signed-off-by: Amos Kong<akong@redhat.com>
> > > > >
> > > > >>+##
> > > > >>+# @sendkey:
> > > > >>+#
> > > > >>+# Send keys to VM.
> > > > >>+#
> > > > >>+# @keys: key sequence
> > > > >>+# @hold-time: time to delay key up events
> > > > >>+#
> > > > >>+# Returns: Nothing on success
> > > > >>+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
> > > > >>+#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
> > > > >>+#
> > > > >>+# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
> > > > >>+#        key or the raw value in either decimal or hexadecimal  format. Use
> > > > >>+#        @code{-} to press several keys simultaneously.
> > > > >>+#
> > > > >>+# Since: 0.14.0
> > > > >>+##
> > > > >>+{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
> > > > >
> > > > >Rather than making 'keys' a free-form string where qemu then has to
> > > > >parse '-' to separate keys, should we instead make it a JSON array?  For
> > > > >example,
> > > > 
> > > > 
> > > > Anthony, Luiz, Daniel,  what's your opinion?
> > > 
> > > Using a JSON array for the key names does seem like the most
> > > natural way to model this. A good rule of thumb is that the
> > > implementation of a command should not need to further
> > > parse the individual parameter values. Using a magic string
> > > encoding instead of the JSON array requires such extra special
> > > case parsing.
> > 
> > That's true, and I agree this is better.
> > 
> > Just would like to point out that we can't go too far on improving
> > HMP-inherited commands, as our goal here is to convert most (or every single)
> > HMP commands to QMP. If we go far on improving commands, we'll get stuck as we
> > did some time ago.
> > 
> > Btw, I remember someone saying that when libvirt wants to use a HMP command it
> > first checks if the command exists in QMP before using passthrough. In that case,
> > how will libvirt behave if we change the arguments?
> 
> We're not talking about changing the args of the existing HMP command,
> and libvirt has no code for a QMP version of sendkey, so there's no
> compatibility issue.

Good.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25 13:06         ` Luiz Capitulino
  2012-05-25 13:12           ` Daniel P. Berrange
@ 2012-05-25 13:16           ` Anthony Liguori
  1 sibling, 0 replies; 15+ messages in thread
From: Anthony Liguori @ 2012-05-25 13:16 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: Eric Blake, Amos Kong, qemu-devel

On 05/25/2012 08:06 AM, Luiz Capitulino wrote:
> On Fri, 25 May 2012 08:34:54 +0100
> "Daniel P. Berrange"<berrange@redhat.com>  wrote:
>
>> On Fri, May 25, 2012 at 02:20:33PM +0800, Amos Kong wrote:
>>> On 25/05/12 11:51, Eric Blake wrote:
>>>> On 05/24/2012 09:32 PM, Amos Kong wrote:
>>>>> Convert 'sendkey' to use. do_sendkey() depends on some variables
>>>>> in monitor.c, so reserve qmp_sendkey() to monitor.c
>>>>> Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
>>>>>
>>>>> Signed-off-by: Amos Kong<akong@redhat.com>
>>>>
>>>>> +##
>>>>> +# @sendkey:
>>>>> +#
>>>>> +# Send keys to VM.
>>>>> +#
>>>>> +# @keys: key sequence
>>>>> +# @hold-time: time to delay key up events
>>>>> +#
>>>>> +# Returns: Nothing on success
>>>>> +#          If key is unknown or redundant, QERR_INVALID_PARAMETER
>>>>> +#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
>>>>> +#
>>>>> +# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
>>>>> +#        key or the raw value in either decimal or hexadecimal  format. Use
>>>>> +#        @code{-} to press several keys simultaneously.
>>>>> +#
>>>>> +# Since: 0.14.0
>>>>> +##
>>>>> +{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
>>>>
>>>> Rather than making 'keys' a free-form string where qemu then has to
>>>> parse '-' to separate keys, should we instead make it a JSON array?  For
>>>> example,
>>>
>>>
>>> Anthony, Luiz, Daniel,  what's your opinion?
>>
>> Using a JSON array for the key names does seem like the most
>> natural way to model this. A good rule of thumb is that the
>> implementation of a command should not need to further
>> parse the individual parameter values. Using a magic string
>> encoding instead of the JSON array requires such extra special
>> case parsing.
>
> That's true, and I agree this is better.
>
> Just would like to point out that we can't go too far on improving
> HMP-inherited commands, as our goal here is to convert most (or every single)
> HMP commands to QMP. If we go far on improving commands, we'll get stuck as we
> did some time ago.

I agree.  But obviously, changing the parameter syntax is straight forward 
enough.  I think we rat hole when we change the command semantics though.

>
> Btw, I remember someone saying that when libvirt wants to use a HMP command it
> first checks if the command exists in QMP before using passthrough. In that case,
> how will libvirt behave if we change the arguments?

I don't think libvirt can possibly be assuming that a QMP command exists that 
it's never seen before...  So hopefully this isn't a blind check.  If it is, 
it's a libvirt bug.

Regards,

Anthony Liguori

>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25 13:00       ` Luiz Capitulino
@ 2012-05-25 14:23         ` Jeff Cody
  0 siblings, 0 replies; 15+ messages in thread
From: Jeff Cody @ 2012-05-25 14:23 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: aliguori, Amos Kong, Eric Blake, qemu-devel

On 05/25/2012 09:00 AM, Luiz Capitulino wrote:
> On Fri, 25 May 2012 14:20:33 +0800
> Amos Kong <akong@redhat.com> wrote:
> 
>> On 25/05/12 11:51, Eric Blake wrote:
>>> On 05/24/2012 09:32 PM, Amos Kong wrote:
>>>> Convert 'sendkey' to use. do_sendkey() depends on some variables
>>>> in monitor.c, so reserve qmp_sendkey() to monitor.c
>>>> Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'
>>>>
>>>> Signed-off-by: Amos Kong<akong@redhat.com>
>>>
>>>> +##
>>>> +# @sendkey:
>>>> +#
>>>> +# Send keys to VM.
>>>> +#
>>>> +# @keys: key sequence
>>>> +# @hold-time: time to delay key up events
>>>> +#
>>>> +# Returns: Nothing on success
>>>> +#          If key is unknown or redundant, QERR_INVALID_PARAMETER
>>>> +#          If key is invalid, QERR_INVALID_PARAMETER_VALUE
>>>> +#
>>>> +# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
>>>> +#        key or the raw value in either decimal or hexadecimal  format. Use
>>>> +#        @code{-} to press several keys simultaneously.
>>>> +#
>>>> +# Since: 0.14.0
>>>> +##
>>>> +{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
>>>
>>> Rather than making 'keys' a free-form string where qemu then has to
>>> parse '-' to separate keys, should we instead make it a JSON array?  For
>>> example,
>>
>>
>> Anthony, Luiz, Daniel,  what's your opinion?
> 
> I agree it's better.
> 
>>> { "execute":"sendkey", "data":{ "keys":["ctrl", "alt", "del"],
>>> "hold-time":200 } }
>>
>> How to make it compatible with hum command? Still use 'ctrl-alt-delete'
>> for hum, separate keys and generate an array in hum_sendkey() before
>> calling qmp_sendkey()?
> 
> Yes. Basically, you'll move the parsing code to hmp_sendkey() and build
> a QList to be passed to qmp_sendkey(). You can take a look at
> tests/check-qlist.c for examples on how to work with qlists.
> 
>> And I'm know clear about how to define command in qapi-schema.json,
>> I didn't find exist example, any clue?
>>
>>    { 'command': 'sendkey', 'data': { 'keys': [ 'str'], '*hold-time': 
>> 'int'} }
>> --
>>    { 'type': 'Key', 'data': {'name': 'str'} }
>>    { 'command': 'sendkey', 'data': { 'keys': [ 'Key' ], '*hold-time': 
>> 'int'} }
> 
> Jeff, didn't you implement this?

Something similar with group snapshots - it had a command that took
an array input.

So I think the schema for what Eric had above would be something like:

{ 'type': 'Sendkey',
  'data': {'key': 'str' } }

{ 'command': 'sendkey',
  'data': { 'keylist': [ 'Sendkey' ], '*hold-time': 'int' } }

(But after typing this I see Anthony has proposed a schema using enums)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
  2012-05-25  3:32 ` [Qemu-devel] [PATCH 3/3] qapi: convert sendkey Amos Kong
  2012-05-25  3:51   ` Eric Blake
@ 2012-05-25 14:35   ` Luiz Capitulino
  1 sibling, 0 replies; 15+ messages in thread
From: Luiz Capitulino @ 2012-05-25 14:35 UTC (permalink / raw)
  To: Amos Kong; +Cc: aliguori, eblake, qemu-devel

On Fri, 25 May 2012 11:32:01 +0800
Amos Kong <akong@redhat.com> wrote:

> Convert 'sendkey' to use. do_sendkey() depends on some variables
> in monitor.c, so reserve qmp_sendkey() to monitor.c
> Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'

Splitting the args rename to a different patch would make review easier. Also,
please, include a cover letter as patch 0/3.

In general looks good, but apart the argument re-work others suggested I have
some comments below.

> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
>  hmp-commands.hx  |    4 ++--
>  hmp.c            |   11 +++++++++++
>  hmp.h            |    1 +
>  monitor.c        |   21 ++++++++++-----------
>  qapi-schema.json |   20 ++++++++++++++++++++
>  qmp-commands.hx  |   24 ++++++++++++++++++++++++
>  6 files changed, 68 insertions(+), 13 deletions(-)
> 
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index af18156..afbfa61 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -502,10 +502,10 @@ ETEXI
>  
>      {
>          .name       = "sendkey",
> -        .args_type  = "string:s,hold_time:i?",
> +        .args_type  = "keys:s,hold-time:i?",
>          .params     = "keys [hold_ms]",
>          .help       = "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)",
> -        .mhandler.cmd = do_sendkey,
> +        .mhandler.cmd = hmp_sendkey,
>      },
>  
>  STEXI
> diff --git a/hmp.c b/hmp.c
> index bb0952e..abb7b59 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -947,3 +947,14 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
>      qmp_device_del(id, &err);
>      hmp_handle_error(mon, &err);
>  }
> +
> +void hmp_sendkey(Monitor *mon, const QDict *qdict)
> +{
> +    const char *keys = qdict_get_str(qdict, "keys");
> +    int has_hold_time = qdict_haskey(qdict, "hold-time");
> +    int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
> +    Error *err = NULL;
> +
> +    qmp_sendkey(keys, has_hold_time, hold_time, &err);
> +    hmp_handle_error(mon, &err);
> +}
> diff --git a/hmp.h b/hmp.h
> index 443b812..40de72c 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -61,5 +61,6 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
>  void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
>  void hmp_migrate(Monitor *mon, const QDict *qdict);
>  void hmp_device_del(Monitor *mon, const QDict *qdict);
> +void hmp_sendkey(Monitor *mon, const QDict *qdict);
>  
>  #endif
> diff --git a/monitor.c b/monitor.c
> index 12a6fe2..238f8da 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -1377,14 +1377,12 @@ static void release_keys(void *opaque)
>      }
>  }
>  
> -static void do_sendkey(Monitor *mon, const QDict *qdict)
> +void qmp_sendkey(const char *keys, bool has_hold_time, int64_t hold_time,
> +                 Error **err)
>  {
>      char keyname_buf[16];
>      char *separator;
>      int keyname_len, keycode, i;
> -    const char *string = qdict_get_str(qdict, "string");
> -    int has_hold_time = qdict_haskey(qdict, "hold_time");
> -    int hold_time = qdict_get_try_int(qdict, "hold_time", -1);
>  
>      if (nb_pending_keycodes > 0) {
>          qemu_del_timer(key_timer);
> @@ -1394,29 +1392,30 @@ static void do_sendkey(Monitor *mon, const QDict *qdict)
>          hold_time = 100;
>      i = 0;
>      while (1) {
> -        separator = strchr(string, '-');
> -        keyname_len = separator ? separator - string : strlen(string);
> +        separator = strchr(keys, '-');
> +        keyname_len = separator ? separator - keys : strlen(keys);
>          if (keyname_len > 0) {
> -            pstrcpy(keyname_buf, sizeof(keyname_buf), string);
> +            pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
>              if (keyname_len > sizeof(keyname_buf) - 1) {
> -                monitor_printf(mon, "invalid key: '%s...'\n", keyname_buf);
> +                error_set(err, QERR_INVALID_PARAMETER_VALUE, "keyname_buf",
> +                          keyname_buf);

You should pass "key name" in the first string.

>                  return;
>              }
>              if (i == MAX_KEYCODES) {
> -                monitor_printf(mon, "too many keys\n");
> +                error_set(err, QERR_TOO_MANY_PARAMETERS);
>                  return;
>              }

I know I suggested TOO_MANY_PARAMETERS myself, but having QERR_OVERFLOW
would be better (and we should of course document that in the schema).

On the other hand I wonder if we should limit this, do we limit filenames
for example? Or maybe we should limit it to a bigger size, like 256 bytes.

Your choice.

>              keyname_buf[keyname_len] = 0;
>              keycode = get_keycode(keyname_buf);
>              if (keycode < 0) {
> -                monitor_printf(mon, "unknown key: '%s'\n", keyname_buf);
> +                error_set(err, QERR_INVALID_PARAMETER, keyname_buf);
>                  return;
>              }
>              keycodes[i++] = keycode;
>          }
>          if (!separator)
>              break;
> -        string = separator + 1;
> +        keys = separator + 1;
>      }
>      nb_pending_keycodes = i;
>      /* key down events */
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 2ca7195..d1799bc 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -1755,3 +1755,23 @@
>  # Since: 0.14.0
>  ##
>  { 'command': 'device_del', 'data': {'id': 'str'} }
> +
> +##
> +# @sendkey:
> +#
> +# Send keys to VM.
> +#
> +# @keys: key sequence
> +# @hold-time: time to delay key up events

Miliseconds?

> +#
> +# Returns: Nothing on success
> +#          If key is unknown or redundant, QERR_INVALID_PARAMETER
> +#          If key is invalid, QERR_INVALID_PARAMETER_VALUE

Please, use the class name (eg. InvalidParameter) instead of the qerror macro.
Also, don't forget to document the Overflow error.

> +#
> +# Notes: Send @var{keys} to the emulator. @var{keys} could be the name of the
> +#        key or the raw value in either decimal or hexadecimal  format. Use
> +#        @code{-} to press several keys simultaneously.

Please, move this right below "Send keys to the VM" and drop the @var{} notation,
as it's only used in the .hx files.

> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index db980fa..ad6fc21 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -335,6 +335,30 @@ Example:
>  EQMP
>  
>      {
> +        .name       = "sendkey",
> +        .args_type  = "keys:s,hold-time:i?",
> +        .mhandler.cmd_new = qmp_marshal_input_sendkey,
> +    },
> +
> +SQMP
> +sendkey
> +----------
> +
> +Send keys to VM.
> +
> +Arguments:
> +
> +- "keys": key sequence (json-string)
> +- "hold-time": time to delay key up events (josn-string, optional)
> +
> +Example:
> +
> +-> { "execute": "sendkey", "arguments": { "keys": "ctrl-alt-delete", "hold-time": 200 } }
> +<- { "return": {} }
> +
> +EQMP
> +
> +    {
>          .name       = "cpu",
>          .args_type  = "index:i",
>          .mhandler.cmd_new = qmp_marshal_input_cpu,

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2012-05-25 14:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-25  3:31 [Qemu-devel] [PATCH 1/3] qerror: add QERR_TOO_MANY_PARAMETERS Amos Kong
2012-05-25  3:32 ` [Qemu-devel] [PATCH 2/3] fix doc of using raw values with sendkey Amos Kong
2012-05-25  3:32 ` [Qemu-devel] [PATCH 3/3] qapi: convert sendkey Amos Kong
2012-05-25  3:51   ` Eric Blake
2012-05-25  6:20     ` Amos Kong
2012-05-25  7:34       ` Daniel P. Berrange
2012-05-25 12:18         ` Markus Armbruster
2012-05-25 13:06         ` Luiz Capitulino
2012-05-25 13:12           ` Daniel P. Berrange
2012-05-25 13:15             ` Luiz Capitulino
2012-05-25 13:16           ` Anthony Liguori
2012-05-25 13:00       ` Luiz Capitulino
2012-05-25 14:23         ` Jeff Cody
2012-05-25 13:14     ` Anthony Liguori
2012-05-25 14:35   ` Luiz Capitulino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).