[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/22] qom: Add object_child_foreach()
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PATCH 03/22] qom: Add object_child_foreach() |
Date: |
Mon, 18 Jun 2012 15:58:55 +0200 |
From: Paolo Bonzini <address@hidden>
A utility function that will be used to implement hierarchical realization.
Signed-off-by: Paolo Bonzini <address@hidden>
Reviewed-by: Anthony Liguori <address@hidden>
[AF: Drop unrelated whitespace change, add Returns: in documentation]
[AF: Use new object_property_is_child() helper.]
Signed-off-by: Andreas Färber <address@hidden>
---
include/qemu/object.h | 14 ++++++++++++++
qom/object.c | 17 +++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/include/qemu/object.h b/include/qemu/object.h
index 487559c..ce9e51f 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -918,6 +918,20 @@ void object_property_add_str(Object *obj, const char *name,
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()
* @path: path to the container
diff --git a/qom/object.c b/qom/object.c
index 105c649..7a70d52 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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;
--
1.7.7
- [Qemu-devel] [PULL] qom-next queue, second batch: QBus, API additions and cleanups, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 05/22] qom: Make Object a type, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 01/22] qom: Add object_class_get_parent(), Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 09/22] arm_l2x0: Rename "type" property to "cache-type", Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 03/22] qom: Add object_child_foreach(),
Andreas Färber <=
- [Qemu-devel] [PATCH 16/22] qdev: Move SysBus initialization to sysbus.c, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 20/22] qbus: Initialize in standard way, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 07/22] qom: Assert that public types have a non-NULL parent field, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 18/22] qdev: Connect busses with their parent devices, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 04/22] qom: Add class_base_init, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 08/22] m48t59: Rename "type" property to "model", Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 22/22] qom: Push error reporting to object_property_find(), Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 10/22] qdev: Push "type" property up to Object, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 06/22] qom: Drop type_register_static_alias() macro, Andreas Färber, 2012/06/18
- [Qemu-devel] [PATCH 02/22] qom: Introduce object_property_is_{child, link}(), Andreas Färber, 2012/06/18