]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qom: Add object_child_foreach()
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 11 Apr 2012 21:30:20 +0000 (23:30 +0200)
committerAndreas Färber <afaerber@suse.de>
Mon, 18 Jun 2012 13:14:36 +0000 (15:14 +0200)
A utility function that will be used to implement hierarchical realization.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
[AF: Drop unrelated whitespace change, add Returns: in documentation]
[AF: Use new object_property_is_child() helper.]
Signed-off-by: Andreas Färber <afaerber@suse.de>
include/qemu/object.h
qom/object.c

index 487559c5c0192817190035d44de12630bcbd11fc..ce9e51f2aee650e61d80e9ad824645f64bae32f7 100644 (file)
@@ -917,6 +917,20 @@ void object_property_add_str(Object *obj, const char *name,
                              void (*set)(Object *, const char *, struct Error **),
                              struct Error **errp);
 
+/**
+ * object_child_foreach:
+ * @obj: the object whose children will be navigated
+ * @fn: the iterator function to be called
+ * @opaque: an opaque value that will be passed to the iterator
+ *
+ * Call @fn passing each child of @obj and @opaque to it, until @fn returns
+ * non-zero.
+ *
+ * Returns: The last value returned by @fn, or 0 if there is no child.
+ */
+int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
+                         void *opaque);
+
 /**
  * container_get:
  * @root: root of the #path, e.g., object_get_root()
index 105c649e8de0870c9a22eabef2ae333e2fab9c2f..7a70d52e3ad9626a6a3adba1547dac699bc76e64 100644 (file)
@@ -607,6 +607,23 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
     g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &data);
 }
 
+int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
+                         void *opaque)
+{
+    ObjectProperty *prop;
+    int ret = 0;
+
+    QTAILQ_FOREACH(prop, &obj->properties, node) {
+        if (object_property_is_child(prop)) {
+            ret = fn(prop->opaque, opaque);
+            if (ret != 0) {
+                break;
+            }
+        }
+    }
+    return ret;
+}
+
 static void object_class_get_list_tramp(ObjectClass *klass, void *opaque)
 {
     GSList **list = opaque;