Skip to contentSkip to conversation

convert sendkey to qapi

PATCH Superseded Amos Kong 7 participants 33 messages Jun 1, 2012 – Jun 19, 2012 4 messages not in the archive

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

v2 cover convert sendkey to qapi

This series converted 'sendkey' command to qapi.

Amos Kong (6):
qerror: add QERR_OVERFLOW
fix doc of using raw values with sendkey rename keyname '<' to 'less'
hmp: rename arguments
qapi: generate list struct and visit_list for enum
qapi: convert sendkey

 hmp-commands.hx       |    8 +++---
 hmp.c                 |   56 +++++++++++++++++++++++++++++++++++++++++
 hmp.h                 |    1 +
 monitor.c             |   67 ++++++++++++++-----------------------------------
 qapi-schema.json      |   47 ++++++++++++++++++++++++++++++++++
 qerror.c              |    4 +++
 qerror.h              |    3 ++
 qmp-commands.hx       |   27 +++++++++++++++++++
 scripts/qapi-types.py |   33 +++++++++++++++++++++---
 scripts/qapi-visit.py |   14 ++++++---
 10 files changed, 199 insertions(+), 61 deletions(-)
author
#1 lore raw

PATCH v2 1/6 qerror: add QERR_OVERFLOW

---
 qerror.c |    4 ++++
 qerror.h |    3 +++
 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
index 5092fe7..b66af09 100644
@@ -172,6 +172,10 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Parameter '%(name)' expects %(expected)",
     },
     {
+        .error_fmt = QERR_OVERFLOW,
+        .desc      = "Input is overflow",
+    },
+    {
         .error_fmt = QERR_INVALID_PASSWORD,
         .desc      = "Password incorrect",
     },
qerror.h +3 -0
index 4cbba48..dfe9c89 100644
@@ -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_OVERFLOW \
+    "{ 'class': 'Overflow', 'data': {} }"
+
 #define QERR_INVALID_PASSWORD \
     "{ 'class': 'InvalidPassword', 'data': {} }"
 
Signature · 1 line
1.7.1
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/6] qerror: add QERR_OVERFLOW

Quoted 1 line · Amos Kong

I think QERR_INVALID_PARAMETER_VALUE is a more logical choice for the error you're generating.

Regards,

Anthony Liguori

Quoted 34 lines
---
  qerror.c |    4 ++++
  qerror.h |    3 +++
  2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
index 5092fe7..b66af09 100644
@@ -172,6 +172,10 @@ static const QErrorStringTable qerror_table[] = {
          .desc      = "Parameter '%(name)' expects %(expected)",
      },
      {
+        .error_fmt = QERR_OVERFLOW,
+        .desc      = "Input is overflow",
+    },
+    {
          .error_fmt = QERR_INVALID_PASSWORD,
          .desc      = "Password incorrect",
      },
qerror.h +3 -0
index 4cbba48..dfe9c89 100644
@@ -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_OVERFLOW \
+    "{ 'class': 'Overflow', 'data': {} }"
+
  #define QERR_INVALID_PASSWORD \
      "{ 'class': 'InvalidPassword', 'data': {} }"
 
author
#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

----- Original Message -----

Quoted 6 lines · Amos Kong
Quoted 1 line

I think QERR_INVALID_PARAMETER_VALUE is a more logical choice for the error
you're generating.

I used this new error in [PATCH 6/6], if user inputs more than 16 keys once, this error will occur, even if all the keys are valid.
If user sees the new error, they will identify that keys number should be reduced. But 'QERR_INVALID_PARAMETER_VALUE' could not pass this information to user.

Amos.

Quoted 42 lines

Regards,

Anthony Liguori

Quoted 36 lines
---
  qerror.c |    4 ++++
  qerror.h |    3 +++
  2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
index 5092fe7..b66af09 100644
@@ -172,6 +172,10 @@ static const QErrorStringTable qerror_table[]
 = {
          .desc      = "Parameter '%(name)' expects %(expected)",
      },
      {
+        .error_fmt = QERR_OVERFLOW,
+        .desc      = "Input is overflow",
+    },
+    {
          .error_fmt = QERR_INVALID_PASSWORD,
          .desc      = "Password incorrect",
      },
qerror.h +3 -0
index 4cbba48..dfe9c89 100644
@@ -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_OVERFLOW \
+    "{ 'class': 'Overflow', 'data': {} }"
+
  #define QERR_INVALID_PASSWORD \
      "{ 'class': 'InvalidPassword', 'data': {} }"

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#8 lore raw

Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

Quoted 1 line · Luiz Capitulino
Quoted 1 line

Hi Luiz, Anthony

Quoted 1 line
Quoted 1 line

BTW, why is there a 16 keycode limit?

'Sendkey' command was added by this commit a3a91a355bc6107b7d06d722fb97d2b80065ee0b Limitation of keycodes number (16) was also introduced here,
and I didn't find the root reason.

Quoted 5 lines
Quoted 1 line

That's a good point. This comes form the array used by the original implementation to store the keycodes.

Amos, is it still needed now that we're using qapi lists?

I try to drop this limitation from monitor.c [1], then execute

(qemu) sendkey 1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0

kbd_put_keycode() are called for all (20) keycodes, but only '123456789012345' can be sent to guest.

It seems we need to notice user when inputted keys are more than 16.

[1] https://github.com/kongove/QEMU/commit/a198cdcce3ce4c1632221ac7f1e7c4e8efcd9c82

Signature · 1 line
			Amos.
author
#9 lore raw

Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

Quoted 21 lines · Amos Kong
Quoted 1 line · Luiz Capitulino
Quoted 1 line

Hi Luiz, Anthony

Quoted 1 line
Quoted 1 line

BTW, why is there a 16 keycode limit?

'Sendkey' command was added by this commit a3a91a355bc6107b7d06d722fb97d2b80065ee0b Limitation of keycodes number (16) was also introduced here, and I didn't find the root reason.

Quoted 5 lines
Quoted 1 line

That's a good point. This comes form the array used by the original implementation to store the keycodes.

Amos, is it still needed now that we're using qapi lists?

I try to drop this limitation from monitor.c [1], then execute

Quoted 7 lines

(qemu) sendkey 1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0

kbd_put_keycode() are called for all (20) keycodes, but only '123456789012345' can be sent to guest.

It seems we need to notice user when inputted keys are more than 16.

Hi Gerd,

When I use 'sendkey' command to send key-series to guest, some keyboard events will be send. There is a limitation (16) that was introduced by this old commit c8256f9d (without description). Do you know the reason?

I found in bonzini's commit 13f8b97a :
+#define QUEUE_LENGTH 16 /* should be enough for a triple-click */
bonzini told me that the reason to do it for the keyboard, was to do ctrl-alt-delete, nothing more

I drop this limitation (16) in monitor.c for sendkey command, when I execute (qemu) sendkey 1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0 , hw/ps2.c:ps2_put_keycode() is called for all keys,
but only '123456789012345' is inputted to guest.

There is a 'PS2_QUEUE_SIZE' (256) in hw/ps2.c, this event queue is shared by mouse and keyboard, but I only inputted 20 keys.

I didn't find where the other keys are ignored, and there is no warning in stderr.

Hi Anthony, Luiz,

However, the limitation (16) for sendkey is necessary, 16 is enough for all combination keys

Quoted 2 lines

[1]
https://github.com/kongove/QEMU/commit/a198cdcce3ce4c1632221ac7f1e7c4e8efcd9c82

Signature · 1 line
			Amos.
#10 lore raw

Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

Hi,

Quoted 7 lines
Quoted 1 line

It seems we need to notice user when inputted keys are more than 16.

Hi Gerd,

When I use 'sendkey' command to send key-series to guest, some keyboard events will be send. There is a limitation (16) that was introduced by this old commit c8256f9d (without description). Do you know the reason?

Probably hardware limitation, ps/2 keyboards can buffer up to 16 keys IIRC.

Likewise the usb hid devices can buffer up to 16 events. In that case it is just a qemu implementation detail and not a property of the hardware we are emulating, so it can be changed. Not trivially though as the buffer is part of the migration data, so it is more work that just changing a #define.

HTH,
Gerd

#11 lore raw

Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

Quoted 11 lines · On Fri, 15 Jun 2012 09:57:49 +0200 Gerd Hoffmann <[email protected]> wrote:

Hi,

Quoted 7 lines
Quoted 1 line

It seems we need to notice user when inputted keys are more than 16.

Hi Gerd,

When I use 'sendkey' command to send key-series to guest, some keyboard events will be send. There is a limitation (16) that was introduced by this old commit c8256f9d (without description). Do you know the reason?

Probably hardware limitation, ps/2 keyboards can buffer up to 16 keys IIRC.

Then the perfect thing to do would be to drop the MAX_KEYCODES check from the sendkey command and move bounds checking down to the device emulation code.

However, this will require a bit of code churn if we do it for all devices, and won't buy us much, as the most likely reason for the error is a client/user trying to send too many keys in parallel to the guest, right?

If this is right, then I think that the best thing to do would be to drop the MAX_KEYCODES check from the sendkey command and document that devices can drop keys if too many of them are sent in parallel or too fast (we can mention ps/2 as an example of a 16 bytes limit).

Quoted 6 lines

Likewise the usb hid devices can buffer up to 16 events. In that case it is just a qemu implementation detail and not a property of the hardware we are emulating, so it can be changed. Not trivially though as the buffer is part of the migration data, so it is more work that just changing a #define.

author
#12 lore raw

Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

Quoted 15 lines · Luiz Capitulino
Quoted 11 lines · On Fri, 15 Jun 2012 09:57:49 +0200 Gerd Hoffmann <[email protected]> wrote:

