[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 18/20] qom: add string property type
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH v3 18/20] qom: add string property type |
Date: |
Mon, 12 Dec 2011 14:29:42 -0600 |
Signed-off-by: Anthony Liguori <address@hidden>
---
hw/qdev.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 22 ++++++++++++++++++++++
2 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 4004860..0fc20fc 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1449,3 +1449,62 @@ DeviceState *qdev_resolve_path(const char *path, bool
*ambiguous)
return dev;
}
+typedef struct StringProperty
+{
+ char *(*get)(DeviceState *, Error **);
+ void (*set)(DeviceState *, const char *, Error **);
+} StringProperty;
+
+static void qdev_property_get_str(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ StringProperty *prop = opaque;
+ char *value;
+
+ value = prop->get(dev, errp);
+ if (value) {
+ visit_type_str(v, &value, name, errp);
+ g_free(value);
+ }
+}
+
+static void qdev_property_set_str(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ StringProperty *prop = opaque;
+ char *value;
+ Error *local_err = NULL;
+
+ visit_type_str(v, &value, name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ prop->set(dev, value, errp);
+ g_free(value);
+}
+
+static void qdev_property_release_str(DeviceState *dev, const char *name,
+ void *opaque)
+{
+ StringProperty *prop = opaque;
+ g_free(prop);
+}
+
+void qdev_property_add_str(DeviceState *dev, const char *name,
+ char *(*get)(DeviceState *, Error **),
+ void (*set)(DeviceState *, const char *, Error **),
+ Error **errp)
+{
+ StringProperty *prop = g_malloc0(sizeof(*prop));
+
+ prop->get = get;
+ prop->set = set;
+
+ qdev_property_add(dev, name, "string",
+ get ? qdev_property_get_str : NULL,
+ set ? qdev_property_set_str : NULL,
+ qdev_property_release_str,
+ prop, errp);
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index fdab848..9faf2ee 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -574,4 +574,26 @@ void qdev_property_add_link(DeviceState *dev, const char
*name,
const char *type, DeviceState **child,
Error **errp);
+/**
+ * @qdev_property_add_str
+ *
+ * Add a string property using getters/setters. This function will add a
+ * property of type 'string'.
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property
+ *
+ * @get - the getter or NULL if the property is write-only. This function must
+ * return a string to be freed by @g_free().
+ *
+ * @set - the setter or NULL if the property is read-only
+ *
+ * @errp - if an error occurs, a pointer to an area to store the error
+ */
+void qdev_property_add_str(DeviceState *dev, const char *name,
+ char *(*get)(DeviceState *, Error **),
+ void (*set)(DeviceState *, const char *, Error **),
+ Error **errp);
+
#endif
--
1.7.4.1
- [Qemu-devel] [PATCH v3 10/20] qmp: add qom-list command, (continued)
- [Qemu-devel] [PATCH v3 10/20] qmp: add qom-list command, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 09/20] qapi: allow a 'gen' key to suppress code generation, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 12/20] qdev: add explicitly named devices to the root complex, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 11/20] qom: qom_{get, set} monitor commands (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 14/20] rtc: make piix3 set the rtc as a child (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 16/20] qom: optimize qdev_get_canonical_path using a parent link, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 19/20] qdev: add a qdev_get_type() function and expose as a 'type' property, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 13/20] dev: add an anonymous peripheral container, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 17/20] qom: add vga node to the pc composition tree, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 15/20] rtc: add a dynamic property for retrieving the date, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 18/20] qom: add string property type,
Anthony Liguori <=
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Anthony Liguori, 2011/12/15
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Kevin Wolf, 2011/12/16
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Paolo Bonzini, 2011/12/16
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Kevin Wolf, 2011/12/16
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Paolo Bonzini, 2011/12/16
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Kevin Wolf, 2011/12/16
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Paolo Bonzini, 2011/12/16
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Anthony Liguori, 2011/12/16
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Anthony Liguori, 2011/12/16
- Re: [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree, Paolo Bonzini, 2011/12/16