This effectively turns qdev properties from write-only to read/write,
allowing to inspect a private DeviceState.

As a start, add qdev_prop_get_uint32().

Signed-off-by: Andreas Färber <andreas.faer...@web.de>
---
 hw/qdev-properties.c |   23 +++++++++++++++++++++++
 hw/qdev.h            |    2 ++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index eff2d24..bca3028 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -639,6 +639,24 @@ void qdev_prop_set(DeviceState *dev, const char *name, 
void *src, enum PropertyT
     qdev_prop_cpy(dev, prop, src);
 }
 
+void *qdev_prop_get(DeviceState *dev, const char *name, enum PropertyType type)
+{
+    Property *prop;
+
+    prop = qdev_prop_find(dev, name);
+    if (!prop) {
+        fprintf(stderr, "%s: property \"%s.%s\" not found\n",
+                __FUNCTION__, dev->info->name, name);
+        abort();
+    }
+    if (prop->info->type != type) {
+        fprintf(stderr, "%s: property \"%s.%s\" type mismatch\n",
+                __FUNCTION__, dev->info->name, name);
+        abort();
+    }
+    return qdev_get_prop_ptr(dev, prop);
+}
+
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
 {
     qdev_prop_set(dev, name, &value, PROP_TYPE_BIT);
@@ -659,6 +677,11 @@ void qdev_prop_set_uint32(DeviceState *dev, const char 
*name, uint32_t value)
     qdev_prop_set(dev, name, &value, PROP_TYPE_UINT32);
 }
 
+uint32_t qdev_prop_get_uint32(DeviceState *dev, const char *name)
+{
+    return *(uint32_t *)qdev_prop_get(dev, name, PROP_TYPE_UINT32);
+}
+
 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
 {
     qdev_prop_set(dev, name, &value, PROP_TYPE_INT32);
diff --git a/hw/qdev.h b/hw/qdev.h
index 8a13ec9..051d03e 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -297,10 +297,12 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
 int qdev_prop_exists(DeviceState *dev, const char *name);
 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
 void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum 
PropertyType type);
+void *qdev_prop_get(DeviceState *dev, const char *name, enum PropertyType 
type);
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
+uint32_t qdev_prop_get_uint32(DeviceState *dev, const char *name);
 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
 void qdev_prop_set_string(DeviceState *dev, const char *name, char *value);
-- 
1.7.5.3


Reply via email to