Hi,

Quoted 7 lines
Quoted 1 line

It seems we need to notice user when inputted keys are more than 16.

Hi Gerd,

When I use 'sendkey' command to send key-series to guest, some keyboard events will be send. There is a limitation (16) that was introduced by this old commit c8256f9d (without description). Do you know the reason?

Probably hardware limitation, ps/2 keyboards can buffer up to 16 keys IIRC.

Quoted 7 lines

Then the perfect thing to do would be to drop the MAX_KEYCODES check from the sendkey command and move bounds checking down to the device emulation code.

However, this will require a bit of code churn if we do it for all devices, and won't buy us much, as the most likely reason for the error is a client/user trying to send too many keys in parallel to the guest, right?

Agree, we can notice in stderr when the redundant keys are ignored as hid.

#define QUEUE_LENGTH 16 /* should be enough for a triple-click */

static void hid_keyboard_event(void *opaque, int keycode)

{
    ...
    if (hs->n == QUEUE_LENGTH) {
        fprintf(stderr, "usb-kbd: warning: key event queue full\n");
        return;
    }
Quoted 11 lines

If this is right, then I think that the best thing to do would be to drop the MAX_KEYCODES check from the sendkey command and document that devices can drop keys if too many of them are sent in parallel or too fast (we can mention ps/2 as an example of a 16 bytes limit).

Quoted 6 lines

Likewise the usb hid devices can buffer up to 16 events. In that case it is just a qemu implementation detail and not a property of the hardware we are emulating, so it can be changed. Not trivially though as the buffer is part of the migration data, so it is more work that just changing a #define.

Signature · 1 line
			Amos.
author
#13 lore raw

Re: [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16

Quoted 29 lines · Amos Kong
Quoted 15 lines · Luiz Capitulino
Quoted 11 lines · On Fri, 15 Jun 2012 09:57:49 +0200 Gerd Hoffmann<[email protected]> wrote:
   Hi,
Quoted 7 lines
Quoted 1 line

It seems we need to notice user when inputted keys are more than 16.

Hi Gerd,

When I use 'sendkey' command to send key-series to guest, some keyboard events will be send. There is a limitation (16) that was introduced by this old commit c8256f9d (without description). Do you know the reason?

Probably hardware limitation, ps/2 keyboards can buffer up to 16 keys IIRC.

Quoted 7 lines

Then the perfect thing to do would be to drop the MAX_KEYCODES check from the sendkey command and move bounds checking down to the device emulation code.

However, this will require a bit of code churn if we do it for all devices, and won't buy us much, as the most likely reason for the error is a client/user trying to send too many keys in parallel to the guest, right?

Agree, we can notice in stderr when the redundant keys are ignored as hid.

#define QUEUE_LENGTH 16 /* should be enough for a triple-click */

Quoted 7 lines

static void hid_keyboard_event(void *opaque, int keycode)

{
     ...
     if (hs->n == QUEUE_LENGTH) {
         fprintf(stderr, "usb-kbd: warning: key event queue full\n");
         return;
     }

I dropped the limitation in sendkey command, and didn't change current ps2.c, executed some tests in different environments.

environment             max inputted key number
------------            -----------------------
win7 notepad            100
rhel6 grub              15
rhel6 pxe               15
rhel6 login window      10
rhel6 vim               16
rhel6 terminal(init 3)  200

It seems original 256 queue limitation in ps2.c is fine. I would only drop limitation(16) in old sendkey command, it's secure.

Quoted 11 lines
Quoted 11 lines

If this is right, then I think that the best thing to do would be to drop the MAX_KEYCODES check from the sendkey command and document that devices can drop keys if too many of them are sent in parallel or too fast (we can mention ps/2 as an example of a 16 bytes limit).

Quoted 6 lines

Likewise the usb hid devices can buffer up to 16 events. In that case it is just a qemu implementation detail and not a property of the hardware we are emulating, so it can be changed. Not trivially though as the buffer is part of the migration data, so it is more work that just changing a #define.

Signature · 1 line
			Amos.
author
#14 lore raw

PATCH v2 2/6 fix doc of using raw values with sendkey

In reply to 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.

---
 hmp-commands.hx |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hmp-commands.hx +2 -2
index 18cb415..af18156 100644
@@ -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
#15 lore raw

Re: [Qemu-devel] [PATCH v2 2/6] fix doc of using raw values with sendkey

Quoted 17 lines · On Sat, 2 Jun 2012 06:54:24 +0800 Amos Kong <[email protected]> wrote:

(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 +0 -0
index 18cb415..af18156 100644

hmp-commands.hx STEXI · line 515

Quoted 3 lines
hmp-commands.hx +0 -0
@@ -513,8 +513,8 @@ STEXI
 @findex sendkey
 
 Send @var{keys} to the emulator. @var{keys} could be the name of the

I think we should do:

s/emulator/guest

Also applies to the schema doc.

Quoted 7 lines
hmp-commands.hx +2 -2
-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
author
#16 lore raw

PATCH v2 3/6 rename keyname '<' to 'less'

In reply to Amos Kong

There are many maps of keycode 0x56 in pc-bios/keymaps/*
pc-bios/keymaps/common:less 0x56 pc-bios/keymaps/common:greater 0x56 shift pc-bios/keymaps/common:bar 0x56 altgr pc-bios/keymaps/common:brokenbar 0x56 shift altgr

This patch just rename '<' to 'less', QAPI might add new variable by adding a prefix to keyname, '$PREFIX_<' is not available, '$PREFIX_less' is ok.

For compatibility, convert user inputted '<' to 'less'.

---
 monitor.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
monitor.c +8 -1
index 12a6fe2..ecfcaa4 100644
@@ -1302,7 +1302,7 @@ static const KeyDef key_defs[] = {
     { 0x48, "kp_8" },
     { 0x49, "kp_9" },
 
-    { 0x56, "<" },
+    { 0x56, "less" },
 
     { 0x57, "f11" },
     { 0x58, "f12" },
@@ -1406,6 +1406,13 @@ static void do_sendkey(Monitor *mon, const QDict *qdict)
                 monitor_printf(mon, "too many keys\n");
                 return;
             }
+
+            /* Be compatible with old interface, convert user inputted "<" */
+            if (!strcmp(keyname_buf, "<")) {
+                pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
+                keyname_len = 4;
+            }
+
             keyname_buf[keyname_len] = 0;
             keycode = get_keycode(keyname_buf);
             if (keycode < 0) {
Signature · 1 line
1.7.1
#17 lore raw

Re: [Qemu-devel] [PATCH v2 3/6] rename keyname '<' to 'less'

Quoted 31 lines · On Sat, 2 Jun 2012 06:54:25 +0800 Amos Kong <[email protected]> wrote:

There are many maps of keycode 0x56 in pc-bios/keymaps/*
pc-bios/keymaps/common:less 0x56 pc-bios/keymaps/common:greater 0x56 shift pc-bios/keymaps/common:bar 0x56 altgr pc-bios/keymaps/common:brokenbar 0x56 shift altgr

This patch just rename '<' to 'less', QAPI might add new variable by adding a prefix to keyname, '$PREFIX_<' is not available, '$PREFIX_less' is ok.

For compatibility, convert user inputted '<' to 'less'.

---
 monitor.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
monitor.c +1 -1
index 12a6fe2..ecfcaa4 100644
@@ -1302,7 +1302,7 @@ static const KeyDef key_defs[] = {
     { 0x48, "kp_8" },
     { 0x49, "kp_9" },
 
-    { 0x56, "<" },
+    { 0x56, "less" },
 
     { 0x57, "f11" },
     { 0x58, "f12" },

monitor.c static void do_sendkey(Monitor *mon, const QDict *qdict) · line 1414

Quoted 9 lines
monitor.c +6 -0
@@ -1406,6 +1406,13 @@ static void do_sendkey(Monitor *mon, const QDict *qdict)
                 monitor_printf(mon, "too many keys\n");
                 return;
             }
+
+            /* Be compatible with old interface, convert user inputted "<" */
+            if (!strcmp(keyname_buf, "<")) {
+                pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
+                keyname_len = 4;
+            }

I'm not against this change, but it breaks 'sendkey <-a'

Quoted 4 lines
monitor.c +1 -0
+
             keyname_buf[keyname_len] = 0;
             keycode = get_keycode(keyname_buf);
             if (keycode < 0) {
author
#18 lore raw

Re: [Qemu-devel] [PATCH v2 3/6] rename keyname '<' to 'less'

----- Original Message -----

Quoted 31 lines
Quoted 28 lines · On Sat, 2 Jun 2012 06:54:25 +0800 Amos Kong <[email protected]> wrote:

There are many maps of keycode 0x56 in pc-bios/keymaps/*
pc-bios/keymaps/common:less 0x56 pc-bios/keymaps/common:greater 0x56 shift pc-bios/keymaps/common:bar 0x56 altgr pc-bios/keymaps/common:brokenbar 0x56 shift altgr

This patch just rename '<' to 'less', QAPI might add new variable by adding a prefix to keyname, '$PREFIX_<' is not available, '$PREFIX_less' is ok.

For compatibility, convert user inputted '<' to 'less'.

---
 monitor.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
monitor.c +1 -1
index 12a6fe2..ecfcaa4 100644
@@ -1302,7 +1302,7 @@ static const KeyDef key_defs[] = {
     { 0x48, "kp_8" },
     { 0x49, "kp_9" },
 
-    { 0x56, "<" },
+    { 0x56, "less" },
 
Quoted 16 lines
Quoted 10 lines
monitor.c +2 -0
     { 0x57, "f11" },
     { 0x58, "f12" },
@@ -1406,6 +1406,13 @@ static void do_sendkey(Monitor *mon, const
 QDict *qdict)
                 monitor_printf(mon, "too many keys\n");
                 return;
             }
+
+            /* Be compatible with old interface, convert user

inputted "<" */

monitor.c static void do_sendkey(Monitor *mon, const QDict *qdict) · line 1414

Quoted 4 lines
monitor.c +4 -0
+            if (!strcmp(keyname_buf, "<")) {
+                pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
+                keyname_len = 4;
+            }

I'm not against this change, but it breaks 'sendkey <-a'

Thanks for catching this, already fixed:

@@ -978,7 +1141,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)

         pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
 
         /* Be compatible with old interface, convert user inputted "<" */
-        if (!strcmp(keyname_buf, "<")) {
+        if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
             pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
             keyname_len = 4;
         }
Quoted 8 lines
Quoted 5 lines

+

             keyname_buf[keyname_len] = 0;
             keycode = get_keycode(keyname_buf);
             if (keycode < 0) {
author
#19 lore raw

PATCH v2 4/6 hmp: rename arguments

In reply to Amos Kong

Rename 'string' to 'keys', rename 'hold_time' to 'hold-time'

---
 hmp-commands.hx |    2 +-
 monitor.c       |   14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)
hmp-commands.hx +1 -1
index af18156..18b8e31 100644
@@ -502,7 +502,7 @@ 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,
monitor.c +7 -7
index ecfcaa4..536d9dd 100644
@@ -1382,9 +1382,9 @@ static void do_sendkey(Monitor *mon, const QDict *qdict)
     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);
+    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);
 
     if (nb_pending_keycodes > 0) {
         qemu_del_timer(key_timer);
@@ -1394,10 +1394,10 @@ 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);
                 return;
@@ -1423,7 +1423,7 @@ static void do_sendkey(Monitor *mon, const QDict *qdict)
         }
         if (!separator)
             break;
-        string = separator + 1;
+        keys = separator + 1;
     }
     nb_pending_keycodes = i;
     /* key down events */
Signature · 1 line
1.7.1
author
#20 lore raw

PATCH v2 5/6 qapi: generate list struct and visit_list for enum

In reply to Amos Kong

Currently, if define an 'enum' and use it in one command's data, List struct for enum could not be generated, but it's used in qmp function.

For example: KeyCodesList could not be generated.

Quoted 1 line
Quoted 1 line
Quoted 1 line

qapi-schema.json:

{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }

Quoted 1 line
Quoted 1 line
Quoted 1 line

qmp-command.h:

void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t hold_time, Error **errp);

