qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands.
@ 2014-02-06 22:30 Hani Benhabiles
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion Hani Benhabiles
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Hani Benhabiles @ 2014-02-06 22:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: imammedo, pbonzini, lcapitulino

This patch series add argument completion to multiple human monitor console
commands.

For device_add and object_add, only the 1st argument is completed.

Hani Benhabiles (4):
  monitor: Add device_del id argument completion.
  monitor: Add device_add device argument completion.
  monitor: Add object_del id argument completion.
  monitor: Add object_add class argument completion.

 monitor.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

-- 
1.8.3.2

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

* [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion.
  2014-02-06 22:30 [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Hani Benhabiles
@ 2014-02-06 22:30 ` Hani Benhabiles
  2014-02-11 18:35   ` Luiz Capitulino
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 2/4] monitor: Add device_add device " Hani Benhabiles
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Hani Benhabiles @ 2014-02-06 22:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: imammedo, pbonzini, lcapitulino

---
 monitor.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/monitor.c b/monitor.c
index b1ea262..f8c4cae 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4254,6 +4254,25 @@ static const char *next_arg_type(const char *typestr)
     return (p != NULL ? ++p : typestr);
 }
 
+static void device_del_completion(ReadLineState *rs, BusState *bus,
+                                  const char *str, size_t len)
+{
+    BusChild *kid;
+
+    QTAILQ_FOREACH(kid, &bus->children, sibling) {
+        DeviceState *dev = kid->child;
+        BusState *dev_child;
+
+        if (dev->id && !strncmp(str, dev->id, len)) {
+            readline_add_completion(rs, dev->id);
+        }
+
+        QLIST_FOREACH(dev_child, &dev->child_bus, sibling) {
+            device_del_completion(rs, dev_child, str, len);
+        }
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
@@ -4330,6 +4349,10 @@ static void monitor_find_completion_by_table(Monitor *mon,
             } else if (!strcmp(cmd->name, "help|?")) {
                 monitor_find_completion_by_table(mon, cmd_table,
                                                  &args[1], nb_args - 1);
+            } else if (!strcmp(cmd->name, "device_del") && nb_args == 2) {
+                size_t len = strlen(str);
+                readline_set_completion_index(mon->rs, len);
+                device_del_completion(mon->rs, sysbus_get_default(), str, len);
             }
             break;
         default:
-- 
1.8.3.2

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

* [Qemu-devel] [PATCH 2/4] monitor: Add device_add device argument completion.
  2014-02-06 22:30 [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Hani Benhabiles
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion Hani Benhabiles
@ 2014-02-06 22:30 ` Hani Benhabiles
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 3/4] monitor: Add object_del id " Hani Benhabiles
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Hani Benhabiles @ 2014-02-06 22:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: imammedo, pbonzini, lcapitulino

---
 monitor.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/monitor.c b/monitor.c
index f8c4cae..65410cb 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4254,6 +4254,27 @@ 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 device_del_completion(ReadLineState *rs, BusState *bus,
                                   const char *str, size_t len)
 {
@@ -4336,6 +4357,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") && nb_args == 2) {
+                device_add_completion(mon->rs, str);
+            }
+            break;
         case 's':
         case 'S':
             if (!strcmp(cmd->name, "sendkey")) {
-- 
1.8.3.2

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

* [Qemu-devel] [PATCH 3/4] monitor: Add object_del id argument completion.
  2014-02-06 22:30 [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Hani Benhabiles
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion Hani Benhabiles
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 2/4] monitor: Add device_add device " Hani Benhabiles
@ 2014-02-06 22:30 ` Hani Benhabiles
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 4/4] monitor: Add object_add class " Hani Benhabiles
  2014-02-11 18:39 ` [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Luiz Capitulino
  4 siblings, 0 replies; 10+ messages in thread
From: Hani Benhabiles @ 2014-02-06 22:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: imammedo, pbonzini, lcapitulino

---
 monitor.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/monitor.c b/monitor.c
index 65410cb..4a2c1ae 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4294,6 +4294,27 @@ static void device_del_completion(ReadLineState *rs, BusState *bus,
     }
 }
 
+static void object_del_completion(ReadLineState *rs, const char *str)
+{
+    ObjectPropertyInfoList *list, *start;
+    size_t len;
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+
+    start = list = qmp_qom_list("/objects", NULL);
+    while (list) {
+        ObjectPropertyInfo *info = list->value;
+
+        if (!strncmp(info->type, "child<", 5)
+            && !strncmp(info->name, str, len)) {
+            readline_add_completion(rs, info->name);
+        }
+        list = list->next;
+    }
+    qapi_free_ObjectPropertyInfoList(start);
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
@@ -4379,6 +4400,8 @@ static void monitor_find_completion_by_table(Monitor *mon,
                 size_t len = strlen(str);
                 readline_set_completion_index(mon->rs, len);
                 device_del_completion(mon->rs, sysbus_get_default(), str, len);
+            } else if (!strcmp(cmd->name, "object_del") && nb_args == 2) {
+                object_del_completion(mon->rs, str);
             }
             break;
         default:
-- 
1.8.3.2

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

* [Qemu-devel] [PATCH 4/4] monitor: Add object_add class argument completion.
  2014-02-06 22:30 [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Hani Benhabiles
                   ` (2 preceding siblings ...)
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 3/4] monitor: Add object_del id " Hani Benhabiles
@ 2014-02-06 22:30 ` Hani Benhabiles
  2014-02-11 18:38   ` Luiz Capitulino
  2014-02-11 18:39 ` [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Luiz Capitulino
  4 siblings, 1 reply; 10+ messages in thread
From: Hani Benhabiles @ 2014-02-06 22:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: imammedo, pbonzini, lcapitulino

---
 monitor.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/monitor.c b/monitor.c
index 4a2c1ae..397e1fe 100644
--- a/monitor.c
+++ b/monitor.c
@@ -56,6 +56,7 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/json-streamer.h"
 #include "qapi/qmp/json-parser.h"
+#include <qom/object_interfaces.h>
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "trace.h"
@@ -4275,6 +4276,26 @@ static void device_add_completion(ReadLineState *rs, const char *str)
     g_slist_free(list);
 }
 
+static void object_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_USER_CREATABLE, false);
+    while (elt) {
+        const char *name;
+
+        name = object_class_get_name(OBJECT_CLASS(elt->data));
+        if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE)) {
+            readline_add_completion(rs, name);
+        }
+        elt = elt->next;
+    }
+    g_slist_free(list);
+}
+
 static void device_del_completion(ReadLineState *rs, BusState *bus,
                                   const char *str, size_t len)
 {
@@ -4381,6 +4402,8 @@ static void monitor_find_completion_by_table(Monitor *mon,
         case 'O':
             if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
                 device_add_completion(mon->rs, str);
+            } else if (!strcmp(cmd->name, "object_add") && nb_args == 2) {
+                object_add_completion(mon->rs, str);
             }
             break;
         case 's':
-- 
1.8.3.2

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

* Re: [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion.
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion Hani Benhabiles
@ 2014-02-11 18:35   ` Luiz Capitulino
  0 siblings, 0 replies; 10+ messages in thread
From: Luiz Capitulino @ 2014-02-11 18:35 UTC (permalink / raw)
  To: Hani Benhabiles; +Cc: imammedo, qemu-devel, pbonzini

On Thu,  6 Feb 2014 23:30:10 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:

> ---
>  monitor.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)

