diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2011-12-12 14:29:26 -0600 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2011-12-15 09:20:47 -0600 |
commit | 44677ded43f1dec44fabfe52f3a4f6eb28134f95 (patch) | |
tree | bf238a0e96f0f23df7d80d83c3674128f340a489 /hw/qdev.h | |
parent | 85ed303bfe1f67a4c18ffe51916e73cffd7d9e9b (diff) | |
download | qemu-44677ded43f1dec44fabfe52f3a4f6eb28134f95.zip |
qom: add new dynamic property infrastructure based on Visitors (v2)
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 <aliguori@us.ibm.com>
Diffstat (limited to 'hw/qdev.h')
-rw-r--r-- | hw/qdev.h | 120 |
1 files changed, 120 insertions, 0 deletions
@@ -5,6 +5,7 @@ #include "qemu-queue.h" #include "qemu-char.h" #include "qemu-option.h" +#include "qapi/qapi-visit-core.h" typedef struct Property Property; @@ -27,6 +28,44 @@ enum { DEV_NVECTORS_UNSPECIFIED = -1, }; +/** + * @DevicePropertyAccessor - called when trying to get/set a property + * + * @dev the device that owns the property + * @v the visitor that contains the property data + * @opaque the device property opaque + * @name the name of the property + * @errp a pointer to an Error that is filled if getting/setting fails. + */ +typedef void (DevicePropertyAccessor)(DeviceState *dev, + Visitor *v, + void *opaque, + const char *name, + Error **errp); + +/** + * @DevicePropertyRelease - called when a property is removed from a device + * + * @dev the device that owns the property + * @name the name of the property + * @opaque the opaque registered with the property + */ +typedef void (DevicePropertyRelease)(DeviceState *dev, + const char *name, + void *opaque); + +typedef struct DeviceProperty +{ + gchar *name; + gchar *type; + DevicePropertyAccessor *get; + DevicePropertyAccessor *set; + DevicePropertyRelease *release; + void *opaque; + + QTAILQ_ENTRY(DeviceProperty) node; +} DeviceProperty; + /* This structure should not be accessed directly. We declare it here so that it can be embedded in individual device state structures. */ struct DeviceState { @@ -51,6 +90,8 @@ struct DeviceState { * more information. */ uint32_t ref; + + QTAILQ_HEAD(, DeviceProperty) properties; }; typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); @@ -355,4 +396,83 @@ void qdev_ref(DeviceState *dev); */ void qdev_unref(DeviceState *dev); +/** + * @qdev_property_add - add a new property to a device + * + * @dev - the device to add a property to + * + * @name - the name of the property. This can contain any character except for + * a forward slash. In general, you should use hyphens '-' instead of + * underscores '_' when naming properties. + * + * @type - the type name of the property. This namespace is pretty loosely + * defined. Sub namespaces are constructed by using a prefix and then + * to angle brackets. For instance, the type 'virtio-net-pci' in the + * 'link' namespace would be 'link<virtio-net-pci>'. + * + * @get - the getter to be called to read a property. If this is NULL, then + * the property cannot be read. + * + * @set - the setter to be called to write a property. If this is NULL, + * then the property cannot be written. + * + * @release - called when the property is removed from the device. This is + * meant to allow a property to free its opaque upon device + * destruction. This may be NULL. + * + * @opaque - an opaque pointer to pass to the callbacks for the property + * + * @errp - returns an error if this function fails + */ +void qdev_property_add(DeviceState *dev, const char *name, const char *type, + DevicePropertyAccessor *get, DevicePropertyAccessor *set, + DevicePropertyRelease *release, + void *opaque, Error **errp); + +/** + * @qdev_property_get - reads a property from a device + * + * @dev - the device + * + * @v - the visitor that will receive the property value. This should be an + * Output visitor and the data will be written with @name as the name. + * + * @name - the name of the property + * + * @errp - returns an error if this function fails + */ +void qdev_property_get(DeviceState *dev, Visitor *v, const char *name, + Error **errp); + +/** + * @qdev_property_set - writes a property to a device + * + * @dev - the device + * + * @v - the visitor that will be used to write the property value. This should + * be an Input visitor and the data will be first read with @name as the + * name and then written as the property value. + * + * @name - the name of the property + * + * @errp - returns an error if this function fails + */ +void qdev_property_set(DeviceState *dev, Visitor *v, const char *name, + Error **errp); + +/** + * @qdev_property_get_type - returns the type of a property + * + * @dev - the device + * + * @name - the name of the property + * + * @errp - returns an error if this function fails + * + * Returns: + * The type name of the property. + */ +const char *qdev_property_get_type(DeviceState *dev, const char *name, + Error **errp); + #endif |