Add helpers qdev_prop_get_*() to access all integer qdev properties as well as string properties.
This effectively turns qdev properties from write-only to read/write, allowing to inspect a private DeviceState. Signed-off-by: Andreas Färber <andreas.faer...@web.de> --- hw/qdev-properties.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 8 +++++++ 2 files changed, 61 insertions(+), 0 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index e262f9a..0be4130 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -669,6 +669,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); @@ -679,36 +697,71 @@ void qdev_prop_set_bool(DeviceState *dev, const char *name, bool value) qdev_prop_set(dev, name, &value, PROP_TYPE_BOOL); } +bool qdev_prop_get_bool(DeviceState *dev, const char *name) +{ + return *(bool *)qdev_prop_get(dev, name, PROP_TYPE_BOOL); +} + void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value) { qdev_prop_set(dev, name, &value, PROP_TYPE_UINT8); } +uint8_t qdev_prop_get_uint8(DeviceState *dev, const char *name) +{ + return *(uint8_t *)qdev_prop_get(dev, name, PROP_TYPE_UINT8); +} + void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value) { qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16); } +uint16_t qdev_prop_get_uint16(DeviceState *dev, const char *name) +{ + return *(uint16_t *)qdev_prop_get(dev, name, PROP_TYPE_UINT16); +} + 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); } +int32_t qdev_prop_get_int32(DeviceState *dev, const char *name) +{ + return *(int32_t *)qdev_prop_get(dev, name, PROP_TYPE_INT32); +} + void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value) { qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64); } +uint64_t qdev_prop_get_uint64(DeviceState *dev, const char *name) +{ + return *(uint64_t *)qdev_prop_get(dev, name, PROP_TYPE_UINT64); +} + void qdev_prop_set_string(DeviceState *dev, const char *name, char *value) { qdev_prop_set(dev, name, &value, PROP_TYPE_STRING); } +char *qdev_prop_get_string(DeviceState *dev, const char *name) +{ + return (char *)qdev_prop_get(dev, name, PROP_TYPE_STRING); +} + int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) { int res; diff --git a/hw/qdev.h b/hw/qdev.h index f05166d..71bd230 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -301,14 +301,22 @@ 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_bool(DeviceState *dev, const char *name, bool value); +bool qdev_prop_get_bool(DeviceState *dev, const char *name); void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value); +uint8_t qdev_prop_get_uint8(DeviceState *dev, const char *name); void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); +uint16_t qdev_prop_get_uint16(DeviceState *dev, const char *name); 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); +int32_t qdev_prop_get_int32(DeviceState *dev, const char *name); void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); +uint64_t qdev_prop_get_uint64(DeviceState *dev, const char *name); void qdev_prop_set_string(DeviceState *dev, const char *name, char *value); +char *qdev_prop_get_string(DeviceState *dev, const char *name); void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value); void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value); void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value); -- 1.7.5.3