From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:35191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVrKY-0005lx-HT for qemu-devel@nongnu.org; Wed, 30 Nov 2011 16:04:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RVrKX-0000Yv-H2 for qemu-devel@nongnu.org; Wed, 30 Nov 2011 16:04:38 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:37009 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVrKX-0000Yr-Ap for qemu-devel@nongnu.org; Wed, 30 Nov 2011 16:04:37 -0500 From: Anthony Liguori Date: Wed, 30 Nov 2011 15:03:36 -0600 Message-Id: <1322687028-29714-7-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1322687028-29714-1-git-send-email-aliguori@us.ibm.com> References: <1322687028-29714-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [PATCH 06/18] qom: add child properties (composition) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Maydell , Anthony Liguori , Stefan Hajnoczi , Jan Kiszka , Markus Armbruster , Luiz Capitulino Child properties express a relationship of composition. Signed-off-by: Anthony Liguori --- hw/qdev.c | 24 ++++++++++++++++++++++++ hw/qdev.h | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 5bffbb7..b09d22a 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -1156,6 +1156,30 @@ DeviceState *qdev_get_root(void) return qdev_root; } +static void qdev_get_child_property(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState *child = opaque; + gchar *path; + + path = qdev_get_canonical_path(child); + visit_type_str(v, &path, name, errp); + g_free(path); +} + +void qdev_property_add_child(DeviceState *dev, const char *name, + DeviceState *child, Error **errp) +{ + gchar *type; + + type = g_strdup_printf("child<%s>", child->info->name); + + qdev_property_add(dev, name, type, qdev_get_child_property, + NULL, NULL, child, errp); + + g_free(type); +} + static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev) { GSList *i; diff --git a/hw/qdev.h b/hw/qdev.h index b8b62f5..905a02c 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -499,4 +499,24 @@ gchar *qdev_get_canonical_path(DeviceState *dev); */ DeviceState *qdev_resolve_path(const char *path, bool *ambiguous); +/** + * @qdev_property_add_child - Add a child property to a device + * + * Child properties form the composition tree. All devices need to be a child + * of another device. Devices can only be a child of one device. + * + * There is no way for a child to determine what it's parent is. It is not + * a bidirectional relationship. This is by design. + * + * @dev - the device to add a property to + * + * @name - the name of the property + * + * @child - the child device + * + * @errp - if an error occurs, a pointer to an area to store the area + */ +void qdev_property_add_child(DeviceState *dev, const char *name, + DeviceState *child, Error **errp); + #endif -- 1.7.4.1