[Qemu-devel] [PATCH 02/14] object: add object_property_foreach

2012-05-01 Thread Anthony Liguori
Provide a mechanism to walk through each property for an object.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com
---
 include/qemu/object.h |   26 ++
 qom/object.c  |   10 ++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/include/qemu/object.h b/include/qemu/object.h
index ca1649c..4ad6758 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -915,5 +915,31 @@ void object_property_add_str(Object *obj, const char *name,
  */
 Object *container_get(Object *root, const char *path);
 
+/**
+ * ObjectPropertyEnumerator:
+ * @obj: the object the property belongs to
+ * @name: the name of the property
+ * @typename: the string typename the property was created with
+ * @read_only: if #true, the property is read-only
+ * @opaque: the opaque handle passed to @object_property_foreach
+ *
+ * Callback function type for @object_property_foreach
+ */
+typedef void (ObjectPropertyEnumerator)(Object *obj,
+const char *name,
+const char *typename,
+bool read_only,
+void *opaque);
+
+/**
+ * object_property_foreach:
+ * @path: object to enumerate properties in
+ * @fn: callback function that will be invoked for each property
+ * @opaque: opaque to pass to @fn
+ *
+ * Enumerate all properties in an existing object.
+ */
+void object_property_foreach(Object *obj, ObjectPropertyEnumerator *fn,
+ void *opaque);
 
 #endif
diff --git a/qom/object.c b/qom/object.c
index e721fc2..94928c5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1194,3 +1194,13 @@ void object_property_add_str(Object *obj, const char 
*name,
 property_release_str,
 prop, errp);
 }
+
+void object_property_foreach(Object *obj, ObjectPropertyEnumerator *fn,
+ void *opaque)
+{
+ObjectProperty *prop;
+
+QTAILQ_FOREACH(prop, obj-properties, node) {
+fn(obj, prop-name, prop-type, !prop-set, opaque);
+}
+}
-- 
1.7.5.4




Re: [Qemu-devel] [PATCH 02/14] object: add object_property_foreach

2012-05-01 Thread Andreas Färber
Am 01.05.2012 20:18, schrieb Anthony Liguori:
 Provide a mechanism to walk through each property for an object.
 
 Signed-off-by: Anthony Liguori aligu...@us.ibm.com

Reviewed-by: Andreas Färber afaer...@suse.de

/-F

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



[Qemu-devel] [PATCH 02/14] object: add object_property_foreach

2012-04-18 Thread Anthony Liguori
Provide a mechanism to walk through each property for an object.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com
---
 include/qemu/object.h |   26 ++
 qom/object.c  |   10 ++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/include/qemu/object.h b/include/qemu/object.h
index a675937..e580197 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -914,5 +914,31 @@ void object_property_add_str(Object *obj, const char *name,
  */
 Object *container_get(const char *path);
 
+/**
+ * ObjectPropertyEnumerator:
+ * @obj: the object the property belongs to
+ * @name: the name of the property
+ * @typename: the string typename the property was created with
+ * @read_only: if #true, the property is read-only
+ * @opaque: the opaque handle passed to @object_property_foreach
+ *
+ * Callback function type for @object_property_foreach
+ */
+typedef void (ObjectPropertyEnumerator)(Object *obj,
+const char *name,
+const char *typename,
+bool read_only,
+void *opaque);
+
+/**
+ * object_property_foreach:
+ * @path: object to enumerate properties in
+ * @fn: callback function that will be invoked for each property
+ * @opaque: opaque to pass to @fn
+ *
+ * Enumerate all properties in an existing object.
+ */
+void object_property_foreach(Object *obj, ObjectPropertyEnumerator *fn,
+ void *opaque);
 
 #endif
diff --git a/qom/object.c b/qom/object.c
index e721fc2..94928c5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1194,3 +1194,13 @@ void object_property_add_str(Object *obj, const char 
*name,
 property_release_str,
 prop, errp);
 }
+
+void object_property_foreach(Object *obj, ObjectPropertyEnumerator *fn,
+ void *opaque)
+{
+ObjectProperty *prop;
+
+QTAILQ_FOREACH(prop, obj-properties, node) {
+fn(obj, prop-name, prop-type, !prop-set, opaque);
+}
+}
-- 
1.7.5.4