qom: Add recursive version of object_child_for_each

Useful for iterating through an entire QOM subtree.

Backports commit d714b8de7747f20fe42e5716d1d44f91e2b891f4 from qemu
This commit is contained in:
Peter Crosthwaite 2018-02-15 11:13:21 -05:00 committed by Lioncash
parent e08c524068
commit a249923d4d
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
16 changed files with 52 additions and 55 deletions

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_aarch64
#define not_v8_cp_reginfo not_v8_cp_reginfo_aarch64
#define object_child_foreach object_child_foreach_aarch64
#define object_child_foreach_recursive object_child_foreach_recursive_aarch64
#define object_class_foreach object_class_foreach_aarch64
#define object_class_foreach_tramp object_class_foreach_tramp_aarch64
#define object_class_get_list object_class_get_list_aarch64
@ -2582,10 +2583,6 @@
#define save_globals save_globals_aarch64
#define scr_write scr_write_aarch64
#define sctlr_write sctlr_write_aarch64
#define semihosting_get_target semihosting_get_target_aarch64
#define semihosting_get_arg semihosting_get_arg_aarch64
#define semihosting_get_argc semihosting_get_argc_aarch64
#define semihosting_get_cmdline semihosting_get_cmdline_aarch64
#define set_bit set_bit_aarch64
#define set_bits set_bits_aarch64
#define set_default_nan_mode set_default_nan_mode_aarch64

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_aarch64eb
#define not_v8_cp_reginfo not_v8_cp_reginfo_aarch64eb
#define object_child_foreach object_child_foreach_aarch64eb
#define object_child_foreach_recursive object_child_foreach_recursive_aarch64eb
#define object_class_foreach object_class_foreach_aarch64eb
#define object_class_foreach_tramp object_class_foreach_tramp_aarch64eb
#define object_class_get_list object_class_get_list_aarch64eb
@ -2582,10 +2583,6 @@
#define save_globals save_globals_aarch64eb
#define scr_write scr_write_aarch64eb
#define sctlr_write sctlr_write_aarch64eb
#define semihosting_get_target semihosting_get_target_aarch64eb
#define semihosting_get_arg semihosting_get_arg_aarch64eb
#define semihosting_get_argc semihosting_get_argc_aarch64eb
#define semihosting_get_cmdline semihosting_get_cmdline_aarch64eb
#define set_bit set_bit_aarch64eb
#define set_bits set_bits_aarch64eb
#define set_default_nan_mode set_default_nan_mode_aarch64eb

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_arm
#define not_v8_cp_reginfo not_v8_cp_reginfo_arm
#define object_child_foreach object_child_foreach_arm
#define object_child_foreach_recursive object_child_foreach_recursive_arm
#define object_class_foreach object_class_foreach_arm
#define object_class_foreach_tramp object_class_foreach_tramp_arm
#define object_class_get_list object_class_get_list_arm
@ -2582,10 +2583,6 @@
#define save_globals save_globals_arm
#define scr_write scr_write_arm
#define sctlr_write sctlr_write_arm
#define semihosting_get_target semihosting_get_target_arm
#define semihosting_get_arg semihosting_get_arg_arm
#define semihosting_get_argc semihosting_get_argc_arm
#define semihosting_get_cmdline semihosting_get_cmdline_arm
#define set_bit set_bit_arm
#define set_bits set_bits_arm
#define set_default_nan_mode set_default_nan_mode_arm

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_armeb
#define not_v8_cp_reginfo not_v8_cp_reginfo_armeb
#define object_child_foreach object_child_foreach_armeb
#define object_child_foreach_recursive object_child_foreach_recursive_armeb
#define object_class_foreach object_class_foreach_armeb
#define object_class_foreach_tramp object_class_foreach_tramp_armeb
#define object_class_get_list object_class_get_list_armeb
@ -2582,10 +2583,6 @@
#define save_globals save_globals_armeb
#define scr_write scr_write_armeb
#define sctlr_write sctlr_write_armeb
#define semihosting_get_target semihosting_get_target_armeb
#define semihosting_get_arg semihosting_get_arg_armeb
#define semihosting_get_argc semihosting_get_argc_armeb
#define semihosting_get_cmdline semihosting_get_cmdline_armeb
#define set_bit set_bit_armeb
#define set_bits set_bits_armeb
#define set_default_nan_mode set_default_nan_mode_armeb

View file