This patch makes qapi can generate List struct for enum.

---
 scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
 scripts/qapi-visit.py |   14 +++++++++-----
 2 files changed, 38 insertions(+), 9 deletions(-)
scripts/qapi-types.py +29 -4
index 4a734f5..c9641fb 100644
@@ -16,17 +16,36 @@ import os
 import getopt
 import errno
 
-def generate_fwd_struct(name, members):
-    return mcgen('''
+def generate_fwd_struct(name, members, enum=False):
+    ret = ""
+    if not enum:
+        ret += mcgen('''
 typedef struct %(name)s %(name)s;
 
+''',
+                     name=name)
+    ret += mcgen('''
 typedef struct %(name)sList
 {
-    %(name)s *value;
+''',
+                     name=name)
+    if enum:
+        ret += mcgen('''
+         %(name)s value;
+''',
+                     name=name)
+    else:
+        ret += mcgen('''
+         %(name)s * value;
+''',
+                     name=name)
+
+    ret += mcgen('''
     struct %(name)sList *next;
 } %(name)sList;
 ''',
                  name=name)
+    return ret
 
 def generate_struct(structname, fieldname, members):
     ret = mcgen('''
@@ -265,7 +284,8 @@ for expr in exprs:
     if expr.has_key('type'):
         ret += generate_fwd_struct(expr['type'], expr['data'])
     elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data'])
+        ret += generate_enum(expr['enum'], expr['data']) + "\n"
+        ret += generate_fwd_struct(expr['enum'], expr['data'], True)
         fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
     elif expr.has_key('union'):
         ret += generate_fwd_struct(expr['union'], expr['data']) + "\n"
@@ -289,6 +309,11 @@ for expr in exprs:
         fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
         ret += generate_type_cleanup_decl(expr['union'])
         fdef.write(generate_type_cleanup(expr['union']) + "\n")
+    elif expr.has_key('enum'):
+        ret += generate_type_cleanup_decl(expr['enum'] + "List")
+        fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")
+        ret += generate_type_cleanup_decl(expr['enum'])
+        fdef.write(generate_type_cleanup(expr['enum']) + "\n")
     else:
         continue
     fdecl.write(ret)
scripts/qapi-visit.py +9 -5
index 8d4e94a..e44edfa 100644
@@ -81,7 +81,7 @@ end:
 ''')
     return ret
 
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, enum=False):
     return mcgen('''
 
 void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
@@ -160,12 +160,14 @@ end:
 
     return ret
 
-def generate_declaration(name, members, genlist=True):
-    ret = mcgen('''
+def generate_declaration(name, members, genlist=True, enum=False):
+    ret = ""
+    if not enum:
+        ret = mcgen('''
 
 void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
 ''',
-                name=name)
+                    name=name)
 
     if genlist:
         ret += mcgen('''
@@ -293,10 +295,12 @@ for expr in exprs:
         ret += generate_declaration(expr['union'], expr['data'])
         fdecl.write(ret)
     elif expr.has_key('enum'):
-        ret = generate_visit_enum(expr['enum'], expr['data'])
+        ret = generate_visit_list(expr['enum'], expr['data'], True)
+        ret += generate_visit_enum(expr['enum'], expr['data'])
         fdef.write(ret)
 
         ret = generate_decl_enum(expr['enum'], expr['data'])
+        ret += generate_declaration(expr['enum'], expr['data'], enum=True)
         fdecl.write(ret)
 
 fdecl.write('''
Signature · 1 line
1.7.1
author
#21 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum

----- Original Message -----

Quoted 11 lines

Currently, if define an 'enum' and use it in one command's data, List struct for enum could not be generated, but it's used in qmp function.

For example: KeyCodesList could not be generated.

Quoted 1 line
Quoted 1 line
Quoted 1 line

qapi-schema.json:

{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

qmp-command.h:

void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t hold_time, Error **errp);

This patch makes qapi can generate List struct for enum.

Anthony, Mike, any comments on this patch?

Quoted 128 lines
---
 scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
 scripts/qapi-visit.py |   14 +++++++++-----
 2 files changed, 38 insertions(+), 9 deletions(-)
scripts/qapi-types.py +24 -4
index 4a734f5..c9641fb 100644
@@ -16,17 +16,36 @@ import os
 import getopt
 import errno
 
-def generate_fwd_struct(name, members):
-    return mcgen('''
+def generate_fwd_struct(name, members, enum=False):
+    ret = ""
+    if not enum:
+        ret += mcgen('''
 typedef struct %(name)s %(name)s;
 
+''',
+                     name=name)
+    ret += mcgen('''
 typedef struct %(name)sList
 {
-    %(name)s *value;
+''',
+                     name=name)
+    if enum:
+        ret += mcgen('''
+         %(name)s value;
+''',
+                     name=name)
+    else:
+        ret += mcgen('''
+         %(name)s * value;
+''',
+                     name=name)
+
+    ret += mcgen('''
     struct %(name)sList *next;
 } %(name)sList;
 ''',
                  name=name)
+    return ret
 
 def generate_struct(structname, fieldname, members):
     ret = mcgen('''
@@ -265,7 +284,8 @@ for expr in exprs:
     if expr.has_key('type'):
         ret += generate_fwd_struct(expr['type'], expr['data'])
     elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data'])
+        ret += generate_enum(expr['enum'], expr['data']) + "\n"
+        ret += generate_fwd_struct(expr['enum'], expr['data'], True)
         fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
     elif expr.has_key('union'):
         ret += generate_fwd_struct(expr['union'], expr['data']) +
         "\n"
scripts/qapi-types.py +5 -0
@@ -289,6 +309,11 @@ for expr in exprs:
         fdef.write(generate_type_cleanup(expr['union'] + "List") +
         "\n")
         ret += generate_type_cleanup_decl(expr['union'])
         fdef.write(generate_type_cleanup(expr['union']) + "\n")
+    elif expr.has_key('enum'):
+        ret += generate_type_cleanup_decl(expr['enum'] + "List")
+        fdef.write(generate_type_cleanup(expr['enum'] + "List") +
 "\n")
+        ret += generate_type_cleanup_decl(expr['enum'])
+        fdef.write(generate_type_cleanup(expr['enum']) + "\n")
     else:

continue
fdecl.write(ret)

scripts/qapi-visit.py +1 -1
index 8d4e94a..e44edfa 100644
@@ -81,7 +81,7 @@ end:
 ''')
     return ret
 
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, enum=False):
     return mcgen('''
 
 void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const

char *name, Error **errp)

scripts/qapi-visit.py +5 -3
@@ -160,12 +160,14 @@ end:
 
     return ret
 
-def generate_declaration(name, members, genlist=True):
-    ret = mcgen('''
+def generate_declaration(name, members, genlist=True, enum=False):
+    ret = ""
+    if not enum:
+        ret = mcgen('''
 
 void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char
 *name, Error **errp);
 ''',
-                name=name)
+                    name=name)
 
     if genlist:
         ret += mcgen('''
scripts/qapi-visit.py +3 -1
@@ -293,10 +295,12 @@ for expr in exprs:
         ret += generate_declaration(expr['union'], expr['data'])
         fdecl.write(ret)
     elif expr.has_key('enum'):
-        ret = generate_visit_enum(expr['enum'], expr['data'])
+        ret = generate_visit_list(expr['enum'], expr['data'], True)
+        ret += generate_visit_enum(expr['enum'], expr['data'])
         fdef.write(ret)
 
         ret = generate_decl_enum(expr['enum'], expr['data'])
+        ret += generate_declaration(expr['enum'], expr['data'],
 enum=True)
         fdecl.write(ret)
 

fdecl.write('''
--
1.7.1

#22 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum

In reply to Amos Kong
Quoted 11 lines · On Sat, 2 Jun 2012 06:54:27 +0800 Amos Kong <[email protected]> wrote:

Currently, if define an 'enum' and use it in one command's data, List struct for enum could not be generated, but it's used in qmp function.

For example: KeyCodesList could not be generated.

Quoted 1 line
Quoted 1 line
Quoted 1 line

qapi-schema.json:

{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

qmp-command.h:

void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t hold_time, Error **errp);

This patch makes qapi can generate List struct for enum.

This patch does it the simple way, just like any type. It generates a enum list type and the functions qapi_free_yourenum() and qapi_free_yourenumlist().

The qapi_free_yourenum() list ends up doing nothing, so it could be a good idea to generate an empty body (also note that we're copying the argument's value, this could bite us in the future).

Another point I was wondering is that, all enums will end up having the exact same code. So maybe we could generate a default int list and use it for all enums. Not sure it's worth it though.

Michael, Paolo, ideas?

More review comments below.

Quoted 12 lines
---
 scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
 scripts/qapi-visit.py |   14 +++++++++-----
 2 files changed, 38 insertions(+), 9 deletions(-)
scripts/qapi-types.py +0 -0
index 4a734f5..c9641fb 100644

scripts/qapi-types.py import os · line 19

Quoted 6 lines
scripts/qapi-types.py +1 -2
@@ -16,17 +16,36 @@ import os
 import getopt
 import errno
 
-def generate_fwd_struct(name, members):
-    return mcgen('''
+def generate_fwd_struct(name, members, enum=False):

I think it's better to have generate_fwd_enum_struct().

Quoted 34 lines
scripts/qapi-types.py +21 -1
+    ret = ""
+    if not enum:
+        ret += mcgen('''
 typedef struct %(name)s %(name)s;
 
+''',
+                     name=name)
+    ret += mcgen('''
 typedef struct %(name)sList
 {
-    %(name)s *value;
+''',
+                     name=name)
+    if enum:
+        ret += mcgen('''
+         %(name)s value;
+''',
+                     name=name)
+    else:
+        ret += mcgen('''
+         %(name)s * value;
+''',
+                     name=name)
+
+    ret += mcgen('''
     struct %(name)sList *next;
 } %(name)sList;
 ''',
                  name=name)
+    return ret
 
 def generate_struct(structname, fieldname, members):
     ret = mcgen('''

scripts/qapi-types.py for expr in exprs: · line 287

Quoted 5 lines
scripts/qapi-types.py +1 -1
@@ -265,7 +284,8 @@ for expr in exprs:
     if expr.has_key('type'):
         ret += generate_fwd_struct(expr['type'], expr['data'])
     elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data'])
+        ret += generate_enum(expr['enum'], expr['data']) + "\n"

The new-line should be returned by generate_enum(). Same applies for the occurrences below.

Quoted 34 lines
scripts/qapi-types.py +6 -0
+        ret += generate_fwd_struct(expr['enum'], expr['data'], True)
         fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
     elif expr.has_key('union'):
         ret += generate_fwd_struct(expr['union'], expr['data']) + "\n"
@@ -289,6 +309,11 @@ for expr in exprs:
         fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
         ret += generate_type_cleanup_decl(expr['union'])
         fdef.write(generate_type_cleanup(expr['union']) + "\n")
+    elif expr.has_key('enum'):
+        ret += generate_type_cleanup_decl(expr['enum'] + "List")
+        fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")
+        ret += generate_type_cleanup_decl(expr['enum'])
+        fdef.write(generate_type_cleanup(expr['enum']) + "\n")
     else:
         continue
     fdecl.write(ret)
scripts/qapi-visit.py +1 -2
index 8d4e94a..e44edfa 100644
@@ -81,7 +81,7 @@ end:
 ''')
     return ret
 
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, enum=False):
     return mcgen('''
 
 void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
@@ -160,12 +160,14 @@ end:
 
     return ret
 
-def generate_declaration(name, members, genlist=True):

scripts/qapi-visit.py end: · line 170

Quoted 10 lines
scripts/qapi-visit.py +5 -2
-    ret = mcgen('''
+def generate_declaration(name, members, genlist=True, enum=False):
+    ret = ""
+    if not enum:
+        ret = mcgen('''
 
 void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
 ''',
-                name=name)
+                    name=name)

Why this change?

Quoted 17 lines
scripts/qapi-visit.py +3 -1
     if genlist:
         ret += mcgen('''
@@ -293,10 +295,12 @@ for expr in exprs:
         ret += generate_declaration(expr['union'], expr['data'])
         fdecl.write(ret)
     elif expr.has_key('enum'):
-        ret = generate_visit_enum(expr['enum'], expr['data'])
+        ret = generate_visit_list(expr['enum'], expr['data'], True)
+        ret += generate_visit_enum(expr['enum'], expr['data'])
         fdef.write(ret)
 
         ret = generate_decl_enum(expr['enum'], expr['data'])
+        ret += generate_declaration(expr['enum'], expr['data'], enum=True)
         fdecl.write(ret)
 
 fdecl.write('''
#23 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum

Quoted 14 lines · Luiz Capitulino
Quoted 11 lines · On Sat, 2 Jun 2012 06:54:27 +0800 Amos Kong <[email protected]> wrote:

Currently, if define an 'enum' and use it in one command's data, List struct for enum could not be generated, but it's used in qmp function.

For example: KeyCodesList could not be generated.

Quoted 1 line
Quoted 1 line
Quoted 1 line

qapi-schema.json:

{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }

Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

qmp-command.h:

void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t hold_time, Error **errp);

This patch makes qapi can generate List struct for enum.

This patch does it the simple way, just like any type. It generates a enum list type and the functions qapi_free_yourenum() and qapi_free_yourenumlist().

Had a couple suggestions, but approach/patch seems reasonable to me.

Quoted 4 lines

The qapi_free_yourenum() list ends up doing nothing, so it could be a good idea to generate an empty body (also note that we're copying the argument's value, this could bite us in the future).

I think we can omit qapi_free_yourenum() completely. Humans will know not to free non-allocated types, and the generated marshallers don't use these interfaces.

Quoted 4 lines

Another point I was wondering is that, all enums will end up having the exact same code. So maybe we could generate a default int list and use it for all enums. Not sure it's worth it though.

Since it's generated code I don't think it's worth it, personally.

Quoted 136 lines

Michael, Paolo, ideas?

More review comments below.

Quoted 12 lines
---
 scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
 scripts/qapi-visit.py |   14 +++++++++-----
 2 files changed, 38 insertions(+), 9 deletions(-)
scripts/qapi-types.py +0 -0
index 4a734f5..c9641fb 100644

scripts/qapi-types.py import os · line 19

Quoted 6 lines
scripts/qapi-types.py +1 -2
@@ -16,17 +16,36 @@ import os
 import getopt
 import errno
 
-def generate_fwd_struct(name, members):
-    return mcgen('''
+def generate_fwd_struct(name, members, enum=False):

I think it's better to have generate_fwd_enum_struct().

Quoted 34 lines
scripts/qapi-types.py +21 -1
+    ret = ""
+    if not enum:
+        ret += mcgen('''
 typedef struct %(name)s %(name)s;
 
+''',
+                     name=name)
+    ret += mcgen('''
 typedef struct %(name)sList
 {
-    %(name)s *value;
+''',
+                     name=name)
+    if enum:
+        ret += mcgen('''
+         %(name)s value;
+''',
+                     name=name)
+    else:
+        ret += mcgen('''
+         %(name)s * value;
+''',
+                     name=name)
+
+    ret += mcgen('''
     struct %(name)sList *next;
 } %(name)sList;
 ''',
                  name=name)
+    return ret
 
 def generate_struct(structname, fieldname, members):
     ret = mcgen('''

scripts/qapi-types.py for expr in exprs: · line 287

Quoted 5 lines
scripts/qapi-types.py +1 -1
@@ -265,7 +284,8 @@ for expr in exprs:
     if expr.has_key('type'):
         ret += generate_fwd_struct(expr['type'], expr['data'])
     elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data'])
+        ret += generate_enum(expr['enum'], expr['data']) + "\n"

The new-line should be returned by generate_enum(). Same applies for the occurrences below.

Quoted 34 lines
scripts/qapi-types.py +6 -0
+        ret += generate_fwd_struct(expr['enum'], expr['data'], True)
         fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
     elif expr.has_key('union'):
         ret += generate_fwd_struct(expr['union'], expr['data']) + "\n"
@@ -289,6 +309,11 @@ for expr in exprs:
         fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
         ret += generate_type_cleanup_decl(expr['union'])
         fdef.write(generate_type_cleanup(expr['union']) + "\n")
+    elif expr.has_key('enum'):
+        ret += generate_type_cleanup_decl(expr['enum'] + "List")
+        fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")
+        ret += generate_type_cleanup_decl(expr['enum'])
+        fdef.write(generate_type_cleanup(expr['enum']) + "\n")
     else:
         continue
     fdecl.write(ret)
scripts/qapi-visit.py +1 -2
index 8d4e94a..e44edfa 100644
@@ -81,7 +81,7 @@ end:
 ''')
     return ret
 
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, enum=False):
     return mcgen('''
 
 void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
@@ -160,12 +160,14 @@ end:
 
     return ret
 
-def generate_declaration(name, members, genlist=True):

scripts/qapi-visit.py end: · line 170

Quoted 10 lines
scripts/qapi-visit.py +5 -2
-    ret = mcgen('''
+def generate_declaration(name, members, genlist=True, enum=False):
+    ret = ""
+    if not enum:
+        ret = mcgen('''
 
 void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
 ''',
-                name=name)
+                    name=name)

Why this change?

Quoted 17 lines
scripts/qapi-visit.py +3 -1
     if genlist:
         ret += mcgen('''
@@ -293,10 +295,12 @@ for expr in exprs:
         ret += generate_declaration(expr['union'], expr['data'])
         fdecl.write(ret)
     elif expr.has_key('enum'):
-        ret = generate_visit_enum(expr['enum'], expr['data'])
+        ret = generate_visit_list(expr['enum'], expr['data'], True)
+        ret += generate_visit_enum(expr['enum'], expr['data'])
         fdef.write(ret)
 
         ret = generate_decl_enum(expr['enum'], expr['data'])
+        ret += generate_declaration(expr['enum'], expr['data'], enum=True)
         fdecl.write(ret)
 
 fdecl.write('''
author
#24 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum

Quoted 36 lines · Michael Roth
Quoted 14 lines · Luiz Capitulino
Quoted 11 lines · On Sat, 2 Jun 2012 06:54:27 +0800 Amos Kong<[email protected]> wrote:

Currently, if define an 'enum' and use it in one command's data, List struct for enum could not be generated, but it's used in qmp function.

For example: KeyCodesList could not be generated.

Quoted 1 line
Quoted 1 line
Quoted 1 line

qapi-schema.json:

{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }

Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

qmp-command.h:

void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t hold_time, Error **errp);

This patch makes qapi can generate List struct for enum.

This patch does it the simple way, just like any type. It generates a enum list type and the functions qapi_free_yourenum() and qapi_free_yourenumlist().

Had a couple suggestions, but approach/patch seems reasonable to me.

Quoted 4 lines

The qapi_free_yourenum() list ends up doing nothing, so it could be a good idea to generate an empty body (also note that we're copying the argument's value, this could bite us in the future).

I think we can omit qapi_free_yourenum() completely. Humans will know not to free non-allocated types, and the generated marshallers don't use these interfaces.

Quoted 1 line
Quoted 10 lines
Quoted 3 lines

Another point I was wondering is that, all enums will end up having the exact same code. So maybe we could generate a default int list and use it for all enums. Not sure it's worth it though.

Since it's generated code I don't think it's worth it, personally.

Quoted 4 lines

Michael, Paolo, ideas?

More review comments below.

Thanks for your review!

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
---
  scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
  scripts/qapi-visit.py |   14 +++++++++-----
  2 files changed, 38 insertions(+), 9 deletions(-)
scripts/qapi-types.py +0 -0
index 4a734f5..c9641fb 100644
@@ -16,17 +16,36 @@ import os
  import getopt
  import errno
 
Quoted 5 lines
Quoted 5 lines

scripts/qapi-types.py import os · line 19

Quoted 3 lines
scripts/qapi-types.py +1 -2
-def generate_fwd_struct(name, members):
-    return mcgen('''
+def generate_fwd_struct(name, members, enum=False):

I think it's better to have generate_fwd_enum_struct().

I tried this before, too many duplicate codes would be introduced, but it's more clear.

two functions need to be added
qapi-types.py: def generate_fwd_enum_struct(name, members):
qapi-visit.py: def generate_enum_declaration(name, members,
genlist=True):

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
scripts/qapi-types.py +21 -1
+    ret = ""
+    if not enum:
+        ret += mcgen('''
  typedef struct %(name)s %(name)s;
 
+''',
+                     name=name)
+    ret += mcgen('''
  typedef struct %(name)sList
  {
-    %(name)s *value;
+''',
+                     name=name)
+    if enum:
+        ret += mcgen('''
+         %(name)s value;
+''',
+                     name=name)
+    else:
+        ret += mcgen('''
+         %(name)s * value;
+''',
+                     name=name)
+
+    ret += mcgen('''
      struct %(name)sList *next;
  } %(name)sList;
  ''',
                   name=name)
+    return ret
 
Quoted 11 lines
Quoted 11 lines

scripts/qapi-types.py for expr in exprs: · line 287

Quoted 8 lines
scripts/qapi-types.py +1 -1
  def generate_struct(structname, fieldname, members):
      ret = mcgen('''
@@ -265,7 +284,8 @@ for expr in exprs:
      if expr.has_key('type'):
          ret += generate_fwd_struct(expr['type'], expr['data'])
      elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data'])
+        ret += generate_enum(expr['enum'], expr['data']) + "\n"

The new-line should be returned by generate_enum(). Same applies for the occurrences below.

"\n" is used to add a blank line here.

Quoted 40 lines
Quoted 39 lines
Quoted 39 lines
scripts/qapi-types.py +6 -0
+        ret += generate_fwd_struct(expr['enum'], expr['data'], True)
          fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
      elif expr.has_key('union'):
          ret += generate_fwd_struct(expr['union'], expr['data']) + "\n"
@@ -289,6 +309,11 @@ for expr in exprs:
          fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
          ret += generate_type_cleanup_decl(expr['union'])
          fdef.write(generate_type_cleanup(expr['union']) + "\n")
+    elif expr.has_key('enum'):
+        ret += generate_type_cleanup_decl(expr['enum'] + "List")
+        fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")
+        ret += generate_type_cleanup_decl(expr['enum'])
+        fdef.write(generate_type_cleanup(expr['enum']) + "\n")
      else:
          continue
      fdecl.write(ret)
scripts/qapi-visit.py +5 -3
index 8d4e94a..e44edfa 100644
@@ -81,7 +81,7 @@ end:
  ''')
      return ret
 
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, enum=False):
      return mcgen('''
 
  void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
@@ -160,12 +160,14 @@ end:
 
      return ret
 
-def generate_declaration(name, members, genlist=True):
-    ret = mcgen('''
+def generate_declaration(name, members, genlist=True, enum=False):
+    ret = ""
+    if not enum:
+        ret = mcgen('''
Quoted 6 lines
Quoted 6 lines

scripts/qapi-visit.py end: · line 170

Quoted 4 lines
scripts/qapi-visit.py +1 -1
  void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
  ''',
-                name=name)
+                    name=name)

Why this change?

Indent of above "mcgen(" changes, make them aligned.

Quoted 19 lines
Quoted 19 lines
Quoted 17 lines
scripts/qapi-visit.py +3 -1
      if genlist:
          ret += mcgen('''
@@ -293,10 +295,12 @@ for expr in exprs:
          ret += generate_declaration(expr['union'], expr['data'])
          fdecl.write(ret)
      elif expr.has_key('enum'):
-        ret = generate_visit_enum(expr['enum'], expr['data'])
+        ret = generate_visit_list(expr['enum'], expr['data'], True)
+        ret += generate_visit_enum(expr['enum'], expr['data'])
          fdef.write(ret)
 
          ret = generate_decl_enum(expr['enum'], expr['data'])
+        ret += generate_declaration(expr['enum'], expr['data'], enum=True)
          fdecl.write(ret)
 
  fdecl.write('''
Signature · 1 line
			Amos.
#25 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum

Quoted 65 lines · On Thu, 07 Jun 2012 10:52:46 +0800 Amos Kong <[email protected]> wrote:
Quoted 36 lines · Michael Roth
Quoted 14 lines · Luiz Capitulino
Quoted 11 lines · On Sat, 2 Jun 2012 06:54:27 +0800 Amos Kong<[email protected]> wrote:

Currently, if define an 'enum' and use it in one command's data, List struct for enum could not be generated, but it's used in qmp function.

For example: KeyCodesList could not be generated.

Quoted 1 line
Quoted 1 line
Quoted 1 line

qapi-schema.json:

{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }

Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

qmp-command.h:

void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t hold_time, Error **errp);

This patch makes qapi can generate List struct for enum.

This patch does it the simple way, just like any type. It generates a enum list type and the functions qapi_free_yourenum() and qapi_free_yourenumlist().

Had a couple suggestions, but approach/patch seems reasonable to me.

Quoted 4 lines

The qapi_free_yourenum() list ends up doing nothing, so it could be a good idea to generate an empty body (also note that we're copying the argument's value, this could bite us in the future).

I think we can omit qapi_free_yourenum() completely. Humans will know not to free non-allocated types, and the generated marshallers don't use these interfaces.

Quoted 1 line
Quoted 10 lines
Quoted 3 lines

Another point I was wondering is that, all enums will end up having the exact same code. So maybe we could generate a default int list and use it for all enums. Not sure it's worth it though.

Since it's generated code I don't think it's worth it, personally.

Quoted 4 lines

Michael, Paolo, ideas?

More review comments below.

Thanks for your review!

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
---
  scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
  scripts/qapi-visit.py |   14 +++++++++-----
  2 files changed, 38 insertions(+), 9 deletions(-)
scripts/qapi-types.py +0 -0
index 4a734f5..c9641fb 100644
@@ -16,17 +16,36 @@ import os
  import getopt
  import errno
 
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

scripts/qapi-types.py import os · line 19

Quoted 3 lines
scripts/qapi-types.py +1 -2
-def generate_fwd_struct(name, members):
-    return mcgen('''
+def generate_fwd_struct(name, members, enum=False):

I think it's better to have generate_fwd_enum_struct().

I tried this before, too many duplicate codes would be introduced, but it's more clear.

You could try to move the duplicated code to a third function (or move the specific bits to generate_fwd_enum_struct() and generate_enum_declaration()).

Quoted 122 lines

two functions need to be added
qapi-types.py: def generate_fwd_enum_struct(name, members):
qapi-visit.py: def generate_enum_declaration(name, members,
genlist=True):

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
scripts/qapi-types.py +21 -1
+    ret = ""
+    if not enum:
+        ret += mcgen('''
  typedef struct %(name)s %(name)s;
 
+''',
+                     name=name)
+    ret += mcgen('''
  typedef struct %(name)sList
  {
-    %(name)s *value;
+''',
+                     name=name)
+    if enum:
+        ret += mcgen('''
+         %(name)s value;
+''',
+                     name=name)
+    else:
+        ret += mcgen('''
+         %(name)s * value;
+''',
+                     name=name)
+
+    ret += mcgen('''
      struct %(name)sList *next;
  } %(name)sList;
  ''',
                   name=name)
+    return ret
 
Quoted 11 lines
Quoted 11 lines

scripts/qapi-types.py for expr in exprs: · line 287

Quoted 8 lines
scripts/qapi-types.py +1 -1
  def generate_struct(structname, fieldname, members):
      ret = mcgen('''
@@ -265,7 +284,8 @@ for expr in exprs:
      if expr.has_key('type'):
          ret += generate_fwd_struct(expr['type'], expr['data'])
      elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data'])
+        ret += generate_enum(expr['enum'], expr['data']) + "\n"

The new-line should be returned by generate_enum(). Same applies for the occurrences below.

"\n" is used to add a blank line here.

Quoted 40 lines
Quoted 39 lines
Quoted 39 lines
scripts/qapi-types.py +6 -0
+        ret += generate_fwd_struct(expr['enum'], expr['data'], True)
          fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
      elif expr.has_key('union'):
          ret += generate_fwd_struct(expr['union'], expr['data']) + "\n"
@@ -289,6 +309,11 @@ for expr in exprs:
          fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
          ret += generate_type_cleanup_decl(expr['union'])
          fdef.write(generate_type_cleanup(expr['union']) + "\n")
+    elif expr.has_key('enum'):
+        ret += generate_type_cleanup_decl(expr['enum'] + "List")
+        fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")
+        ret += generate_type_cleanup_decl(expr['enum'])
+        fdef.write(generate_type_cleanup(expr['enum']) + "\n")
      else:
          continue
      fdecl.write(ret)
scripts/qapi-visit.py +5 -3
index 8d4e94a..e44edfa 100644
@@ -81,7 +81,7 @@ end:
  ''')
      return ret
 
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, enum=False):
      return mcgen('''
 
  void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
@@ -160,12 +160,14 @@ end:
 
      return ret
 
-def generate_declaration(name, members, genlist=True):
-    ret = mcgen('''
+def generate_declaration(name, members, genlist=True, enum=False):
+    ret = ""
+    if not enum:
+        ret = mcgen('''
Quoted 6 lines
Quoted 6 lines

scripts/qapi-visit.py end: · line 170

Quoted 4 lines
scripts/qapi-visit.py +1 -1
  void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
  ''',
-                name=name)
+                    name=name)

Why this change?

Indent of above "mcgen(" changes, make them aligned.

Quoted 19 lines
Quoted 19 lines
Quoted 17 lines
scripts/qapi-visit.py +3 -1
      if genlist:
          ret += mcgen('''
@@ -293,10 +295,12 @@ for expr in exprs:
          ret += generate_declaration(expr['union'], expr['data'])
          fdecl.write(ret)
      elif expr.has_key('enum'):
-        ret = generate_visit_enum(expr['enum'], expr['data'])
+        ret = generate_visit_list(expr['enum'], expr['data'], True)
+        ret += generate_visit_enum(expr['enum'], expr['data'])
          fdef.write(ret)
 
          ret = generate_decl_enum(expr['enum'], expr['data'])
+        ret += generate_declaration(expr['enum'], expr['data'], enum=True)
          fdecl.write(ret)
 
  fdecl.write('''
#26 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum

In reply to Amos Kong
Quoted 78 lines · Amos Kong

Currently, if define an 'enum' and use it in one command's data, List struct for enum could not be generated, but it's used in qmp function.

For example: KeyCodesList could not be generated.

Quoted 1 line
Quoted 1 line
Quoted 1 line

qapi-schema.json:

{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }

Quoted 1 line
Quoted 1 line
Quoted 1 line

qmp-command.h:

void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t hold_time, Error **errp);

This patch makes qapi can generate List struct for enum.

---
 scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
 scripts/qapi-visit.py |   14 +++++++++-----
 2 files changed, 38 insertions(+), 9 deletions(-)
scripts/qapi-types.py +24 -4
index 4a734f5..c9641fb 100644
@@ -16,17 +16,36 @@ import os
 import getopt
 import errno
 
-def generate_fwd_struct(name, members):
-    return mcgen('''
+def generate_fwd_struct(name, members, enum=False):
+    ret = ""
+    if not enum:
+        ret += mcgen('''
 typedef struct %(name)s %(name)s;
 
+''',
+                     name=name)
+    ret += mcgen('''
 typedef struct %(name)sList
 {
-    %(name)s *value;
+''',
+                     name=name)
+    if enum:
+        ret += mcgen('''
+         %(name)s value;
+''',
+                     name=name)
+    else:
+        ret += mcgen('''
+         %(name)s * value;
+''',
+                     name=name)
+
+    ret += mcgen('''
     struct %(name)sList *next;
 } %(name)sList;
 ''',
                  name=name)
+    return ret
 
 def generate_struct(structname, fieldname, members):
     ret = mcgen('''
@@ -265,7 +284,8 @@ for expr in exprs:
     if expr.has_key('type'):
         ret += generate_fwd_struct(expr['type'], expr['data'])
     elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data'])
+        ret += generate_enum(expr['enum'], expr['data']) + "\n"
+        ret += generate_fwd_struct(expr['enum'], expr['data'], True)
         fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
     elif expr.has_key('union'):
         ret += generate_fwd_struct(expr['union'], expr['data']) + "\n"

scripts/qapi-types.py for expr in exprs: · line 314

Quoted 6 lines
scripts/qapi-types.py +3 -0
@@ -289,6 +309,11 @@ for expr in exprs:
         fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
         ret += generate_type_cleanup_decl(expr['union'])
         fdef.write(generate_type_cleanup(expr['union']) + "\n")
+    elif expr.has_key('enum'):
+        ret += generate_type_cleanup_decl(expr['enum'] + "List")
+        fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")

This one is fine

scripts/qapi-types.py for expr in exprs: · line 316

Quoted 2 lines
scripts/qapi-types.py +2 -0
+        ret += generate_type_cleanup_decl(expr['enum'])
+        fdef.write(generate_type_cleanup(expr['enum']) + "\n")

but we don't need this one since enum types are passed around by copy.

The qapi_free_X() functions are utility functions that aren't used by the code generators, so there should be any harm in omitting these.

Quoted 8 lines
scripts/qapi-types.py +0 -0
     else:
         continue
     fdecl.write(ret)
scripts/qapi-visit.py +0 -0
index 8d4e94a..e44edfa 100644

scripts/qapi-visit.py end: · line 86

Quoted 7 lines
scripts/qapi-visit.py +1 -1
@@ -81,7 +81,7 @@ end:
 ''')
     return ret
 
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, enum=False):
     return mcgen('''
 

Were there plans to add a branch for enum=True? Otherwise we can drop this from the patch.

Quoted 37 lines
scripts/qapi-visit.py +8 -4
 void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
@@ -160,12 +160,14 @@ end:
 
     return ret
 
-def generate_declaration(name, members, genlist=True):
-    ret = mcgen('''
+def generate_declaration(name, members, genlist=True, enum=False):
+    ret = ""
+    if not enum:
+        ret = mcgen('''
 
 void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
 ''',
-                name=name)
+                    name=name)
 
     if genlist:
         ret += mcgen('''
@@ -293,10 +295,12 @@ for expr in exprs:
         ret += generate_declaration(expr['union'], expr['data'])
         fdecl.write(ret)
     elif expr.has_key('enum'):
-        ret = generate_visit_enum(expr['enum'], expr['data'])
+        ret = generate_visit_list(expr['enum'], expr['data'], True)
+        ret += generate_visit_enum(expr['enum'], expr['data'])
         fdef.write(ret)
 
         ret = generate_decl_enum(expr['enum'], expr['data'])
+        ret += generate_declaration(expr['enum'], expr['data'], enum=True)
         fdecl.write(ret)
 
 fdecl.write('''
Signature · 1 line
1.7.1
author
#27 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum

Quoted 88 lines · Michael Roth
Quoted 78 lines · Amos Kong

Currently, if define an 'enum' and use it in one command's data, List struct for enum could not be generated, but it's used in qmp function.

For example: KeyCodesList could not be generated.

Quoted 1 line
Quoted 1 line
Quoted 1 line

qapi-schema.json:

{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }

Quoted 1 line
Quoted 1 line
Quoted 1 line

qmp-command.h:

void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t hold_time, Error **errp);

This patch makes qapi can generate List struct for enum.

---
  scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
  scripts/qapi-visit.py |   14 +++++++++-----
  2 files changed, 38 insertions(+), 9 deletions(-)
scripts/qapi-types.py +24 -4
index 4a734f5..c9641fb 100644
@@ -16,17 +16,36 @@ import os
  import getopt
  import errno
 
-def generate_fwd_struct(name, members):
-    return mcgen('''
+def generate_fwd_struct(name, members, enum=False):
+    ret = ""
+    if not enum:
+        ret += mcgen('''
  typedef struct %(name)s %(name)s;
 
+''',
+                     name=name)
+    ret += mcgen('''
  typedef struct %(name)sList
  {
-    %(name)s *value;
+''',
+                     name=name)
+    if enum:
+        ret += mcgen('''
+         %(name)s value;
+''',
+                     name=name)
+    else:
+        ret += mcgen('''
+         %(name)s * value;
+''',
+                     name=name)
+
+    ret += mcgen('''
      struct %(name)sList *next;
  } %(name)sList;
  ''',
                   name=name)
+    return ret
 
  def generate_struct(structname, fieldname, members):
      ret = mcgen('''
@@ -265,7 +284,8 @@ for expr in exprs:
      if expr.has_key('type'):
          ret += generate_fwd_struct(expr['type'], expr['data'])
      elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data'])
+        ret += generate_enum(expr['enum'], expr['data']) + "\n"
+        ret += generate_fwd_struct(expr['enum'], expr['data'], True)
          fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
      elif expr.has_key('union'):
          ret += generate_fwd_struct(expr['union'], expr['data']) + "\n"

scripts/qapi-types.py for expr in exprs: · line 314

Quoted 6 lines
scripts/qapi-types.py +3 -0
@@ -289,6 +309,11 @@ for expr in exprs:
          fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
          ret += generate_type_cleanup_decl(expr['union'])
          fdef.write(generate_type_cleanup(expr['union']) + "\n")
+    elif expr.has_key('enum'):
+        ret += generate_type_cleanup_decl(expr['enum'] + "List")
+        fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")

This one is fine

Quoted 7 lines

scripts/qapi-types.py for expr in exprs: · line 316

Quoted 2 lines
scripts/qapi-types.py +2 -0
+        ret += generate_type_cleanup_decl(expr['enum'])
+        fdef.write(generate_type_cleanup(expr['enum']) + "\n")

but we don't need this one since enum types are passed around by copy.

The qapi_free_X() functions are utility functions that aren't used by the code generators, so there should be any harm in omitting these.

Ok, will drop those two sentences.

Quoted 11 lines
Quoted 11 lines
scripts/qapi-types.py +0 -0
      else:
          continue
      fdecl.write(ret)
scripts/qapi-visit.py +0 -0
index 8d4e94a..e44edfa 100644
@@ -81,7 +81,7 @@ end:
  ''')
      return ret
 
Quoted 7 lines

scripts/qapi-visit.py end: · line 86

Quoted 4 lines
scripts/qapi-visit.py +1 -1
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, enum=False):
      return mcgen('''
 

Were there plans to add a branch for enum=True? Otherwise we can drop this from the patch.

redundant, will drop it.

Quoted 37 lines
Quoted 37 lines
scripts/qapi-visit.py +8 -5
  void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
@@ -160,12 +160,14 @@ end:
 
      return ret
 
-def generate_declaration(name, members, genlist=True):
-    ret = mcgen('''
+def generate_declaration(name, members, genlist=True, enum=False):
+    ret = ""
+    if not enum:
+        ret = mcgen('''
 
  void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
  ''',
-                name=name)
+                    name=name)
 
      if genlist:
          ret += mcgen('''
@@ -293,10 +295,12 @@ for expr in exprs:
          ret += generate_declaration(expr['union'], expr['data'])
          fdecl.write(ret)
      elif expr.has_key('enum'):
-        ret = generate_visit_enum(expr['enum'], expr['data'])
+        ret = generate_visit_list(expr['enum'], expr['data'], True)
+        ret += generate_visit_enum(expr['enum'], expr['data'])
          fdef.write(ret)
 
          ret = generate_decl_enum(expr['enum'], expr['data'])
+        ret += generate_declaration(expr['enum'], expr['data'], enum=True)
          fdecl.write(ret)
 
  fdecl.write('''
--

1.7.1

Signature · 1 line
			Amos.
author
#28 lore raw

PATCH v2 6/6 qapi: convert sendkey

In reply to Amos Kong

Convert 'sendkey' to use QAPI. do_sendkey() depends on some variables/functions in monitor.c, so reserve qmp_sendkey() to monitor.c

key_defs[] in monitor.c is the mapping of key name to keycode, Keys' order in the enmu and key_defs[] is same.

---
 hmp-commands.hx  |    2 +-
 hmp.c            |   56 +++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    1 +
 monitor.c        |   70 +++++++++++++----------------------------------------
 qapi-schema.json |   47 ++++++++++++++++++++++++++++++++++++
 qmp-commands.hx  |   27 ++++++++++++++++++++
 6 files changed, 149 insertions(+), 54 deletions(-)
hmp-commands.hx +1 -1
index 18b8e31..afbfa61 100644
@@ -505,7 +505,7 @@ ETEXI
         .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 +56 -0

65 lines not on this page · raw message

hmp.h +1 -0
index 443b812..40de72c 100644
@@ -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 +17 -53

94 lines not on this page · raw message

qapi-schema.json +47 -0

50 lines not on this page · raw message

qmp-commands.hx +27 -0
index db980fa..3692805 100644
@@ -335,6 +335,33 @@ Example:
 EQMP
 
     {
+        .name       = "sendkey",
+        .args_type  = "keys:O,hold-time:i?",
+        .mhandler.cmd_new = qmp_marshal_input_sendkey,
+    },
+
+SQMP
+sendkey
+----------
+
+Send keys to VM.
+
+Arguments:
+
+keys array:
+    - "key": key sequence (json-string)
+
+- hold-time: time to delay key up events, miliseconds (josn-int, optional)
+
+Example:
+
+-> { "execute": "sendkey",
+     "arguments": { 'keys': [ 'ctrl', 'alt', 'delete' ] } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "cpu",
         .args_type  = "index:i",
         .mhandler.cmd_new = qmp_marshal_input_cpu,
Signature · 1 line
1.7.1
#29 lore raw

Re: [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey

Quoted 14 lines · Amos Kong

Convert 'sendkey' to use QAPI. do_sendkey() depends on some variables/functions in monitor.c, so reserve qmp_sendkey() to monitor.c

key_defs[] in monitor.c is the mapping of key name to keycode, Keys' order in the enmu and key_defs[] is same.

---

+++ b/qapi-schema.json

qapi-schema.json +0 -0
@@ -1755,3 +1755,50 @@
 # Since: 0.14.0
 ##

qapi-schema.json line 1766

Quoted 10 lines
qapi-schema.json +9 -0
 { 'command': 'device_del', 'data': {'id': 'str'} }
+
+##
+# @KeyCodes:
+#
+# An enumeration of key name.
+#
+# This is used by the sendkey command.
+#
+# Since: 0.14.0

Really? Or is this enum since 1.2?

Quoted 6 lines
qapi-schema.json +6 -0
+
+##
+# @sendkey:
+#
+# Send keys to VM.
+#

qapi-schema.json line 1799

Quoted 10 lines
qapi-schema.json +10 -0
+# @keys: key sequence
+# @hold-time: time to delay key up events, milliseconds
+#
+# Returns: Nothing on success
+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
+#          If keys number is over the limitation, QERR_OVERFLOW
+#
+# Notes: Send keys to the emulator. Keys could be the name of the
+#        key or the raw value in either decimal or hexadecimal  format. Use
+#        "-" to press several keys simultaneously.

These notes don't really correspond to the QMP interface of passing in a JSON array of simultaneous keys to press.

Review line 1784

Quoted 2 lines
(quoted diff) +2 -0
+#
+# Since: 0.14.0

Again, shouldn't this be 1.2?

qmp-commands.hx Example: · line 354

Quoted 12 lines
qmp-commands.hx +12 -0
+SQMP
+sendkey
+----------
+
+Send keys to VM.
+
+Arguments:
+
+keys array:
+    - "key": key sequence (json-string)
+
+- hold-time: time to delay key up events, miliseconds (josn-int, optional)

s/miliseconds/milliseconds/

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#30 lore raw

Re: [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey

Hello Eric,

Thanks for your comments.

----- Original Message -----

Quoted 11 lines · Amos Kong
Quoted 9 lines

Convert 'sendkey' to use QAPI. do_sendkey() depends on some variables/functions in monitor.c, so reserve qmp_sendkey() to monitor.c

key_defs[] in monitor.c is the mapping of key name to keycode, Keys' order in the enmu and key_defs[] is same.

---

Quoted 16 lines
Quoted 4 lines

+++ b/qapi-schema.json

qapi-schema.json +0 -0
@@ -1755,3 +1755,50 @@
 # Since: 0.14.0
 ##

qapi-schema.json line 1766

Quoted 10 lines
qapi-schema.json +9 -0
 { 'command': 'device_del', 'data': {'id': 'str'} }
+
+##
+# @KeyCodes:
+#
+# An enumeration of key name.
+#
+# This is used by the sendkey command.
+#
+# Since: 0.14.0

Really? Or is this enum since 1.2?

Yeah, it should be 1.2

Quoted 12 lines
Quoted 12 lines
qapi-schema.json +11 -0
+
+##
+# @sendkey:
+#
+# Send keys to VM.
+#
+# @keys: key sequence
+# @hold-time: time to delay key up events, milliseconds
+#
+# Returns: Nothing on success
+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
Quoted 8 lines

qapi-schema.json line 1799

Quoted 5 lines
qapi-schema.json +5 -0
+#          If keys number is over the limitation, QERR_OVERFLOW
+#
+# Notes: Send keys to the emulator. Keys could be the name of the
+#        key or the raw value in either decimal or hexadecimal format. Use
+#        "-" to press several keys simultaneously.

These notes don't really correspond to the QMP interface of passing in a JSON array of simultaneous keys to press.

# Notes: Send keys to the emulator. Keys could be the name of the
# key or the raw value in either decimal or hexadecimal format. Use
# a JSON array to press several keys simultaneously.

Ho, I found another bug in my code, key in decimal or hexadecimal format is not supported. I will fix it.

Quoted 4 lines

Review line 1784

Quoted 2 lines
(quoted diff) +2 -0
+#
+# Since: 0.14.0

Again, shouldn't this be 1.2?

yeah, 1.2

Quoted 22 lines
Quoted 13 lines
qmp-commands.hx +12 -0
+SQMP
+sendkey
+----------
+
+Send keys to VM.
+
+Arguments:
+
+keys array:
+    - "key": key sequence (json-string)
+
+- hold-time: time to delay key up events, miliseconds (josn-int,
Quoted 1 line

optional)

s/miliseconds/milliseconds/

--
Eric Blake [email protected] +1-919-301-3266
Libvirt virtualization library http://libvirt.org

#31 lore raw

Re: [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey

Quoted 19 lines · Amos Kong
Quoted 9 lines
Quoted 9 lines
qapi-schema.json +9 -0
+# @sendkey:
+#
+# Send keys to VM.
+#
+# @keys: key sequence
+# @hold-time: time to delay key up events, milliseconds
+#
+# Returns: Nothing on success
+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
Quoted 8 lines

qapi-schema.json line 1799

Quoted 5 lines
qapi-schema.json +5 -0
+#          If keys number is over the limitation, QERR_OVERFLOW
+#
+# Notes: Send keys to the emulator. Keys could be the name of the
+#        key or the raw value in either decimal or hexadecimal format. Use
+#        "-" to press several keys simultaneously.

These notes don't really correspond to the QMP interface of passing in a JSON array of simultaneous keys to press.

Quoted 8 lines

# Notes: Send keys to the emulator. Keys could be the name of the
# key or the raw value in either decimal or hexadecimal format. Use
# a JSON array to press several keys simultaneously.

Ho, I found another bug in my code, key in decimal or hexadecimal format is not supported. I will fix it.

How do you plan to support decimal in QMP? I don't think it's possible, at least not without still keeping a JSON array of keys to press. On the other hand, I'm not sure if we need to worry about that. Let me explain:

Let's suppose the QMP interface is symbolic only.

In the HMP interface, _you_ can use the lookup list to convert decimal to key name, so that the HMP interface is a wrapper around the QMP interface, but everything is symbolic by the time we get that far.

In the libvirt case, where libvirt talks directly to QMP, libvirt also has the same table for looking up keysyms vs. values (in fact, libvirt already uses that table to convert between different keysets, so for an example, the libvirt user can specify a command using xt_kbd or usb or ... mappings, which libvirt then converts into the mapping desired by qemu). Since libvirt already consults a table, libvirt can ensure that the table has the proper QMP symbolic names in that table.

Finally, I know there was a patch proposed by Dan Berrange a while back to let both libvirt and qemu share a common database of keyset names and corresponding integer mappings. I don't remember if it was applied to qemu; if not, it should be revived and used at this time.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#32 lore raw

Re: [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey

Quoted 27 lines · Eric Blake
Quoted 25 lines · Amos Kong
Quoted 9 lines
Quoted 9 lines
qapi-schema.json +9 -0
+# @sendkey:
+#
+# Send keys to VM.
+#
+# @keys: key sequence
+# @hold-time: time to delay key up events, milliseconds
+#
+# Returns: Nothing on success
+#          If key is unknown or redundant, QERR_INVALID_PARAMETER
Quoted 8 lines

qapi-schema.json line 1799

Quoted 5 lines
qapi-schema.json +5 -0
+#          If keys number is over the limitation, QERR_OVERFLOW
+#
+# Notes: Send keys to the emulator. Keys could be the name of the
+#        key or the raw value in either decimal or hexadecimal format. Use
+#        "-" to press several keys simultaneously.

These notes don't really correspond to the QMP interface of passing in a JSON array of simultaneous keys to press.

# Notes: Send keys to the emulator. Keys could be the name of the
# key or the raw value in either decimal or hexadecimal format. Use
# a JSON array to press several keys simultaneously.

Quoted 4 lines
Quoted 2 lines

Ho, I found another bug in my code, key in decimal or hexadecimal format is not supported. I will fix it.

How do you plan to support decimal in QMP?

In old do_sendkey(), only key-name and hexadecimal were supported, the description needs to be fixed.

Quoted 5 lines

I don't think it's possible,
at least not without still keeping a JSON array of keys to press. On the other hand, I'm not sure if we need to worry about that. Let me explain:

Quoted 7 lines

Let's suppose the QMP interface is symbolic only.

In the HMP interface, _you_ can use the lookup list to convert decimal to key name, so that the HMP interface is a wrapper around the QMP interface, but everything is symbolic by the time we get that far.

In the libvirt case, where libvirt talks directly to QMP,

It seems we can only support key-name for QMP, and support key-name/hexadecimal for HMP. Is it acceptable?

Quoted 14 lines

libvirt also
has the same table for looking up keysyms vs. values (in fact, libvirt already uses that table to convert between different keysets, so for an example, the libvirt user can specify a command using xt_kbd or usb or ... mappings, which libvirt then converts into the mapping desired by qemu). Since libvirt already consults a table, libvirt can ensure that the table has the proper QMP symbolic names in that table.

Finally, I know there was a patch proposed by Dan Berrange a while back to let both libvirt and qemu share a common database of keyset names and corresponding integer mappings. I don't remember if it was applied to qemu; if not, it should be revived and used at this time.

Signature · 1 line
			Amos.
#33 lore raw

Re: [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey

Quoted 5 lines · Amos Kong
Quoted 4 lines
Quoted 2 lines

Ho, I found another bug in my code, key in decimal or hexadecimal format is not supported. I will fix it.

How do you plan to support decimal in QMP?

Quoted 8 lines

In old do_sendkey(), only key-name and hexadecimal were supported, the description needs to be fixed.

It seems we can only support key-name for QMP, and support key-name/hexadecimal
for HMP. Is it acceptable?

Yes, that was my argument for bare minimum support - anyone using QMP (like libvirt) will have to be smart enough to use key-name only, while anyone using HMP will be able to use hex because HMP will convert hex to key-name at the appropriate time before calling into QMP.

Of course, being able to support hex from QMP would be a nice feature, but I'm not sure how to add it in.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#34 lore raw

Re: [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey

Quoted 16 lines · Eric Blake
Quoted 5 lines · Amos Kong
Quoted 4 lines
Quoted 2 lines

Ho, I found another bug in my code, key in decimal or hexadecimal format is not supported. I will fix it.

How do you plan to support decimal in QMP?

Quoted 8 lines

In old do_sendkey(), only key-name and hexadecimal were supported, the description needs to be fixed.

It seems we can only support key-name for QMP, and support key-name/hexadecimal
for HMP. Is it acceptable?

Quoted 7 lines

Yes, that was my argument for bare minimum support - anyone using QMP (like libvirt) will have to be smart enough to use key-name only, while anyone using HMP will be able to use hex because HMP will convert hex to key-name at the appropriate time before calling into QMP.

Of course, being able to support hex from QMP would be a nice feature, but I'm not sure how to add it in.

Why is it a nice feature?

I don't quite understand why anyone would want to use hex actually... You would have to convert from whatever symbolic code you're using to QEMU's hex value so why not just stay in symbolic representation.

Regards,

Anthony Liguori

Quoted 1 line
#35 lore raw

Re: [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey

Quoted 4 lines · Anthony Liguori
Quoted 2 lines

Of course, being able to support hex from QMP would be a nice feature, but I'm not sure how to add it in.

Why is it a nice feature?

Because libvirt already allows users to pass in integers instead of symbolic names. Providing integer support in QMP would let the path be passthrough, instead of libvirt doing a reverse lookup to convert integer to symbol just to call QMP for qemu to do a lookup from symbol back to integer.

Quoted 4 lines

I don't quite understand why anyone would want to use hex actually... You would have to convert from whatever symbolic code you're using to QEMU's hex value so why not just stay in symbolic representation.

Staying just symbolic is fine - remember, I already stated that libvirt already has a lookup table to convert between several different keycode sets already, and Dan Berrange has already proposed sharing that table with qemu. And settling on symbolic as the only interface, even if it is less efficient than integer passthrough, is at least easier to maintain.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#36 lore raw
In reply to Amos Kong

----- Original Message -----

Quoted 9 lines

This series converted 'sendkey' command to qapi.

Amos Kong (6):
qerror: add QERR_OVERFLOW
fix doc of using raw values with sendkey rename keyname '<' to 'less'
hmp: rename arguments
qapi: generate list struct and visit_list for enum
qapi: convert sendkey

Changes from v1:
- using a JSON array for the key names
- rename new error to 'QERR_OVERFLOW'
- fix command descriptions
- qapi: generate list struct for enum
- add '<' fixing

Quoted 15 lines
 hmp-commands.hx       |    8 +++---
 hmp.c                 |   56
 +++++++++++++++++++++++++++++++++++++++++
 hmp.h                 |    1 +
 monitor.c             |   67
 ++++++++++++++-----------------------------------
 qapi-schema.json      |   47 ++++++++++++++++++++++++++++++++++
 qerror.c              |    4 +++
 qerror.h              |    3 ++
 qmp-commands.hx       |   27 +++++++++++++++++++
 scripts/qapi-types.py |   33 +++++++++++++++++++++---
 scripts/qapi-visit.py |   14 ++++++---
 10 files changed, 199 insertions(+), 61 deletions(-)