From patchwork Tue Sep 8 16:51:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 53295 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id D8DBE22A09 for ; Tue, 8 Sep 2015 20:38:23 +0000 (UTC) Received: by lbbmp1 with SMTP id mp1sf40406781lbb.2 for ; Tue, 08 Sep 2015 13:38:22 -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:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=ueTEVLyhKH2YdcKX2uZfFieC409em1S4B8umQgNyuYM=; b=dXiL/H9gZFfckuEAhB277+tjqYc9tfRwuFjASEB2inYZIabi7Q77xbosTecpB3uCgO rH08qLj+AWyCMfO0LEyiAB8F578iizkiqHOsFlPwo/GQrRwI7jUq9cSkKQxYLckAxcYV UB3xt48l1OG2oUFydYwHlrZkJuDx9B2LMzafl0XpkanfvnUiUr9/3kYPXSwMeEqA37f/ 1V3yaHUfm1Zu6PMWsoGBdrRmTdR4U1MVjpCsuDdEYjFd8tpfIC+ZHmod3yEIh92HvArY +02GRo54YRUygwA17K8K+so1Ml85TuV/+D0mObeGheRVmLrCnPVALVAG205NJXuyLgxl ditg== X-Gm-Message-State: ALoCoQkHmn0q3w1ilS3jgtkU5L0BbiztE+zubd+DOxzxsMqtF+zIqb6x3fuj6siZurZ1dxjkeN2D X-Received: by 10.112.57.194 with SMTP id k2mr7125686lbq.10.1441744702247; Tue, 08 Sep 2015 13:38:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.180.75 with SMTP id dm11ls276805lac.102.gmail; Tue, 08 Sep 2015 13:38:21 -0700 (PDT) X-Received: by 10.112.167.202 with SMTP id zq10mr24922915lbb.69.1441744701949; Tue, 08 Sep 2015 13:38:21 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id yp3si4439956lbb.43.2015.09.08.13.38.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2015 13:38:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by lagj9 with SMTP id j9so78413550lag.2 for ; Tue, 08 Sep 2015 13:38:21 -0700 (PDT) X-Received: by 10.152.18.133 with SMTP id w5mr14871824lad.72.1441744701851; Tue, 08 Sep 2015 13:38:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1203719lbq; Tue, 8 Sep 2015 13:38:20 -0700 (PDT) X-Received: by 10.140.19.43 with SMTP id 40mr37900160qgg.67.1441744700844; Tue, 08 Sep 2015 13:38:20 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 101si5346119qkt.38.2015.09.08.13.38.20 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Sep 2015 13:38:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:35799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZMAU-0006dT-2z for patch@linaro.org; Tue, 08 Sep 2015 12:54:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZM7W-0002VA-Tx for qemu-devel@nongnu.org; Tue, 08 Sep 2015 12:51:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZM7V-0007xx-PV for qemu-devel@nongnu.org; Tue, 08 Sep 2015 12:51:46 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:35049) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZM7V-0007b2-Hm for qemu-devel@nongnu.org; Tue, 08 Sep 2015 12:51:45 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZZM7I-0001hu-E1 for qemu-devel@nongnu.org; Tue, 08 Sep 2015 17:51:32 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 8 Sep 2015 17:51:18 +0100 Message-Id: <1441731092-6513-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1441731092-6513-1-git-send-email-peter.maydell@linaro.org> References: <1441731092-6513-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 06/20] qom: Add recursive version of object_child_for_each 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.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.54 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 Reviewed-by: Edgar E. Iglesias Tested-by: Edgar E. Iglesias Message-id: 1441383782-24378-2-git-send-email-peter.maydell@linaro.org --- 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;