All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lin Ma" <lma@suse.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, pbonzini@redhat.com, afaerber@suse.de
Subject: [Qemu-devel] 答复:  [PATCH v4 5/5] object: Add 'help' option for all available backends and properties
Date: Wed, 02 Nov 2016 23:19:26 -0600	[thread overview]
Message-ID: <581B395E02000062000ACC6E@prv-mh.provo.novell.com> (raw)
In-Reply-To: <20161020112829.14589-6-lma@suse.com>

ping...

>>> Lin Ma <lma@suse.com> 2016/10/20 星期四 下午 7:28 >>>
'-object help' prints available user creatable backends.
'-object $typename,help' prints relevant properties.

Signed-off-by: Lin Ma <lma@suse.com>
---
include/qom/object_interfaces.h |  2 ++
qemu-options.hx				 |  7 +++++-
qom/object_interfaces.c		 | 55 +++++++++++++++++++++++++++++++++++++++++
vl.c						    |  5 ++++
4 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index 8b17f4d..197cd5f 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -165,4 +165,6 @@ int user_creatable_add_opts_foreach(void *opaque,
  */
void user_creatable_del(const char *id, Error **errp);

+int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp);
+
#endif
diff --git a/qemu-options.hx b/qemu-options.hx
index b1fbdb0..b9573ce 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3761,7 +3761,9 @@ DEF("object", HAS_ARG, QEMU_OPTION_object,
	 "			    create a new object of type TYPENAME setting properties\n"
	 "			    in the order they are specified.  Note that the 'id'\n"
	 "			    property must be set.  These objects are placed in the\n"
-    " 			   '/objects' path.\n",
+    " 			   '/objects' path.\n"
+    " 			   Use '-object help' to print available backend types and\n"
+    " 			   '-object typename,help' to print relevant properties.\n",
	 QEMU_ARCH_ALL)
STEXI
@item -object @var{typename}[,@var{prop1}=@var{value1},...]
@@ -3771,6 +3773,9 @@ in the order they are specified.  Note that the 'id'
property must be set.  These objects are placed in the
'/objects' path.

+Use @code{-object help} to print available backend types and
+@code{-object @var{typename},help} to print relevant properties.
+
@table @option

@item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index bf59846..da8be39 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -5,6 +5,7 @@
#include "qapi-visit.h"
#include "qapi/qmp-output-visitor.h"
#include "qapi/opts-visitor.h"
+#include "qemu/help_option.h"

void user_creatable_complete(Object *obj, Error **errp)
{
@@ -212,6 +213,60 @@ void user_creatable_del(const char *id, Error **errp)
	 object_unparent(obj);
}

+int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    const char *type = NULL;
+    Object *obj = NULL;
+    ObjectClass *klass;
+    ObjectProperty *prop;
+    ObjectPropertyIterator iter;
+
+    type = qemu_opt_get(opts, "qom-type");
+    if (type && is_help_option(type)) {
+	    GSList *list;
+	    printf("Available object backend types:\n");
+	    for (list = object_class_get_list(TYPE_USER_CREATABLE, false);  \
+			    list; 												  \
+			    list = list->next) {
+		    const char *name;
+		    name = object_class_get_name(OBJECT_CLASS(list->data));
+		    if (strcmp(name, TYPE_USER_CREATABLE)) {
+			    printf("%s\n", name);
+		    }
+	    }
+	    g_slist_free(list);
+	    goto out;
+    }
+
+    if (!type || !qemu_opt_has_help_opt(opts)) {
+	    return 0;
+    }
+
+    klass = object_class_by_name(type);
+    if (!klass) {
+	    printf("invalid object type: %s\n", type);
+	    goto out;
+    }
+    if (object_class_is_abstract(klass)) {
+	    printf("object type '%s' is abstract\n", type);
+	    goto out;
+    }
+    obj = object_new(type);
+    object_property_iter_init(&iter, obj);
+
+    while ((prop = object_property_iter_next(&iter))) {
+	    if (prop->description) {
+		    printf("%s (%s, %s)\n", prop->name, prop->type, prop->description);
+	    } else {
+		    printf("%s (%s)\n", prop->name, prop->type);
+	    }
+    }
+
+out:
+    object_unref(obj);
+    return 1;
+}
+
static void register_types(void)
{
	 static const TypeInfo uc_interface_info = {
diff --git a/vl.c b/vl.c
index ebd47af..145
6eca 100644
--- a/vl.c
+++ b/vl.c
@@ -4100,6 +4100,11 @@ int main(int argc, char **argv, char **envp)
		 exit(0);
	 }

+    if (qemu_opts_foreach(qemu_find_opts("object"), user_creatable_help_func,
+						  NULL, NULL)) {
+	    exit(1);
+    }
+
	 if (!trace_init_backends()) {
		 exit(1);
	 }
-- 
2.9.2

  reply	other threads:[~2016-11-03  5:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-20 11:28 [Qemu-devel] [PATCH v4 0/5] object: Add 'help' option for all available backends and properties Lin Ma
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 1/5] qom: Add interface check in object_class_is_abstract Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-11-03 18:18   ` [Qemu-devel] " Markus Armbruster
2016-11-07  9:19     ` [Qemu-devel] 答复: " Lin Ma
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 2/5] qapi: auto generate enum value strings Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-11-03 19:17   ` [Qemu-devel] " Markus Armbruster
2016-11-07 15:41     ` [Qemu-devel] 答复: " Lin Ma
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 3/5] qapi: add test case for the generated enum value str Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 4/5] backends: add description for enum class properties Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-11-03 19:58   ` [Qemu-devel] " Markus Armbruster
2016-11-07 15:54     ` [Qemu-devel] 答复: " Lin Ma
2016-11-07 16:09     ` [Qemu-devel] " Daniel P. Berrange
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 5/5] object: Add 'help' option for all available backends and properties Lin Ma
2016-11-03  5:19   ` Lin Ma [this message]
2016-11-03 19:50   ` Markus Armbruster
2016-11-07 16:17     ` [Qemu-devel] 答复: " Lin Ma
2016-11-03  5:19 ` [Qemu-devel] 答复: [PATCH v4 0/5] " Lin Ma
2016-12-02 18:37 [Qemu-devel] 答复: [PATCH v4 5/5] " Nutaro, James J.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=581B395E02000062000ACC6E@prv-mh.provo.novell.com \
    --to=lma@suse.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.