From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Pavel Fedin" <p.fedin@samsung.com>, "Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH v3 2/5] qmp: convert to use object_property_foreach iterators
Date: Thu, 8 Oct 2015 15:09:01 +0100 [thread overview]
Message-ID: <1444313344-16196-3-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1444313344-16196-1-git-send-email-berrange@redhat.com>
Rather than directly traversing the object property list,
use the object_property_foreach iterator. This removes a
dependancy on the implementation approach for properties.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
qmp.c | 103 ++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 59 insertions(+), 44 deletions(-)
diff --git a/qmp.c b/qmp.c
index 057a7cb..9baad84 100644
--- a/qmp.c
+++ b/qmp.c
@@ -202,12 +202,29 @@ void qmp_system_wakeup(Error **errp)
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
}
+
+static void qmp_qom_list_iter(Object *obj,
+ ObjectProperty *prop,
+ Error **errp,
+ void *opaque)
+{
+ ObjectPropertyInfoList **props = opaque;
+
+ ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
+
+ entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
+ entry->next = *props;
+ *props = entry;
+
+ entry->value->name = g_strdup(prop->name);
+ entry->value->type = g_strdup(prop->type);
+}
+
ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
{
Object *obj;
bool ambiguous = false;
ObjectPropertyInfoList *props = NULL;
- ObjectProperty *prop;
obj = object_resolve_path(path, &ambiguous);
if (obj == NULL) {
@@ -220,17 +237,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
return NULL;
}
- QTAILQ_FOREACH(prop, &obj->properties, node) {
- ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
-
- entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
- entry->next = props;
- props = entry;
-
- entry->value->name = g_strdup(prop->name);
- entry->value->type = g_strdup(prop->type);
- }
-
+ object_property_foreach(obj, qmp_qom_list_iter, NULL, &props);
return props;
}
@@ -494,12 +501,49 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
return info;
}
+static void qmp_device_list_properties_iter(Object *obj,
+ ObjectProperty *prop,
+ Error **errp,
+ void *opaque)
+{
+ DevicePropertyInfoList **props = opaque;
+ DevicePropertyInfo *info;
+ DevicePropertyInfoList *entry;
+
+ /* Skip Object and DeviceState properties */
+ if (strcmp(prop->name, "type") == 0 ||
+ strcmp(prop->name, "realized") == 0 ||
+ strcmp(prop->name, "hotpluggable") == 0 ||
+ strcmp(prop->name, "hotplugged") == 0 ||
+ strcmp(prop->name, "parent_bus") == 0) {
+ return;
+ }
+
+ /* Skip legacy properties since they are just string versions of
+ * properties that we already list.
+ */
+ if (strstart(prop->name, "legacy-", NULL)) {
+ return;
+ }
+
+ info = make_device_property_info(object_get_class(obj),
+ prop->name, prop->type,
+ prop->description);
+ if (!info) {
+ return;
+ }
+
+ entry = g_malloc0(sizeof(*entry));
+ entry->value = info;
+ entry->next = *props;
+ *props = entry;
+}
+
DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
Error **errp)
{
ObjectClass *klass;
Object *obj;
- ObjectProperty *prop;
DevicePropertyInfoList *prop_list = NULL;
klass = object_class_by_name(typename);
@@ -517,37 +561,8 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
obj = object_new(typename);
- QTAILQ_FOREACH(prop, &obj->properties, node) {
- DevicePropertyInfo *info;
- DevicePropertyInfoList *entry;
-
- /* Skip Object and DeviceState properties */
- if (strcmp(prop->name, "type") == 0 ||
- strcmp(prop->name, "realized") == 0 ||
- strcmp(prop->name, "hotpluggable") == 0 ||
- strcmp(prop->name, "hotplugged") == 0 ||
- strcmp(prop->name, "parent_bus") == 0) {
- continue;
- }
-
- /* Skip legacy properties since they are just string versions of
- * properties that we already list.
- */
- if (strstart(prop->name, "legacy-", NULL)) {
- continue;
- }
-
- info = make_device_property_info(klass, prop->name, prop->type,
- prop->description);
- if (!info) {
- continue;
- }
-
- entry = g_malloc0(sizeof(*entry));
- entry->value = info;
- entry->next = prop_list;
- prop_list = entry;
- }
+ object_property_foreach(obj, qmp_device_list_properties_iter,
+ NULL, &prop_list);
object_unref(obj);
--
2.4.3
next prev parent reply other threads:[~2015-10-08 14:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-08 14:08 [Qemu-devel] [PATCH v3 0/5] qom: more efficient object property handling Daniel P. Berrange
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 1/5] qom: introduce object_property_foreach method Daniel P. Berrange
2015-10-08 16:29 ` Eric Blake
2015-10-09 8:31 ` [Qemu-devel] Stick to loops (was: [PATCH v3 1/5] qom: introduce object_property_foreach method) Markus Armbruster
2015-10-12 10:00 ` Daniel P. Berrange
2015-10-12 10:24 ` [Qemu-devel] Stick to loops Paolo Bonzini
2015-10-12 11:56 ` Markus Armbruster
2015-10-13 12:09 ` [Qemu-devel] Stick to loops (was: [PATCH v3 1/5] qom: introduce object_property_foreach method) Daniel P. Berrange
2015-10-08 14:09 ` Daniel P. Berrange [this message]
2015-10-08 16:35 ` [Qemu-devel] [PATCH v3 2/5] qmp: convert to use object_property_foreach iterators Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 3/5] vl: convert machine help to use object_property_foreach Daniel P. Berrange
2015-10-08 19:06 ` Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 4/5] qom: replace object property list with GHashTable Daniel P. Berrange
2015-10-08 15:05 ` Pavel Fedin
2015-10-08 19:13 ` Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 5/5] qom: allow properties to be registered against classes Daniel P. Berrange
2015-10-08 19:35 ` Eric Blake
2015-10-08 15:12 ` [Qemu-devel] [PATCH v3 0/5] qom: more efficient object property handling Eric Blake
2015-10-08 15:27 ` Pavel Fedin
2015-10-08 15:48 ` Daniel P. Berrange
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=1444313344-16196-3-git-send-email-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=afaerber@suse.de \
--cc=p.fedin@samsung.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).