qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Valentin Rakush <valentin.rakush@gmail.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, lcapitulino@redhat.com,
	asmetanin@virtuozzo.com, den@openvz.org,
	Valentin Rakush <valentin.rakush@gmail.com>,
	afaerber@suse.de
Subject: [Qemu-devel] [PATCH v4] qom, qmp, hmp, qapi: create qom-type-prop-list for class properties
Date: Fri, 22 Jan 2016 15:15:55 +0300	[thread overview]
Message-ID: <1453464955-1601-1-git-send-email-valentin.rakush@gmail.com> (raw)

This patch adds support for qom-type-prop-list command to list object
class properties. A later patch will use this functionality to
implement x86_64-cpu properties.

Signed-off-by: Valentin Rakush <valentin.rakush@gmail.com>
Cc: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Andreas Färber <afaerber@suse.de>
Cc: Daniel P. Berrange <berrange@redhat.com>
---
V4: review fixes
 - the typename argument in the hmp command changed to be mandatory
V3: commit message fix
 - commit message changed to reflect actual command name
V2: Fixes after first review
 - changed command name from qom-type-list to qom-type-prop-list
 - changed memory allocation from g_malloc0 to g_new0
 - changed parameter name from path to typename
 - fixed wordings and comments
 - fixed source code formatting
 - registered the command in monitor

 hmp-commands.hx      | 13 +++++++++++++
 hmp.c                | 21 +++++++++++++++++++++
 hmp.h                |  1 +
 include/qom/object.h | 31 +++++++++++++++++++++++++++++++
 qapi-schema.json     | 19 +++++++++++++++++++
 qmp-commands.hx      |  6 ++++++
 qmp.c                | 32 ++++++++++++++++++++++++++++++++
 qom/object.c         |  7 +++++++
 8 files changed, 130 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index bb52e4d..ee4d1e2 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1734,6 +1734,19 @@ Print QOM properties of object at location @var{path}
 ETEXI
 
     {
+        .name       = "qom-type-prop-list",
+        .args_type  = "typename:s",
+        .params     = "typename",
+        .help       = "list QOM class properties",
+        .mhandler.cmd  = hmp_qom_type_prop_list,
+    },
+
+STEXI
+@item qom-type-prop-list [@var{typename}]
+Print QOM properties of the type @var{typename}
+ETEXI
+
+    {
         .name       = "qom-set",
         .args_type  = "path:s,property:s,value:s",
         .params     = "path property value",
diff --git a/hmp.c b/hmp.c
index 54f2620..6de9bf0 100644
--- a/hmp.c
+++ b/hmp.c
@@ -2052,6 +2052,27 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)
     hmp_handle_error(mon, &err);
 }
 
