From patchwork Thu Jul 16 20:11:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 51204 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E22F922A8A for ; Thu, 16 Jul 2015 20:11:24 +0000 (UTC) Received: by lagw2 with SMTP id w2sf21268843lag.3 for ; Thu, 16 Jul 2015 13:11:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=MXsAu3+kEAR1DL/dJ8uTLO4OHuuVdnvRJEZqri369kk=; b=U1Iz825X8qpwWxv1gQLl1U/mXE86Pam1DJ10wv7OKdeH95ebrtmzpcx9GTDpi3eyUB JGyYWxQx65qxF6swHx7VLDNt0V5mkZdVbKIkRSOKSLRYXWqytmwdrAPOn12lJ8726+Ye 6oDfT8BtAPm9naGZe9jdQOsnD3ItwdltKO1gm0UkoaeyhvEPUcCppVkVLIU1t2Gzwzgu HQ/D2JIjwAP5XI3mLIOFV4btiFOwx1FhSzFWeW+nsE0YGr7y6EKI/bln+g9Iw2x0sj/C a633KyXy1jYhpkTUZJwG2RhRrytjEpL3kvT06KjgIXv6YOGr4rolt2a4qaCGH30lno7+ bv5w== X-Gm-Message-State: ALoCoQkaiVhwF2MQGSz8Dh4JqEmsdjNl87zot3pVyuraBdxMXB+pJX6xiHhyRjCr28x2YhxcVazn X-Received: by 10.112.54.166 with SMTP id k6mr5658657lbp.0.1437077483737; Thu, 16 Jul 2015 13:11:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.181.34 with SMTP id dt2ls391249lac.14.gmail; Thu, 16 Jul 2015 13:11:23 -0700 (PDT) X-Received: by 10.112.55.70 with SMTP id q6mr9767321lbp.99.1437077483520; Thu, 16 Jul 2015 13:11:23 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id ql5si7854974lbb.165.2015.07.16.13.11.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jul 2015 13:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by lagx9 with SMTP id x9so49955925lag.1 for ; Thu, 16 Jul 2015 13:11:23 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr11301375lbb.56.1437077483239; Thu, 16 Jul 2015 13:11:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp474392lbb; Thu, 16 Jul 2015 13:11:21 -0700 (PDT) X-Received: by 10.70.92.138 with SMTP id cm10mr22264879pdb.63.1437077481256; Thu, 16 Jul 2015 13:11:21 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id hs11si14740198pdb.178.2015.07.16.13.11.19 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 16 Jul 2015 13:11:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZFpUv-0001Bd-8h; Thu, 16 Jul 2015 21:11:13 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, "Edgar E. Iglesias" , Peter Crosthwaite , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [PATCH v2 1/6] qom: Add recursive version of object_child_for_each Date: Thu, 16 Jul 2015 21:11:08 +0100 Message-Id: <1437077473-4532-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437077473-4532-1-git-send-email-peter.maydell@linaro.org> References: <1437077473-4532-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Peter Crosthwaite Useful for iterating through an entire QOM subtree. Signed-off-by: Peter Crosthwaite Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- include/qom/object.h | 15 +++++++++++++++ qom/object.c | 25 ++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 807978e..be7280c 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1494,6 +1494,21 @@ 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() * @path: path to the container diff --git a/qom/object.c b/qom/object.c index eea8edf..b7b05d3 100644 --- a/qom/object.c +++ b/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;