[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 06/18] qom: add child properties (composition)
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 06/18] qom: add child properties (composition) |
Date: |
Wed, 30 Nov 2011 15:03:36 -0600 |
Child properties express a relationship of composition.
Signed-off-by: Anthony Liguori <address@hidden>
---
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
- [Qemu-devel] [PATCH 00/18] qom: dynamic properties and composition tree, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 03/18] qom: introduce root device, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 04/18] qdev: provide an interface to return canonical path from root, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 05/18] qdev: provide a path resolution, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 01/18] qom: add new dynamic property infrastructure based on Visitors, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 07/18] qom: add link properties, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 06/18] qom: add child properties (composition),
Anthony Liguori <=
- [Qemu-devel] [PATCH 02/18] qom: register legacy properties as new style properties, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 08/18] qapi: allow a 'gen' key to suppress code generation, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 10/18] qom: qom_{get,set} monitor commands, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 11/18] qdev: add explicitly named devices to the root complex, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 17/18] Add test tools, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 16/18] Make qmp.py easier to use, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 18/18] qdev: split out QOM functions to separate files, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 13/18] rtc: make piix3 set the rtc as a child, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 09/18] qmp: add qom-list command, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 15/18] qom: optimize qdev_get_canonical_path using a parent link, Anthony Liguori, 2011/11/30