diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-09-10 11:43:25 +0200 |
---|---|---|
committer | malc <av1474@comtv.ru> | 2009-09-10 19:47:58 +0400 |
commit | 316940b06273c43ec8d58fcb0908267f7fa5d333 (patch) | |
tree | 4c75627fd5d6828e09fb8c986dd74f6f7bf8b5b4 /hw/qdev-properties.c | |
parent | 679a37afc49373834f2dc639b179f78112219089 (diff) |
qdev: add property type for 32bit signed integers.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r-- | hw/qdev-properties.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 12ff46bf0b..28b2716b04 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -64,6 +64,29 @@ PropertyInfo qdev_prop_uint32 = { .print = print_uint32, }; +static int parse_int32(DeviceState *dev, Property *prop, const char *str) +{ + int32_t *ptr = qdev_get_prop_ptr(dev, prop); + + if (sscanf(str, "%" PRId32, ptr) != 1) + return -1; + return 0; +} + +static int print_int32(DeviceState *dev, Property *prop, char *dest, size_t len) +{ + int32_t *ptr = qdev_get_prop_ptr(dev, prop); + return snprintf(dest, len, "%" PRId32, *ptr); +} + +PropertyInfo qdev_prop_int32 = { + .name = "int32", + .type = PROP_TYPE_INT32, + .size = sizeof(int32_t), + .parse = parse_int32, + .print = print_int32, +}; + /* --- 32bit hex value --- */ static int parse_hex32(DeviceState *dev, Property *prop, const char *str) @@ -367,6 +390,11 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value) qdev_prop_set(dev, name, &value, 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); +} + void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value) { qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64); |