[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 008/197] qom: add link properties (v2)
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH v3 008/197] qom: add link properties (v2) |
Date: |
Mon, 12 Dec 2011 14:18:04 -0600 |
Links represent an ephemeral relationship between devices. They are meant to
replace the qdev concept of busses by allowing more informal relationships
between devices.
Links are fairly limited in their usefulness without implementing QOM-style
subclassing and interfaces.
Signed-off-by: Anthony Liguori <address@hidden>
---
v1 -> v2
- comments (Stefan)
- maintain a reference when adding/removing a link property (Kevin)
---
hw/qdev.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 23 +++++++++++++++++++
2 files changed, 97 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index fa6b489..42430fa 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1200,6 +1200,80 @@ void qdev_property_add_child(DeviceState *dev, const
char *name,
g_free(type);
}
+static void qdev_get_link_property(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ DeviceState **child = opaque;
+ gchar *path;
+
+ if (*child) {
+ path = qdev_get_canonical_path(*child);
+ visit_type_str(v, &path, name, errp);
+ g_free(path);
+ } else {
+ path = (gchar *)"";
+ visit_type_str(v, &path, name, errp);
+ }
+}
+
+static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ DeviceState **child = opaque;
+ bool ambiguous = false;
+ const char *type;
+ char *path;
+
+ type = qdev_property_get_type(dev, name, NULL);
+
+ visit_type_str(v, &path, name, errp);
+
+ if (*child) {
+ qdev_unref(*child);
+ }
+
+ if (strcmp(path, "") != 0) {
+ DeviceState *target;
+
+ target = qdev_resolve_path(path, &ambiguous);
+ if (target) {
+ gchar *target_type;
+
+ target_type = g_strdup_printf("link<%s>", target->info->name);
+ if (strcmp(target_type, type) == 0) {
+ *child = target;
+ qdev_ref(target);
+ } else {
+ error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, type);
+ }
+
+ g_free(target_type);
+ } else {
+ error_set(errp, QERR_DEVICE_NOT_FOUND, path);
+ }
+ } else {
+ *child = NULL;
+ }
+
+ g_free(path);
+}
+
+void qdev_property_add_link(DeviceState *dev, const char *name,
+ const char *type, DeviceState **child,
+ Error **errp)
+{
+ gchar *full_type;
+
+ full_type = g_strdup_printf("link<%s>", type);
+
+ qdev_property_add(dev, name, full_type,
+ qdev_get_link_property,
+ qdev_set_link_property,
+ NULL, child, errp);
+
+ g_free(full_type);
+}
+
static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
{
DeviceProperty *prop;
diff --git a/hw/qdev.h b/hw/qdev.h
index 38b36e8..4351e2e 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -547,4 +547,27 @@ DeviceState *qdev_resolve_path(const char *path, bool
*ambiguous);
void qdev_property_add_child(DeviceState *dev, const char *name,
DeviceState *child, Error **errp);
+/**
+ * @qdev_property_add_link - Add a link property to a device
+ *
+ * Links establish relationships between devices. Links are unidirectional
+ * although two links can be combined to form a bidirectional relationship
+ * between devices.
+ *
+ * Links form the graph in the device model.
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property
+ *
+ * @type - the qdev type of the link
+ *
+ * @child - a pointer to where the link device reference is stored
+ *
+ * @errp - if an error occurs, a pointer to an area to store the area
+ */
+void qdev_property_add_link(DeviceState *dev, const char *name,
+ const char *type, 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, 2011/12/12
- [Qemu-devel] [PATCH v3 008/197] qom: add link properties (v2),
Anthony Liguori <=
- [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
- [Qemu-devel] [PATCH v3 022/197] qdev: add a qdev_get_type() function and expose as a 'type' property, Anthony Liguori, 2011/12/12