From patchwork Wed Apr 11 21:30:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 151887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BDCBDB7039 for ; Thu, 12 Apr 2012 07:31:10 +1000 (EST) Received: from localhost ([::1]:58712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI588-0006rt-JE for incoming@patchwork.ozlabs.org; Wed, 11 Apr 2012 17:31:08 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI57t-0006nl-Jl for qemu-devel@nongnu.org; Wed, 11 Apr 2012 17:30:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SI57q-0002WI-FE for qemu-devel@nongnu.org; Wed, 11 Apr 2012 17:30:53 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:43940) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI57q-0002VW-65 for qemu-devel@nongnu.org; Wed, 11 Apr 2012 17:30:50 -0400 Received: by wibhm17 with SMTP id hm17so4303341wib.4 for ; Wed, 11 Apr 2012 14:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=xUM6Hz+rh8Ya3yYFC7AvaunwW0yXt7btm0JH3lXXwcc=; b=ATB65fcELJKQScLj3GTlWcooIelZwvH4l4xtDDLz8hHFLyig/r7JeO59B3oEC4JNtX ErnLVHnolB1v9R8m4dJXVQIehKzEYzJux/iH3redHkzG+91dkgblrhpqYWmJcToGGrqA zM2ousphbxPfgUXfjnXiNpodxEU22RpGZNabTq/Koe9fgtMYFKFIsafPW1NxX1Ve02VX OFRMuq4fuKA6a97sw1BzuVHJMom8vVoK9gNtj584XqprHdsHs6Qu8ZDyZv/+6W9IE72K 4PYyYhSJYj0DqKAnJKQ01eZYQ64OIYb9E3CQb8Hr+/ggnd05Z0zVI2XJmh5Ppiekyq/C gWpg== Received: by 10.216.136.131 with SMTP id w3mr14083wei.15.1334179848186; Wed, 11 Apr 2012 14:30:48 -0700 (PDT) Received: from yakj.lan (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id h8sm13849678wix.4.2012.04.11.14.30.47 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 11 Apr 2012 14:30:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2012 23:30:20 +0200 Message-Id: <1334179842-6061-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.9.3 In-Reply-To: <1334179793-5914-1-git-send-email-pbonzini@redhat.com> References: <1334179793-5914-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.169 Cc: aliguori@us.ibm.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v2 02/24] qom: add object_child_foreach X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A utility function that will be used to implement hierarchical realization. Signed-off-by: Paolo Bonzini Reviewed-by: 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;