@ -2162,6 +2162,7 @@ symbols = (
'not_v7_cp_reginfo',
'not_v8_cp_reginfo',
'object_child_foreach',
'object_child_foreach_recursive',
'object_class_foreach',
'object_class_foreach_tramp',
'object_class_get_list',

View file

@ -1251,6 +1251,22 @@ void object_property_set_description(Object *obj, const char *name,
int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
void *opaque);
/**
* object_child_foreach_recursive:
* @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. Calls recursively, all child nodes of @obj will also be passed
* all the way down to the leaf nodes of the tree. Depth first ordering.
*
* Returns: The last value returned by @fn, or 0 if there is no child.
*/
int object_child_foreach_recursive(Object *obj,
int (*fn)(Object *child, void *opaque),
void *opaque);
/**
* container_get:
* @root: root of the #path, e.g., object_get_root()

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_m68k
#define not_v8_cp_reginfo not_v8_cp_reginfo_m68k
#define object_child_foreach object_child_foreach_m68k
#define object_child_foreach_recursive object_child_foreach_recursive_m68k
#define object_class_foreach object_class_foreach_m68k
#define object_class_foreach_tramp object_class_foreach_tramp_m68k
#define object_class_get_list object_class_get_list_m68k
@ -2582,10 +2583,6 @@
#define save_globals save_globals_m68k
#define scr_write scr_write_m68k
#define sctlr_write sctlr_write_m68k
#define semihosting_get_target semihosting_get_target_m68k
#define semihosting_get_arg semihosting_get_arg_m68k
#define semihosting_get_argc semihosting_get_argc_m68k
#define semihosting_get_cmdline semihosting_get_cmdline_m68k
#define set_bit set_bit_m68k
#define set_bits set_bits_m68k
#define set_default_nan_mode set_default_nan_mode_m68k

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_mips
#define not_v8_cp_reginfo not_v8_cp_reginfo_mips
#define object_child_foreach object_child_foreach_mips
#define object_child_foreach_recursive object_child_foreach_recursive_mips
#define object_class_foreach object_class_foreach_mips
#define object_class_foreach_tramp object_class_foreach_tramp_mips
#define object_class_get_list object_class_get_list_mips
@ -2582,10 +2583,6 @@
#define save_globals save_globals_mips
#define scr_write scr_write_mips
#define sctlr_write sctlr_write_mips
#define semihosting_get_target semihosting_get_target_mips
#define semihosting_get_arg semihosting_get_arg_mips
#define semihosting_get_argc semihosting_get_argc_mips
#define semihosting_get_cmdline semihosting_get_cmdline_mips
#define set_bit set_bit_mips
#define set_bits set_bits_mips
#define set_default_nan_mode set_default_nan_mode_mips

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_mips64
#define not_v8_cp_reginfo not_v8_cp_reginfo_mips64
#define object_child_foreach object_child_foreach_mips64
#define object_child_foreach_recursive object_child_foreach_recursive_mips64
#define object_class_foreach object_class_foreach_mips64
#define object_class_foreach_tramp object_class_foreach_tramp_mips64
#define object_class_get_list object_class_get_list_mips64
@ -2582,10 +2583,6 @@
#define save_globals save_globals_mips64
#define scr_write scr_write_mips64
#define sctlr_write sctlr_write_mips64
#define semihosting_get_target semihosting_get_target_mips64
#define semihosting_get_arg semihosting_get_arg_mips64
#define semihosting_get_argc semihosting_get_argc_mips64
#define semihosting_get_cmdline semihosting_get_cmdline_mips64
#define set_bit set_bit_mips64
#define set_bits set_bits_mips64
#define set_default_nan_mode set_default_nan_mode_mips64

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_mips64el
#define not_v8_cp_reginfo not_v8_cp_reginfo_mips64el
#define object_child_foreach object_child_foreach_mips64el
#define object_child_foreach_recursive object_child_foreach_recursive_mips64el
#define object_class_foreach object_class_foreach_mips64el
#define object_class_foreach_tramp object_class_foreach_tramp_mips64el
#define object_class_get_list object_class_get_list_mips64el
@ -2582,10 +2583,6 @@
#define save_globals save_globals_mips64el
#define scr_write scr_write_mips64el
#define sctlr_write sctlr_write_mips64el
#define semihosting_get_target semihosting_get_target_mips64el
#define semihosting_get_arg semihosting_get_arg_mips64el
#define semihosting_get_argc semihosting_get_argc_mips64el
#define semihosting_get_cmdline semihosting_get_cmdline_mips64el
#define set_bit set_bit_mips64el
#define set_bits set_bits_mips64el
#define set_default_nan_mode set_default_nan_mode_mips64el

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_mipsel
#define not_v8_cp_reginfo not_v8_cp_reginfo_mipsel
#define object_child_foreach object_child_foreach_mipsel
#define object_child_foreach_recursive object_child_foreach_recursive_mipsel
#define object_class_foreach object_class_foreach_mipsel
#define object_class_foreach_tramp object_class_foreach_tramp_mipsel
#define object_class_get_list object_class_get_list_mipsel
@ -2582,10 +2583,6 @@
#define save_globals save_globals_mipsel
#define scr_write scr_write_mipsel
#define sctlr_write sctlr_write_mipsel
#define semihosting_get_target semihosting_get_target_mipsel
#define semihosting_get_arg semihosting_get_arg_mipsel
#define semihosting_get_argc semihosting_get_argc_mipsel
#define semihosting_get_cmdline semihosting_get_cmdline_mipsel
#define set_bit set_bit_mipsel
#define set_bits set_bits_mipsel
#define set_default_nan_mode set_default_nan_mode_mipsel

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_powerpc
#define not_v8_cp_reginfo not_v8_cp_reginfo_powerpc
#define object_child_foreach object_child_foreach_powerpc
#define object_child_foreach_recursive object_child_foreach_recursive_powerpc
#define object_class_foreach object_class_foreach_powerpc
#define object_class_foreach_tramp object_class_foreach_tramp_powerpc
#define object_class_get_list object_class_get_list_powerpc
@ -2582,10 +2583,6 @@
#define save_globals save_globals_powerpc
#define scr_write scr_write_powerpc
#define sctlr_write sctlr_write_powerpc
#define semihosting_get_target semihosting_get_target_powerpc
#define semihosting_get_arg semihosting_get_arg_powerpc
#define semihosting_get_argc semihosting_get_argc_powerpc
#define semihosting_get_cmdline semihosting_get_cmdline_powerpc
#define set_bit set_bit_powerpc
#define set_bits set_bits_powerpc
#define set_default_nan_mode set_default_nan_mode_powerpc

View file

@ -657,23 +657,42 @@ void object_class_foreach(struct uc_struct *uc, void (*fn)(ObjectClass *klass, v
uc->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;

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_sparc
#define not_v8_cp_reginfo not_v8_cp_reginfo_sparc
#define object_child_foreach object_child_foreach_sparc
#define object_child_foreach_recursive object_child_foreach_recursive_sparc
#define object_class_foreach object_class_foreach_sparc
#define object_class_foreach_tramp object_class_foreach_tramp_sparc
#define object_class_get_list object_class_get_list_sparc
@ -2582,10 +2583,6 @@
#define save_globals save_globals_sparc
#define scr_write scr_write_sparc
#define sctlr_write sctlr_write_sparc
#define semihosting_get_target semihosting_get_target_sparc
#define semihosting_get_arg semihosting_get_arg_sparc
#define semihosting_get_argc semihosting_get_argc_sparc
#define semihosting_get_cmdline semihosting_get_cmdline_sparc
#define set_bit set_bit_sparc
#define set_bits set_bits_sparc
#define set_default_nan_mode set_default_nan_mode_sparc

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_sparc64
#define not_v8_cp_reginfo not_v8_cp_reginfo_sparc64
#define object_child_foreach object_child_foreach_sparc64
#define object_child_foreach_recursive object_child_foreach_recursive_sparc64
#define object_class_foreach object_class_foreach_sparc64
#define object_class_foreach_tramp object_class_foreach_tramp_sparc64
#define object_class_get_list object_class_get_list_sparc64
@ -2582,10 +2583,6 @@
#define save_globals save_globals_sparc64
#define scr_write scr_write_sparc64
#define sctlr_write sctlr_write_sparc64
#define semihosting_get_target semihosting_get_target_sparc64
#define semihosting_get_arg semihosting_get_arg_sparc64
#define semihosting_get_argc semihosting_get_argc_sparc64
#define semihosting_get_cmdline semihosting_get_cmdline_sparc64
#define set_bit set_bit_sparc64
#define set_bits set_bits_sparc64
#define set_default_nan_mode set_default_nan_mode_sparc64

View file

@ -2156,6 +2156,7 @@
#define not_v7_cp_reginfo not_v7_cp_reginfo_x86_64
#define not_v8_cp_reginfo not_v8_cp_reginfo_x86_64
#define object_child_foreach object_child_foreach_x86_64
#define object_child_foreach_recursive object_child_foreach_recursive_x86_64
#define object_class_foreach object_class_foreach_x86_64
#define object_class_foreach_tramp object_class_foreach_tramp_x86_64
#define object_class_get_list object_class_get_list_x86_64
@ -2582,10 +2583,6 @@
#define save_globals save_globals_x86_64
#define scr_write scr_write_x86_64
#define sctlr_write sctlr_write_x86_64
#define semihosting_get_target semihosting_get_target_x86_64
#define semihosting_get_arg semihosting_get_arg_x86_64
#define semihosting_get_argc semihosting_get_argc_x86_64
#define semihosting_get_cmdline semihosting_get_cmdline_x86_64
#define set_bit set_bit_x86_64
#define set_bits set_bits_x86_64
#define set_default_nan_mode set_default_nan_mode_x86_64