Your S-o-B is missing in all patches. Can reply to them adding it?

> 
> diff --git a/monitor.c b/monitor.c
> index b1ea262..f8c4cae 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4254,6 +4254,25 @@ static const char *next_arg_type(const char *typestr)
>      return (p != NULL ? ++p : typestr);
>  }
>  
> +static void device_del_completion(ReadLineState *rs, BusState *bus,
> +                                  const char *str, size_t len)
> +{
> +    BusChild *kid;
> +
> +    QTAILQ_FOREACH(kid, &bus->children, sibling) {
> +        DeviceState *dev = kid->child;
> +        BusState *dev_child;
> +
> +        if (dev->id && !strncmp(str, dev->id, len)) {
> +            readline_add_completion(rs, dev->id);
> +        }
> +
> +        QLIST_FOREACH(dev_child, &dev->child_bus, sibling) {
> +            device_del_completion(rs, dev_child, str, len);
> +        }
> +    }
> +}
> +
>  static void monitor_find_completion_by_table(Monitor *mon,
>                                               const mon_cmd_t *cmd_table,
>                                               char **args,
> @@ -4330,6 +4349,10 @@ static void monitor_find_completion_by_table(Monitor *mon,
>              } else if (!strcmp(cmd->name, "help|?")) {
>                  monitor_find_completion_by_table(mon, cmd_table,
>                                                   &args[1], nb_args - 1);
> +            } else if (!strcmp(cmd->name, "device_del") && nb_args == 2) {
> +                size_t len = strlen(str);
> +                readline_set_completion_index(mon->rs, len);
> +                device_del_completion(mon->rs, sysbus_get_default(), str, len);
>              }
>              break;
>          default:

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

* Re: [Qemu-devel] [PATCH 4/4] monitor: Add object_add class argument completion.
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 4/4] monitor: Add object_add class " Hani Benhabiles
@ 2014-02-11 18:38   ` Luiz Capitulino
  2014-02-11 22:14     ` Hani Benhabiles
  0 siblings, 1 reply; 10+ messages in thread
