mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
qom: Add recursive version of object_child_for_each
Useful for iterating through an entire QOM subtree. Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Tested-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Message-id: 1441383782-24378-2-git-send-email-peter.maydell@linaro.org
This commit is contained in:
parent
d5523a1365
commit
d714b8de77
2 changed files with 37 additions and 3 deletions
25
qom/object.c
25
qom/object.c
|
@ -775,23 +775,42 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
|
|||
enumerating_types = false;
|
||||
}
|
||||
|
||||
int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
|
||||
void *opaque)
|
||||
static int do_object_child_foreach(Object *obj,
|
||||
int (*fn)(Object *child, void *opaque),
|
||||
void *opaque, bool recurse)
|
||||
{
|
||||
ObjectProperty *prop, *next;
|
||||
int ret = 0;
|
||||
|
||||
QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) {
|
||||
if (object_property_is_child(prop)) {
|
||||
ret = fn(prop->opaque, opaque);
|
||||
Object *child = prop->opaque;
|
||||
|
||||
ret = fn(child, opaque);
|
||||
if (ret != 0) {
|
||||
break;
|
||||
}
|
||||
if (recurse) {
|
||||
do_object_child_foreach(child, fn, opaque, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
|
||||
void *opaque)
|
||||
{
|
||||
return do_object_child_foreach(obj, fn, opaque, false);
|
||||
}
|
||||
|
||||
int object_child_foreach_recursive(Object *obj,
|
||||
int (*fn)(Object *child, void *opaque),
|
||||
void *opaque)
|
||||
{
|
||||
return do_object_child_foreach(obj, fn, opaque, true);
|
||||
}
|
||||
|
||||
static void object_class_get_list_tramp(ObjectClass *klass, void *opaque)
|
||||
{
|
||||
GSList **list = opaque;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue