From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFAh2-00080z-B1 for qemu-devel@nongnu.org; Tue, 03 Apr 2012 16:51:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFAh0-0006Ua-Ia for qemu-devel@nongnu.org; Tue, 03 Apr 2012 16:51:07 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:58879) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFAh0-0006UT-DB for qemu-devel@nongnu.org; Tue, 03 Apr 2012 16:51:06 -0400 Received: by obbup19 with SMTP id up19so178987obb.4 for ; Tue, 03 Apr 2012 13:51:04 -0700 (PDT) Message-ID: <4F7B62B6.5030704@codemonkey.ws> Date: Tue, 03 Apr 2012 15:51:02 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1333451753-3550-1-git-send-email-pbonzini@redhat.com> <1333451753-3550-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1333451753-3550-3-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 02/25] qom: add object_child_foreach List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, afaerber@suse.de On 04/03/2012 06:15 AM, Paolo Bonzini wrote: > A utility function that will be used to implement hierarchical realization. > > Signed-off-by: Paolo Bonzini Reviewed-by: Anthony Liguori Regards, Anthony Liguori > --- > include/qemu/object.h | 14 +++++++++++++- > qom/object.c | 17 +++++++++++++++++ > 2 files changed, 30 insertions(+), 1 deletion(-) > > diff --git a/include/qemu/object.h b/include/qemu/object.h > index f814521..470efe3 100644 > --- a/include/qemu/object.h > +++ b/include/qemu/object.h > @@ -918,6 +918,19 @@ 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. Return 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: > * @path: path to the container > * > @@ -928,5 +941,4 @@ void object_property_add_str(Object *obj, const char *name, > */ > Object *container_get(const char *path); > > - > #endif > diff --git a/qom/object.c b/qom/object.c > index 3e9fed7..4975d93 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -597,6 +597,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 (strstart(prop->type, "child<", NULL)) { > + 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;