[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/18] qom: register legacy properties as new style
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 02/18] qom: register legacy properties as new style properties |
Date: |
Wed, 30 Nov 2011 15:03:32 -0600 |
Expose all legacy properties through the new QOM property mechanism. The qdev
property types are exposed through the 'legacy<>' namespace. They are always
visited as strings since they do their own string parsing.
Signed-off-by: Anthony Liguori <address@hidden>
---
hw/qdev.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 7 +++++
2 files changed, 89 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index ad2d44f..b890c9f 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -83,6 +83,7 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const
char *name)
static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
{
DeviceState *dev;
+ Property *prop;
assert(bus->info == info->bus_info);
dev = g_malloc0(info->size);
@@ -99,6 +100,11 @@ static DeviceState *qdev_create_from_info(BusState *bus,
DeviceInfo *info)
}
dev->instance_id_alias = -1;
dev->state = DEV_STATE_CREATED;
+
+ for (prop = dev->info->props; prop && prop->name; prop++) {
+ qdev_property_add_legacy(dev, prop, NULL);
+ }
+
return dev;
}
@@ -1061,3 +1067,79 @@ const char *qdev_property_get_type(DeviceState *dev,
const char *name, Error **e
return prop->type;
}
+
+/**
+ * Legacy property handling
+ */
+
+static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void
*opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+
+ if (prop->info->print) {
+ char buffer[1024];
+ char *ptr = buffer;
+
+ prop->info->print(dev, prop, buffer, sizeof(buffer));
+ visit_type_str(v, &ptr, name, errp);
+ } else {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ }
+}
+
+static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void
*opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+
+ if (dev->state != DEV_STATE_CREATED) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ if (prop->info->parse) {
+ Error *local_err = NULL;
+ char *ptr = NULL;
+
+ visit_type_str(v, &ptr, name, &local_err);
+ if (!local_err) {
+ int ret;
+ ret = prop->info->parse(dev, prop, ptr);
+ if (ret != 0) {
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+ name, prop->info->name);
+ }
+ g_free(ptr);
+ } else {
+ error_propagate(errp, local_err);
+ }
+ } else {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ }
+}
+
+/**
+ * @qdev_add_legacy_property - adds a legacy property
+ *
+ * Do not use this is new code! Properties added through this interface will
+ * be given types in the "legacy<>" type namespace.
+ *
+ * Legacy properties are always processed as strings. The format of the string
+ * depends on the property type.
+ */
+void qdev_property_add_legacy(DeviceState *dev, Property *prop,
+ Error **errp)
+{
+ gchar *type;
+
+ type = g_strdup_printf("legacy<%s>", prop->info->name);
+
+ qdev_property_add(dev, prop->name, type,
+ qdev_get_legacy_property,
+ qdev_set_legacy_property,
+ NULL,
+ prop, errp);
+
+ g_free(type);
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 0f23677..8ac9031 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -447,4 +447,11 @@ void qdev_property_set(DeviceState *dev, Visitor *v, const
char *name,
const char *qdev_property_get_type(DeviceState *dev, const char *name,
Error **errp);
+/**
+ * @qdev_property_add_legacy - add a legacy @Property to a device
+ *
+ * DO NOT USE THIS IN NEW CODE!
+ */
+void qdev_property_add_legacy(DeviceState *dev, Property *prop, 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, 2011/11/30
- [Qemu-devel] [PATCH 02/18] qom: register legacy properties as new style properties,
Anthony Liguori <=
- [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
- [Qemu-devel] [PATCH 12/18] dev: add an anonymous peripheral container, Anthony Liguori, 2011/11/30