qdev properties are settable only during construction and static to classes.
This isn't flexible enough for QOM.
This patch introduces a property interface for qdev that provides dynamic
properties that are tied to objects, instead of classes. These properties are
Visitor based instead of string based too.
Signed-off-by: Anthony Liguori<address@hidden>
---
hw/qdev.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
qerror.c | 4 ++
qerror.h | 3 ++
4 files changed, 224 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 106407f..ad2d44f 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -390,12 +390,33 @@ void qdev_init_nofail(DeviceState *dev)
}
}
+static void qdev_property_del_all(DeviceState *dev)
+{
+ while (dev->properties) {
+ GSList *i = dev->properties;
+ DeviceProperty *prop = i->data;
+
+ dev->properties = i->next;
+
+ if (prop->release) {
+ prop->release(dev, prop->name, prop->opaque);
+ }
+
+ g_free(prop->name);
+ g_free(prop->type);
+ g_free(prop);
+ g_free(i);
+ }
+}
+
/* Unlink device from bus and free the structure. */
void qdev_free(DeviceState *dev)
{
BusState *bus;
Property *prop;
+ qdev_property_del_all(dev);
+
if (dev->state == DEV_STATE_INITIALIZED) {
while (dev->num_child_bus) {
bus = QLIST_FIRST(&dev->child_bus);
@@ -962,3 +983,81 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
return strdup(path);
}
+
+void qdev_property_add(DeviceState *dev, const char *name, const char *type,
+ DevicePropertyEtter *get, DevicePropertyEtter *set,
+ DevicePropertyRelease *release, void *opaque,
+ Error **errp)