From patchwork Tue May 1 18:18:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 156172 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 CE523B6FAB for ; Wed, 2 May 2012 04:40:01 +1000 (EST) Received: from localhost ([::1]:41897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPHzT-0007mS-CR for incoming@patchwork.ozlabs.org; Tue, 01 May 2012 14:39:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPHzF-0007fX-65 for qemu-devel@nongnu.org; Tue, 01 May 2012 14:39:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SPHzD-0001yg-Iw for qemu-devel@nongnu.org; Tue, 01 May 2012 14:39:44 -0400 Received: from [159.125.79.200] (port=22234 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPHzD-0001xt-Et for qemu-devel@nongnu.org; Tue, 01 May 2012 14:39:43 -0400 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id q41IIQmO009928; Tue, 1 May 2012 13:18:26 -0500 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q41IIOYV009902; Tue, 1 May 2012 13:18:24 -0500 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Tue, 1 May 2012 13:18:02 -0500 Message-Id: <1335896294-9530-3-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1335896294-9530-1-git-send-email-aliguori@us.ibm.com> References: <1335896294-9530-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 159.125.79.200 Cc: Peter Maydell , Paolo Bonzini , Anthony Liguori , Andreas Faerber , Wanpeng Li Subject: [Qemu-devel] [PATCH 02/14] object: add object_property_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 Provide a mechanism to walk through each property for an object. Signed-off-by: Anthony Liguori Reviewed-by: Andreas Färber --- include/qemu/object.h | 26 ++++++++++++++++++++++++++ qom/object.c | 10 ++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/include/qemu/object.h b/include/qemu/object.h index ca1649c..4ad6758 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -915,5 +915,31 @@ void object_property_add_str(Object *obj, const char *name, */ Object *container_get(Object *root, const char *path); +/** + * ObjectPropertyEnumerator: + * @obj: the object the property belongs to + * @name: the name of the property + * @typename: the string typename the property was created with + * @read_only: if #true, the property is read-only + * @opaque: the opaque handle passed to @object_property_foreach + * + * Callback function type for @object_property_foreach + */ +typedef void (ObjectPropertyEnumerator)(Object *obj, + const char *name, + const char *typename, + bool read_only, + void *opaque); + +/** + * object_property_foreach: + * @path: object to enumerate properties in + * @fn: callback function that will be invoked for each property + * @opaque: opaque to pass to @fn + * + * Enumerate all properties in an existing object. + */ +void object_property_foreach(Object *obj, ObjectPropertyEnumerator *fn, + void *opaque); #endif diff --git a/qom/object.c b/qom/object.c index e721fc2..94928c5 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1194,3 +1194,13 @@ void object_property_add_str(Object *obj, const char *name, property_release_str, prop, errp); } + +void object_property_foreach(Object *obj, ObjectPropertyEnumerator *fn, + void *opaque) +{ + ObjectProperty *prop; + + QTAILQ_FOREACH(prop, &obj->properties, node) { + fn(obj, prop->name, prop->type, !prop->set, opaque); + } +}