aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-02-02 12:51:44 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2012-02-07 13:52:42 +0100
commit9b170e60adc6dc01564128cf09f96ec923ed6526 (patch)
tree45e9dd8f533a40be7006517f0f5e998f62292ff1
parent6350b0904615cc0531cc3059ea34db5c009c88aa (diff)
downloadqemu-9b170e60adc6dc01564128cf09f96ec923ed6526.zip
qemu-9b170e60adc6dc01564128cf09f96ec923ed6526.tar.gz
qemu-9b170e60adc6dc01564128cf09f96ec923ed6526.tar.bz2
qdev: access properties via QOM
Do not poke anymore in the struct when accessing qdev properties. Instead, ask the object to set the right value. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--hw/qdev-addr.c5
-rw-r--r--hw/qdev-properties.c78
-rw-r--r--hw/qdev.h4
3 files changed, 59 insertions, 28 deletions
diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
index 5976dcd..8daa733 100644
--- a/hw/qdev-addr.c
+++ b/hw/qdev-addr.c
@@ -71,5 +71,8 @@ PropertyInfo qdev_prop_taddr = {
void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_TADDR);
+ Error *errp = NULL;
+ object_property_set_int(OBJECT(dev), value, name, &errp);
+ assert(!errp);
+
}
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index debb37f..5a11676 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -1115,7 +1115,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
return 0;
}
-void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
+static void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
{
Property *prop;
@@ -1135,52 +1135,63 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_BIT);
+ Error *errp = NULL;
+ object_property_set_bool(OBJECT(dev), value, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_UINT8);
+ Error *errp = NULL;
+ object_property_set_int(OBJECT(dev), value, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16);
+ Error *errp = NULL;
+ object_property_set_int(OBJECT(dev), value, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_UINT32);
+ Error *errp = NULL;
+ object_property_set_int(OBJECT(dev), value, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_INT32);
+ Error *errp = NULL;
+ object_property_set_int(OBJECT(dev), value, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64);
+ Error *errp = NULL;
+ object_property_set_int(OBJECT(dev), value, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_string(DeviceState *dev, const char *name, char *value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_STRING);
+ Error *errp = NULL;
+ object_property_set_str(OBJECT(dev), value, name, &errp);
+ assert(!errp);
}
int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
{
- int res;
-
- res = bdrv_attach_dev(value, dev);
- if (res < 0) {
- error_report("Can't attach drive %s to %s.%s: %s",
- bdrv_get_device_name(value),
- dev->id ? dev->id : object_get_typename(OBJECT(dev)),
- name, strerror(-res));
+ Error *errp = NULL;
+ object_property_set_str(OBJECT(dev), bdrv_get_device_name(value),
+ name, &errp);
+ if (errp) {
+ qerror_report_err(errp);
+ error_free(errp);
return -1;
}
- qdev_prop_set(dev, name, &value, PROP_TYPE_DRIVE);
return 0;
}
@@ -1192,28 +1203,47 @@ void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverS
}
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
+ Error *errp = NULL;
+ assert(value->label);
+ object_property_set_str(OBJECT(dev), value->label, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
+ Error *errp = NULL;
+ assert(value->name);
+ object_property_set_str(OBJECT(dev), value->name, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
{
- qdev_prop_set(dev, name, &value, PROP_TYPE_VLAN);
+ Error *errp = NULL;
+ object_property_set_int(OBJECT(dev), value ? value->id : -1, name, &errp);
+ assert(!errp);
}
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
{
- qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
+ Error *errp = NULL;
+ char str[2 * 6 + 5 + 1];
+ snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
+ value[0], value[1], value[2], value[3], value[4], value[5]);
+
+ object_property_set_str(OBJECT(dev), str, name, &errp);
+ assert(!errp);
}
-void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
- LostTickPolicy *value)
+void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
{
- qdev_prop_set(dev, name, value, PROP_TYPE_LOSTTICKPOLICY);
+ Property *prop;
+ Error *errp = NULL;
+
+ prop = qdev_prop_find(dev, name);
+ object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
+ name, &errp);
+ assert(!errp);
}
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
diff --git a/hw/qdev.h b/hw/qdev.h
index acccf26..9ccd5c3 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -310,7 +310,6 @@ extern PropertyInfo qdev_prop_pci_devfn;
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_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);
@@ -324,8 +323,7 @@ void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
-void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
- LostTickPolicy *value);
+void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
/* FIXME: Remove opaque pointer properties. */
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
void qdev_prop_set_defaults(DeviceState *dev, Property *props);