Skip to contentSkip to conversation

monitor: Add device_add type argument completion.

PATCH In review Hani Benhabiles 2 participants 4 messages Jan 24, 2014 – Feb 10, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 monitor: Add device_add type argument completion.

---
 monitor.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
monitor.c +25 -0
index 845f608..cf91544 100644
@@ -4254,6 +4254,26 @@ static const char *next_arg_type(const char *typestr)
     return (p != NULL ? ++p : typestr);
 }
 
+static void device_add_completion(ReadLineState *rs, const char *str)
+{
+    GSList *list, *elt;
+    size_t len;
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    list = elt = object_class_get_list(TYPE_DEVICE, false);
+    while (elt) {
+        const char *name;
+        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
+                                             TYPE_DEVICE);
+        name = object_class_get_name(OBJECT_CLASS(dc));
+        if (!strncmp(name, str, len)) {
+            readline_add_completion(rs, name);
+        }
+        elt = elt->next;
+    }
+    g_slist_free(list);
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
@@ -4317,6 +4337,11 @@ static void monitor_find_completion_by_table(Monitor *mon,
             readline_set_completion_index(mon->rs, strlen(str));
             bdrv_iterate(block_completion_it, &mbs);
             break;
+        case 'O':
+            if (!strcmp(cmd->name, "device_add")) {
+                device_add_completion(mon->rs, str);
+            }
+            break;
         case 's':
         case 'S':
             if (!strcmp(cmd->name, "sendkey")) {
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 37 lines · On Fri, 24 Jan 2014 23:27:55 +0100 Hani Benhabiles <[email protected]> wrote:
---
 monitor.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
monitor.c +20 -0
index 845f608..cf91544 100644
@@ -4254,6 +4254,26 @@ static const char *next_arg_type(const char *typestr)
     return (p != NULL ? ++p : typestr);
 }
 
+static void device_add_completion(ReadLineState *rs, const char *str)
+{
+    GSList *list, *elt;
+    size_t len;
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    list = elt = object_class_get_list(TYPE_DEVICE, false);
+    while (elt) {
+        const char *name;
+        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
+                                             TYPE_DEVICE);
+        name = object_class_get_name(OBJECT_CLASS(dc));
+        if (!strncmp(name, str, len)) {
+            readline_add_completion(rs, name);
+        }
+        elt = elt->next;
+    }
+    g_slist_free(list);
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,

monitor.c static void monitor_find_completion_by_table(Monitor *mon, · line 4342

Quoted 6 lines
monitor.c +3 -0
@@ -4317,6 +4337,11 @@ static void monitor_find_completion_by_table(Monitor *mon,
             readline_set_completion_index(mon->rs, strlen(str));
             bdrv_iterate(block_completion_it, &mbs);
             break;
+        case 'O':
+            if (!strcmp(cmd->name, "device_add")) {
+                device_add_completion(mon->rs, str);

This is nice, but it keeps printing auto-completion options even after it has auto-completed. For example:

(qemu) device_add pcnet <TAB>

Will show all device names once again.

Quoted 5 lines
monitor.c +2 -0
+            }
+            break;
         case 's':
         case 'S':
             if (!strcmp(cmd->name, "sendkey")) {
#2 lore raw

Hi Luiz,

Thanks for taking a look at it.

Quoted 50 lines · Luiz Capitulino
Quoted 37 lines · On Fri, 24 Jan 2014 23:27:55 +0100 Hani Benhabiles <[email protected]> wrote:
---
 monitor.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
monitor.c +20 -0
index 845f608..cf91544 100644
@@ -4254,6 +4254,26 @@ static const char *next_arg_type(const char *typestr)
     return (p != NULL ? ++p : typestr);
 }
 
+static void device_add_completion(ReadLineState *rs, const char *str)
+{
+    GSList *list, *elt;
+    size_t len;
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    list = elt = object_class_get_list(TYPE_DEVICE, false);
+    while (elt) {
+        const char *name;
+        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
+                                             TYPE_DEVICE);
+        name = object_class_get_name(OBJECT_CLASS(dc));
+        if (!strncmp(name, str, len)) {
+            readline_add_completion(rs, name);
+        }
+        elt = elt->next;
+    }
+    g_slist_free(list);
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,

monitor.c static void monitor_find_completion_by_table(Monitor *mon, · line 4342

Quoted 6 lines
monitor.c +3 -0
@@ -4317,6 +4337,11 @@ static void monitor_find_completion_by_table(Monitor *mon,
             readline_set_completion_index(mon->rs, strlen(str));
             bdrv_iterate(block_completion_it, &mbs);
             break;
+        case 'O':
+            if (!strcmp(cmd->name, "device_add")) {
+                device_add_completion(mon->rs, str);

This is nice, but it keeps printing auto-completion options even after it has auto-completed. For example:

Quoted 10 lines

(qemu) device_add pcnet <TAB>

Will show all device names once again.

Quoted 5 lines
monitor.c +2 -0
+            }
+            break;
         case 's':
         case 'S':
             if (!strcmp(cmd->name, "sendkey")) {

I fixed the issue in these patch series:
http://lists.gnu.org/archive/html/qemu-devel/2014-02/msg00891.html

Could you please take a look at it ?

Cheers,

Hani.

#3 lore raw
Quoted 66 lines · On Mon, 10 Feb 2014 22:23:02 +0100 Hani Benhabiles <[email protected]> wrote:

Hi Luiz,

Thanks for taking a look at it.

Quoted 50 lines · Luiz Capitulino
Quoted 37 lines · On Fri, 24 Jan 2014 23:27:55 +0100 Hani Benhabiles <[email protected]> wrote:
---
 monitor.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
monitor.c +20 -0
index 845f608..cf91544 100644
@@ -4254,6 +4254,26 @@ static const char *next_arg_type(const char *typestr)
     return (p != NULL ? ++p : typestr);
 }
 
+static void device_add_completion(ReadLineState *rs, const char *str)
+{
+    GSList *list, *elt;
+    size_t len;
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    list = elt = object_class_get_list(TYPE_DEVICE, false);
+    while (elt) {
+        const char *name;
+        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
+                                             TYPE_DEVICE);
+        name = object_class_get_name(OBJECT_CLASS(dc));
+        if (!strncmp(name, str, len)) {
+            readline_add_completion(rs, name);
+        }
+        elt = elt->next;
+    }
+    g_slist_free(list);
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,

monitor.c static void monitor_find_completion_by_table(Monitor *mon, · line 4342

Quoted 6 lines
monitor.c +3 -0
@@ -4317,6 +4337,11 @@ static void monitor_find_completion_by_table(Monitor *mon,
             readline_set_completion_index(mon->rs, strlen(str));
             bdrv_iterate(block_completion_it, &mbs);
             break;
+        case 'O':
+            if (!strcmp(cmd->name, "device_add")) {
+                device_add_completion(mon->rs, str);

This is nice, but it keeps printing auto-completion options even after it has auto-completed. For example:

Quoted 10 lines

(qemu) device_add pcnet <TAB>

Will show all device names once again.

Quoted 5 lines
monitor.c +2 -0
+            }
+            break;
         case 's':
         case 'S':
             if (!strcmp(cmd->name, "sendkey")) {
Quoted 4 lines

I fixed the issue in these patch series:
http://lists.gnu.org/archive/html/qemu-devel/2014-02/msg00891.html

Could you please take a look at it ?

It's in my queue, I should get to it. Eventually :)