From: Luiz Capitulino @ 2014-02-11 18:38 UTC (permalink / raw)
  To: Hani Benhabiles; +Cc: imammedo, qemu-devel, pbonzini

On Thu,  6 Feb 2014 23:30:13 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:

> ---
>  monitor.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/monitor.c b/monitor.c
> index 4a2c1ae..397e1fe 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -56,6 +56,7 @@
>  #include "qapi/qmp/qjson.h"
>  #include "qapi/qmp/json-streamer.h"
>  #include "qapi/qmp/json-parser.h"
> +#include <qom/object_interfaces.h>
>  #include "qemu/osdep.h"
>  #include "cpu.h"
>  #include "trace.h"
> @@ -4275,6 +4276,26 @@ static void device_add_completion(ReadLineState *rs, const char *str)
>      g_slist_free(list);
>  }
>  
> +static void object_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_USER_CREATABLE, false);
> +    while (elt) {
> +        const char *name;
> +
> +        name = object_class_get_name(OBJECT_CLASS(elt->data));
> +        if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE)) {
> +            readline_add_completion(rs, name);
> +        }
> +        elt = elt->next;
> +    }
> +    g_slist_free(list);
> +}
> +
>  static void device_del_completion(ReadLineState *rs, BusState *bus,
>                                    const char *str, size_t len)
>  {
> @@ -4381,6 +4402,8 @@ static void monitor_find_completion_by_table(Monitor *mon,
>          case 'O':
>              if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
>                  device_add_completion(mon->rs, str);
> +            } else if (!strcmp(cmd->name, "object_add") && nb_args == 2) {
> +                object_add_completion(mon->rs, str);
>              }
>              break;
>          case 's':

Those many ifs need to be generalized. Maybe we could add a
command_completion callback to mon_cmd_t? Anyway, I won't refuse the series
because of that but it would be very welcome to improve this.

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

* Re: [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands.
  2014-02-06 22:30 [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Hani Benhabiles
                   ` (3 preceding siblings ...)
  2014-02-06 22:30 ` [Qemu-devel] [PATCH 4/4] monitor: Add object_add class " Hani Benhabiles
@ 2014-02-11 18:39 ` Luiz Capitulino
  2014-02-11 22:10   ` Hani Benhabiles
  4 siblings, 1 reply; 10+ messages in thread
From: Luiz Capitulino @ 2014-02-11 18:39 UTC (permalink / raw)
  To: Hani Benhabiles; +Cc: imammedo, qemu-devel, pbonzini

On Thu,  6 Feb 2014 23:30:09 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:

> This patch series add argument completion to multiple human monitor console
> commands.
> 
> For device_add and object_add, only the 1st argument is completed.
> 
> Hani Benhabiles (4):
>   monitor: Add device_del id argument completion.
>   monitor: Add device_add device argument completion.
>   monitor: Add object_del id argument completion.
>   monitor: Add object_add class argument completion.
> 
>  monitor.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 95 insertions(+)

Series look good and I've applied it to my queue, but I need your sob
before sending a pull request.

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

* Re: [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands.
  2014-02-11 18:39 ` [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Luiz Capitulino
@ 2014-02-11 22:10   ` Hani Benhabiles
  0 siblings, 0 replies; 10+ messages in thread
From: Hani Benhabiles @ 2014-02-11 22:10 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: imammedo, qemu-devel, pbonzini

On Tue, Feb 11, 2014 at 01:39:13PM -0500, Luiz Capitulino wrote:
> On Thu,  6 Feb 2014 23:30:09 +0100
> Hani Benhabiles <kroosec@gmail.com> wrote:
> 
> > This patch series add argument completion to multiple human monitor console
> > commands.
> > 
> > For device_add and object_add, only the 1st argument is completed.
> > 
> > Hani Benhabiles (4):
> >   monitor: Add device_del id argument completion.
> >   monitor: Add device_add device argument completion.
> >   monitor: Add object_del id argument completion.
> >   monitor: Add object_add class argument completion.
> > 
> >  monitor.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 95 insertions(+)
> 
> Series look good and I've applied it to my queue, but I need your sob
> before sending a pull request.

Thanks Luiz! Sorry about the s-o-b.

Signed-off-by: Hani Benhabiles <hani@linux.com>

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

* Re: [Qemu-devel] [PATCH 4/4] monitor: Add object_add class argument completion.
  2014-02-11 18:38   ` Luiz Capitulino
@ 2014-02-11 22:14     ` Hani Benhabiles
  0 siblings, 0 replies; 10+ messages in thread
From: Hani Benhabiles @ 2014-02-11 22:14 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: imammedo, qemu-devel, pbonzini

On Tue, Feb 11, 2014 at 01:38:32PM -0500, Luiz Capitulino wrote:
> On Thu,  6 Feb 2014 23:30:13 +0100
> Hani Benhabiles <kroosec@gmail.com> wrote:
> 
> > ---
> >  monitor.c | 23 +++++++++++++++++++++++
> >  1 file changed, 23 insertions(+)
> > 
> > diff --git a/monitor.c b/monitor.c
> > index 4a2c1ae..397e1fe 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -56,6 +56,7 @@
> >  #include "qapi/qmp/qjson.h"
> >  #include "qapi/qmp/json-streamer.h"
> >  #include "qapi/qmp/json-parser.h"
> > +#include <qom/object_interfaces.h>
> >  #include "qemu/osdep.h"
> >  #include "cpu.h"
> >  #include "trace.h"
> > @@ -4275,6 +4276,26 @@ static void device_add_completion(ReadLineState *rs, const char *str)
> >      g_slist_free(list);
> >  }
> >  
> > +static void object_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_USER_CREATABLE, false);
> > +    while (elt) {
> > +        const char *name;
> > +
> > +        name = object_class_get_name(OBJECT_CLASS(elt->data));
> > +        if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE)) {
> > +            readline_add_completion(rs, name);
> > +        }
> > +        elt = elt->next;
> > +    }
> > +    g_slist_free(list);
> > +}
> > +
> >  static void device_del_completion(ReadLineState *rs, BusState *bus,
> >                                    const char *str, size_t len)
> >  {
> > @@ -4381,6 +4402,8 @@ static void monitor_find_completion_by_table(Monitor *mon,
> >          case 'O':
> >              if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
> >                  device_add_completion(mon->rs, str);
> > +            } else if (!strcmp(cmd->name, "object_add") && nb_args == 2) {
> > +                object_add_completion(mon->rs, str);
> >              }
> >              break;
> >          case 's':
> 
> Those many ifs need to be generalized. Maybe we could add a
> command_completion callback to mon_cmd_t? Anyway, I won't refuse the series
> because of that but it would be very welcome to improve this.

I agree that it could be made better. I will be looking at it next for possible
improvements.


Cheers,

Hani.

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

end of thread, other threads:[~2014-02-11 22:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-06 22:30 [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Hani Benhabiles
2014-02-06 22:30 ` [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion Hani Benhabiles
2014-02-11 18:35   ` Luiz Capitulino
2014-02-06 22:30 ` [Qemu-devel] [PATCH 2/4] monitor: Add device_add device " Hani Benhabiles
2014-02-06 22:30 ` [Qemu-devel] [PATCH 3/4] monitor: Add object_del id " Hani Benhabiles
2014-02-06 22:30 ` [Qemu-devel] [PATCH 4/4] monitor: Add object_add class " Hani Benhabiles
2014-02-11 18:38   ` Luiz Capitulino
2014-02-11 22:14     ` Hani Benhabiles
2014-02-11 18:39 ` [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands Luiz Capitulino
2014-02-11 22:10   ` Hani Benhabiles

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