+void hmp_qom_type_prop_list(Monitor *mon, const QDict *qdict)
+{
+    const char *typename = qdict_get_try_str(qdict, "typename");
+    ObjectPropertyInfoList *list;
+    Error *err = NULL;
+
+    list = qmp_qom_type_prop_list(typename, &err);
+    if (!err) {
+        ObjectPropertyInfoList *start = list;
+        while (list) {
+            ObjectPropertyInfo *value = list->value;
+
+            monitor_printf(mon, "%s (%s)\n",
+                           value->name, value->type);
+            list = list->next;
+        }
+        qapi_free_ObjectPropertyInfoList(start);
+    }
+    hmp_handle_error(mon, &err);
+}
+
 void hmp_qom_set(Monitor *mon, const QDict *qdict)
 {
     const char *path = qdict_get_str(qdict, "path");
diff --git a/hmp.h b/hmp.h
index a8c5b5a..8c12ebe 100644
--- a/hmp.h
+++ b/hmp.h
@@ -103,6 +103,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_info_memdev(Monitor *mon, const QDict *qdict);
 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
 void hmp_qom_list(Monitor *mon, const QDict *qdict);
+void hmp_qom_type_prop_list(Monitor *mon, const QDict *qdict);
 void hmp_qom_set(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
diff --git a/include/qom/object.h b/include/qom/object.h
index d0dafe9..0c8379d 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1013,6 +1013,37 @@ void object_property_iter_init(ObjectPropertyIterator *iter,
  */
 ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter);
 
+/**
+ * object_class_property_iter_init:
+ * @klass: the class owning the properties to be iterated over
+ *
+ * Initializes an iterator for traversing all properties
+ * registered against a class type and all parent classes.
+ *
+ * It is forbidden to modify the property list while iterating,
+ * whether removing or adding properties.
+ *
+ * NB For getting next property in the list the object related
+ * function object_property_iter_next is still used.
+ *
+ * Typical usage pattern would be
+ *
+ * <example>
+ *   <title>Using object class property iterators</title>
+ *   <programlisting>
+ *   ObjectProperty *prop;
+ *   ObjectPropertyIterator iter;
+ *
+ *   object_class property_iter_init(&iter, obj);
+ *   while ((prop = object_property_iter_next(&iter))) {
+ *     ... do something with prop ...
+ *   }
+ *   </programlisting>
+ * </example>
+ */
+void object_class_property_iter_init(ObjectPropertyIterator *iter,
+                                     ObjectClass *klass);
+
 void object_unparent(Object *obj);
 
 /**
diff --git a/qapi-schema.json b/qapi-schema.json
index b3038b2..2e960db 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4081,3 +4081,22 @@
 ##
 { 'enum': 'ReplayMode',
   'data': [ 'none', 'record', 'play' ] }
+
+##
+# @qom-type-prop-list:
+#
+# This command will list any properties of an object class
+# given its typename.
+#
+# @typename: the typename of the class. See @qom-list-types to check
+#            available typenames.
+#
+# Returns: a list of @ObjectPropertyInfo that describe the properties
+#          of the class.
+#
+# Since: 2.6
+##
+{ 'command': 'qom-type-prop-list',
+  'data': { 'typename': 'str' },
+  'returns': [ 'ObjectPropertyInfo' ] }
+
diff --git a/qmp-commands.hx b/qmp-commands.hx
index db072a6..d3be962 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3789,6 +3789,12 @@ EQMP
     },
 
     {
+        .name       = "qom-type-prop-list",
+        .args_type  = "typename:s",
+        .mhandler.cmd_new = qmp_marshal_qom_type_prop_list,
+    },
+
+    {
         .name       = "qom-set",
 	.args_type  = "path:s,property:s,value:q",
         .mhandler.cmd_new = qmp_marshal_qom_set,
diff --git a/qmp.c b/qmp.c
index 53affe2..643e4bc 100644
--- a/qmp.c
+++ b/qmp.c
@@ -460,6 +460,38 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
     return ret;
 }
 
+ObjectPropertyInfoList *qmp_qom_type_prop_list(const char *typename, Error **errp)
+{
+    ObjectClass *klass;
+    ObjectPropertyInfoList *props = NULL;
+    ObjectProperty* prop;
+    ObjectPropertyIterator iter;
+
+    klass = object_class_by_name(typename);
+    if (!klass) {
+        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+                  "Object class '%s' not found", typename);
+        return NULL;
+    }
+
+    object_class_property_iter_init(&iter, klass);
+    while ((prop = object_property_iter_next(&iter))) {
+        ObjectPropertyInfoList *entry = g_new0(ObjectPropertyInfoList, 1);
+
+        if (entry)
+        {
+            entry->value = g_new0(ObjectPropertyInfo, 1);
+            entry->next = props;
+            props = entry;
+
+            entry->value->name = g_strdup(prop->name);
+            entry->value->type = g_strdup(prop->type);
+        }
+    }
+
+    return props;
+}
+
 /* Return a DevicePropertyInfo for a qdev property.
  *
  * If a qdev property with the given name does not exist, use the given default
diff --git a/qom/object.c b/qom/object.c
index 5ff97ab..cabd91d 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -994,6 +994,13 @@ ObjectProperty *object_property_find(Object *obj, const char *name,
     return NULL;
 }
 
+void object_class_property_iter_init(ObjectPropertyIterator *iter,
+                                     ObjectClass *klass)
+{
+    g_hash_table_iter_init(&iter->iter, klass->properties);
+    iter->nextclass = object_class_get_parent(klass);
+}
+
 void object_property_iter_init(ObjectPropertyIterator *iter,
                                Object *obj)
 {
-- 
1.8.3.1

             reply	other threads:[~2016-01-22 12:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-22 12:15 Valentin Rakush [this message]
2016-01-22 13:00 ` [Qemu-devel] [PATCH v4] qom, qmp, hmp, qapi: create qom-type-prop-list for class properties Daniel P. Berrange
2016-01-22 13:16 ` Denis V. Lunev
2016-01-22 19:02 ` Eric Blake
2016-01-22 20:20   ` Valentin Rakush
2016-01-25 17:43     ` Eric Blake
2016-01-26  9:08       ` Valentin Rakush

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=1453464955-1601-1-git-send-email-valentin.rakush@gmail.com \
    --to=valentin.rakush@gmail.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=asmetanin@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=lcapitulino@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 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).