qerror: add QERR_TOO_MANY_PARAMETERS
PATCH 1/3 qerror: add QERR_TOO_MANY_PARAMETERS
--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -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", },
qerror.h +3 -0
@@ -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': {} }"
Signature · 1 line
1.7.1
PATCH 2/3 fix doc of using raw values with sendkey
(qemu) sendkey a
(qemu) sendkey 0x1e
(qemu) sendkey #0x1e
unknown key: '#0x1e'
The last command doesn't work, '#' is not request before raw values.
--- hmp-commands.hx | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
hmp-commands.hx +2 -2
@@ -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
Signature · 1 line
1.7.1
PATCH 3/3 qapi: convert sendkey
In reply to Amos KongConvert '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'
--- 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(-)
hmp-commands.hx +2 -2
@@ -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
hmp.c +11 -0
@@ -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); +}
hmp.h +1 -0
@@ -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
monitor.c +10 -11
@@ -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 */
qapi-schema.json +20 -0
@@ -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'} }
qmp-commands.hx +24 -0
@@ -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,
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
Quoted 15 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong <[email protected]>qapi-schema.json +9
-0+## +# @sendkey: +# +# Send keys to VM. +# +# @keys: key sequence +# @hold-time: time to delay key up events +# +# Returns: Nothing on success
qapi-schema.json line 1777
Quoted 10 lines
qapi-schema.json +10
-0+# 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 } }
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
Quoted 22 lines · Eric Blake
Quoted 21 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +15
-0+## +# @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.
Quoted 8 lines
qapi-schema.json line 1777
Quoted 4 lines
qapi-schema.json +4
-0+# +# 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?
Quoted 2 lines
{ "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'} }
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
Quoted 33 lines · Amos Kong
Quoted 22 lines · Eric Blake
Quoted 21 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +15
-0+## +# @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.Quoted 8 lines
qapi-schema.json line 1777
Quoted 4 lines
qapi-schema.json +4
-0+# +# 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,
Quoted 1 line
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
Signature · 4 lines
|: 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 :|
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
Quoted 34 lines · Daniel P. Berrange
Quoted 33 lines · Amos Kong
Quoted 30 lines · Eric Blake
Quoted 15 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +9
-0+## +# @sendkey: +# +# Send keys to VM. +# +# @keys: key sequence +# @hold-time: time to delay key up events +# +# Returns: Nothing on successqapi-schema.json line 1777
Quoted 10 lines
qapi-schema.json +10
-0+# 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,
Quoted 8 lines
Quoted 1 line
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.
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
In reply to Daniel P. BerrangeQuoted 34 lines · On Fri, 25 May 2012 08:34:54 +0100 "Daniel P. Berrange" <[email protected]>…
Quoted 33 lines · Amos Kong
Quoted 30 lines · Eric Blake
Quoted 15 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +9
-0+## +# @sendkey: +# +# Send keys to VM. +# +# @keys: key sequence +# @hold-time: time to delay key up events +# +# Returns: Nothing on successqapi-schema.json line 1777
Quoted 10 lines
qapi-schema.json +10
-0+# 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,
Quoted 8 lines
Quoted 1 line
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?
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
Quoted 48 lines · Luiz Capitulino
Quoted 34 lines · On Fri, 25 May 2012 08:34:54 +0100 "Daniel P. Berrange" <[email protected]>…
Quoted 33 lines · Amos Kong
Quoted 30 lines · Eric Blake
Quoted 15 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +9
-0+## +# @sendkey: +# +# Send keys to VM. +# +# @keys: key sequence +# @hold-time: time to delay key up events +# +# Returns: Nothing on successqapi-schema.json line 1777
Quoted 10 lines
qapi-schema.json +10
-0+# 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,
Quoted 8 lines
Quoted 1 line
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.
Quoted 8 lines
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
Signature · 4 lines
|: 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 :|
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
Quoted 54 lines · On Fri, 25 May 2012 14:12:39 +0100 "Daniel P. Berrange" <[email protected]>…
Quoted 53 lines · Luiz Capitulino
Quoted 34 lines · On Fri, 25 May 2012 08:34:54 +0100 "Daniel P. Berrange" <[email protected]>…
Quoted 33 lines · Amos Kong
Quoted 30 lines · Eric Blake
Quoted 15 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +9
-0+## +# @sendkey: +# +# Send keys to VM. +# +# @keys: key sequence +# @hold-time: time to delay key up events +# +# Returns: Nothing on successqapi-schema.json line 1777
Quoted 10 lines
qapi-schema.json +10
-0+# 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,
Quoted 8 lines
Quoted 1 line
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.
Quoted 7 lines
Quoted 3 lines
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.
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
In reply to Luiz CapitulinoQuoted 46 lines · Luiz Capitulino
Quoted 34 lines · On Fri, 25 May 2012 08:34:54 +0100 "Daniel P. Berrange"<[email protected]>…
Quoted 33 lines · Amos Kong
Quoted 30 lines · Eric Blake
Quoted 15 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +9
-0+## +# @sendkey: +# +# Send keys to VM. +# +# @keys: key sequence +# @hold-time: time to delay key up events +# +# Returns: Nothing on successqapi-schema.json line 1777
Quoted 10 lines
qapi-schema.json +10
-0+# 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,
Quoted 8 lines
Quoted 1 line
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.
Quoted 6 lines
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.
Quoted 4 lines
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
Quoted 1 line
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
In reply to Amos KongQuoted 33 lines · On Fri, 25 May 2012 14:20:33 +0800 Amos Kong <[email protected]> wrote:
Quoted 22 lines · Eric Blake
Quoted 21 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +15
-0+## +# @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.Quoted 8 lines
qapi-schema.json line 1777
Quoted 4 lines
qapi-schema.json +4
-0+# +# 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,
Quoted 1 line
Anthony, Luiz, Daniel, what's your opinion?
I agree it's better.
Quoted 6 lines
Quoted 2 lines
{ "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 callingqmp_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.
Quoted 9 lines
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?
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
Quoted 54 lines · Luiz Capitulino
Quoted 33 lines · On Fri, 25 May 2012 14:20:33 +0800 Amos Kong <[email protected]> wrote:
Quoted 22 lines · Eric Blake
Quoted 21 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +15
-0+## +# @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.Quoted 8 lines
qapi-schema.json line 1777
Quoted 4 lines
qapi-schema.json +4
-0+# +# 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,
Quoted 1 line
Anthony, Luiz, Daniel, what's your opinion?
I agree it's better.
Quoted 6 lines
Quoted 2 lines
{ "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 callingqmp_sendkey()?Yes. Basically, you'll move the parsing code to
hmp_sendkey()and build a QList to be passed toqmp_sendkey(). You can take a look attests/check-qlist.cfor examples on how to work with qlists.Quoted 3 lines
And I'm know clear about how to define command in qapi-schema.json, I didn't find exist example, any clue?
Quoted 8 lines
Quoted 6 lines
{ '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)
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
In reply to Eric BlakeQuoted 31 lines · Eric Blake
Quoted 15 lines · Amos Kong
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename 'string' to 'keys', rename 'hold_time' to 'hold-time'Signed-off-by Amos Kong<[email protected]>qapi-schema.json +9
-0+## +# @sendkey: +# +# Send keys to VM. +# +# @keys: key sequence +# @hold-time: time to delay key up events +# +# Returns: Nothing on successqapi-schema.json line 1777
Quoted 10 lines
qapi-schema.json +10
-0+# 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,
Quoted 2 lines
{ "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
Quoted 1 line
Re: [Qemu-devel] [PATCH 3/3] qapi: convert sendkey
In reply to Amos KongQuoted 3 lines · On Fri, 25 May 2012 11:32:01 +0800 Amos Kong <[email protected]> wrote:
Convert 'sendkey' to use.
do_sendkey()depends on some variables inmonitor.c, so reserveqmp_sendkey()tomonitor.cRename '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.
Quoted 83 lines
Signed-off-by Amos Kong <[email protected]>--- 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(-)hmp-commands.hx +2
-2@@ -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, }, STEXIhmp.c +11
-0@@ -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); +}hmp.h +1
-0@@ -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 monitor.c +2
-5@@ -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,'-' );
monitor.c static void do_sendkey(Monitor *mon, const QDict *qdict) · line 1401
Quoted 10 lines
monitor.c +5
-3- 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.
monitor.c static void do_sendkey(Monitor *mon, const QDict *qdict) · line 1407
Quoted 7 lines
monitor.c +1
-1return ; }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.
Quoted 22 lines
monitor.c +2
-2keyname_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 */ qapi-schema.json +0
-0@@ -1755,3 +1755,23 @@ # Since: 0.14.0
qapi-schema.json line 1765
Quoted 10 lines
qapi-schema.json +8
-0## { 'command': 'device_del', 'data': {'id': 'str'} } + +## +# @sendkey: +# +# Send keys to VM. +# +# @keys: key sequence +# @hold-time: time to delay key up events
Miliseconds?
qapi-schema.json line 1769
Quoted 4 lines
qapi-schema.json +4
-0+# +# 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.
qapi-schema.json line 1773
Quoted 4 lines
qapi-schema.json +4
-0+# +# 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.
Quoted 39 lines
qapi-schema.json +4
-0+# +# Since: 0.14.0 +## +{ 'command': 'sendkey', 'data': {'keys': 'str', '*hold-time': 'int'} }qmp-commands.hx +24
-0@@ -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,