*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)
{
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);
}
}
dev->parent_bus = bus;
QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
- qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) {
qdev_property_add_legacy(dev, prop, NULL);
qdev_property_add_static(dev, prop, NULL);
}
+ qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
}
/* Create a new device. This only initializes the device state structure
dev->instance_id_alias = -1;
dev->state = DEV_STATE_CREATED;
- qdev_prop_set_defaults(dev, qdev_get_props(dev));
for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
qdev_property_add_legacy(dev, prop, NULL);
qdev_property_add_static(dev, prop, NULL);
}
object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
+ qdev_prop_set_defaults(dev, qdev_get_props(dev));
}
/* Unlink device from bus and free the structure. */
const char *name;
PropertyInfo *info;
int offset;
- int bitnr;
- void *defval;
+ uint8_t bitnr;
+ uint8_t qtype;
+ int64_t defval;
};
enum PropertyType {
.info = &(_prop), \
.offset = offsetof(_state, _field) \
+ type_check(_type,typeof_field(_state, _field)), \
- .defval = (_type[]) { _defval }, \
+ .qtype = QTYPE_QINT, \
+ .defval = (_type)_defval, \
}
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
.name = (_name), \
.bitnr = (_bit), \
.offset = offsetof(_state, _field) \
+ type_check(uint32_t,typeof_field(_state, _field)), \
- .defval = (bool[]) { (_defval) }, \
+ .qtype = QTYPE_QBOOL, \
+ .defval = (bool)_defval, \
}
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \