[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 007/197] qom: add child properties (composition)
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH v3 007/197] qom: add child properties (composition) (v2) |
Date: |
Mon, 12 Dec 2011 14:18:03 -0600 |
Child properties express a relationship of composition.
Signed-off-by: Anthony Liguori <address@hidden>
---
v1 -> v2
- fix comments (Kevin)
- add a reference when adding a child property (Kevin)
---
hw/qdev.c | 26 ++++++++++++++++++++++++++
hw/qdev.h | 20 ++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 2519f00..fa6b489 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1174,6 +1174,32 @@ 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);
+
+ qdev_ref(dev);
+
+ g_free(type);
+}
+
static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
{
DeviceProperty *prop;
diff --git a/hw/qdev.h b/hw/qdev.h
index 641d134..38b36e8 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -527,4 +527,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 its 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 v3 000/197] qom: dynamic properties and composition tree (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 003/197] qom: register legacy properties as new style properties (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 002/197] qom: add new dynamic property infrastructure based on Visitors (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 005/197] qdev: provide an interface to return canonical path from root (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 006/197] qdev: provide a path resolution (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 007/197] qom: add child properties (composition) (v2),
Anthony Liguori <=
- [Qemu-devel] [PATCH v3 008/197] qom: add link properties (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 009/197] qapi: allow a 'gen' key to suppress code generation, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 010/197] qmp: add qom-list command, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 011/197] qom: qom_{get, set} monitor commands (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 015/197] rtc: add a dynamic property for retrieving the date, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 016/197] qom: optimize qdev_get_canonical_path using a parent link, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 017/197] qmp: make qmp.py easier to use, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 018/197] qom: add test tools (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 020/197] qom: add vga node to the pc composition tree, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 021/197] qom: add string property type, Anthony Liguori, 2011/12/12