Received: from eggs.gnu.org ([208.118.235.92]:37866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUr-0001cl-2K for qemu-devel@nongnu.org; Mon, 18 Jun 2012 10:00:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SgcUS-0003VT-De for qemu-devel@nongnu.org; Mon, 18 Jun 2012 10:00:00 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53223 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUS-0003VD-3m for qemu-devel@nongnu.org; Mon, 18 Jun 2012 09:59:36 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 18 Jun 2012 15:58:55 +0200 Message-Id: <1340027954-19045-4-git-send-email-afaerber@suse.de> In-Reply-To: <1340027954-19045-1-git-send-email-afaerber@suse.de> References: <1340027954-19045-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 03/22] qom: Add object_child_foreach() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori From: Paolo Bonzini A utility function that will be used to implement hierarchical realizatio= n. Signed-off-by: Paolo Bonzini Reviewed-by: Anthony Liguori [AF: Drop unrelated whitespace change, add Returns: in documentation] [AF: Use new object_property_is_child() helper.] Signed-off-by: Andreas F=C3=A4rber --- 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); =20 /** + * 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 retu= rns + * 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 *opa= que), + 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 *kl= ass, void *opaque), g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &= data); } =20 +int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opa= que), + void *opaque) +{ + ObjectProperty *prop; + int ret =3D 0; + + QTAILQ_FOREACH(prop, &obj->properties, node) { + if (object_property_is_child(prop)) { + ret =3D fn(prop->opaque, opaque); + if (ret !=3D 0) { + break; + } + } + } + return ret; +} + static void object_class_get_list_tramp(ObjectClass *klass, void *opaque= ) { GSList **list =3D opaque; --=20 1.7.7