diff options
author | Juan Quintela <quintela@redhat.com> | 2009-09-29 22:48:25 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-10-05 09:32:37 -0500 |
commit | c7cc172d207d4719a21c8c2a874919eaf2da1273 (patch) | |
tree | bab9db25c992ffecbe3c606623225cbcb0d686c2 /hw/qdev-properties.c | |
parent | vmstate: Add support for sending partial arrays (diff) | |
download | qemu-kvm-c7cc172d207d4719a21c8c2a874919eaf2da1273.tar.gz qemu-kvm-c7cc172d207d4719a21c8c2a874919eaf2da1273.tar.bz2 qemu-kvm-c7cc172d207d4719a21c8c2a874919eaf2da1273.zip |
qdev: Add support for uint8_t
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r-- | hw/qdev-properties.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 2ecb58df2..c4fb15c02 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -8,6 +8,34 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) return ptr; } +/* --- 8bit integer --- */ + +static int parse_uint8(DeviceState *dev, Property *prop, const char *str) +{ + uint8_t *ptr = qdev_get_prop_ptr(dev, prop); + const char *fmt; + + /* accept both hex and decimal */ + fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx8 : "%" PRIu8; + if (sscanf(str, fmt, ptr) != 1) + return -1; + return 0; +} + +static int print_uint8(DeviceState *dev, Property *prop, char *dest, size_t len) +{ + uint8_t *ptr = qdev_get_prop_ptr(dev, prop); + return snprintf(dest, len, "%" PRIu8, *ptr); +} + +PropertyInfo qdev_prop_uint8 = { + .name = "uint8", + .type = PROP_TYPE_UINT8, + .size = sizeof(uint8_t), + .parse = parse_uint8, + .print = print_uint8, +}; + /* --- 16bit integer --- */ static int parse_uint16(DeviceState *dev, Property *prop, const char *str) @@ -391,6 +419,11 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT memcpy(dst, src, prop->info->size); } +void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value) +{ + qdev_prop_set(dev, name, &value, 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); |