aboutsummaryrefslogtreecommitdiff
path: root/hw/qdev-properties.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-02-02 09:43:02 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2012-02-07 13:52:42 +0100
commit4f2d3d705c1ae7dce29254e2c4645c84e77a74d4 (patch)
tree7f525b04ca416995c309d49869ba53f1b2c9a016 /hw/qdev-properties.c
parent7a7aae21ccab06606cee9aba846d2e30cb616763 (diff)
qdev: initialize properties via QOM
Similarly, use the object properties also to set the default values of the qdev properties. This requires reordering registration and initialization. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r--hw/qdev-properties.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index b3cd2a8921..49bed302d4 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -26,17 +26,6 @@ static void bit_prop_set(DeviceState *dev, Property *props, bool val)
*p &= ~mask;
}
-static void qdev_prop_cpy(DeviceState *dev, Property *props, void *src)
-{
- if (props->info->type == PROP_TYPE_BIT) {
- bool *defval = src;
- bit_prop_set(dev, props, *defval);
- } else {
- char *dst = qdev_get_prop_ptr(dev, props);
- memcpy(dst, src, props->info->size);
- }
-}
-
/* Bit */
static int parse_bit(DeviceState *dev, Property *prop, const char *str)
{
@@ -1241,13 +1230,23 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
void qdev_prop_set_defaults(DeviceState *dev, Property *props)
{
+ Object *obj = OBJECT(dev);
if (!props)
return;
- while (props->name) {
- if (props->defval) {
- qdev_prop_cpy(dev, props, props->defval);
+ for (; props->name; props++) {
+ Error *errp = NULL;
+ if (props->qtype == QTYPE_NONE) {
+ continue;
}
- props++;
+ if (props->qtype == QTYPE_QBOOL) {
+ object_property_set_bool(obj, props->defval, props->name, &errp);
+ } else if (props->info->enum_table) {
+ object_property_set_str(obj, props->info->enum_table[props->defval],
+ props->name, &errp);
+ } else if (props->qtype == QTYPE_QINT) {
+ object_property_set_int(obj, props->defval, props->name, &errp);
+ }
+ assert(!errp);
}
}