qdev: Introduce PropertyInfo.create
This allows property implementation to provide a specialized property creation method. Update conditions guarding property types accordingly. Signed-off-by: Fam Zheng <famz@redhat.com> Message-Id: <20170714021509.23681-3-famz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
8f5d58ef2c
commit
faabdbb792
@ -744,6 +744,10 @@ static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prop->info->create) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
name = g_strdup_printf("legacy-%s", prop->name);
|
name = g_strdup_printf("legacy-%s", prop->name);
|
||||||
object_property_add(OBJECT(dev), name, "str",
|
object_property_add(OBJECT(dev), name, "str",
|
||||||
prop->info->print ? qdev_get_legacy_property : prop->info->get,
|
prop->info->print ? qdev_get_legacy_property : prop->info->get,
|
||||||
@ -770,20 +774,23 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,
|
|||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
Object *obj = OBJECT(dev);
|
Object *obj = OBJECT(dev);
|
||||||
|
|
||||||
/*
|
if (prop->info->create) {
|
||||||
* TODO qdev_prop_ptr does not have getters or setters. It must
|
prop->info->create(obj, prop, &local_err);
|
||||||
* go now that it can be replaced with links. The test should be
|
} else {
|
||||||
* removed along with it: all static properties are read/write.
|
/*
|
||||||
*/
|
* TODO qdev_prop_ptr does not have getters or setters. It must
|
||||||
if (!prop->info->get && !prop->info->set) {
|
* go now that it can be replaced with links. The test should be
|
||||||
return;
|
* removed along with it: all static properties are read/write.
|
||||||
|
*/
|
||||||
|
if (!prop->info->get && !prop->info->set) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
object_property_add(obj, prop->name, prop->info->name,
|
||||||
|
prop->info->get, prop->info->set,
|
||||||
|
prop->info->release,
|
||||||
|
prop, &local_err);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_property_add(obj, prop->name, prop->info->name,
|
|
||||||
prop->info->get, prop->info->set,
|
|
||||||
prop->info->release,
|
|
||||||
prop, &local_err);
|
|
||||||
|
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return;
|
||||||
|
@ -241,6 +241,7 @@ struct PropertyInfo {
|
|||||||
const char * const *enum_table;
|
const char * const *enum_table;
|
||||||
int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
|
int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
|
||||||
void (*set_default_value)(Object *obj, const Property *prop);
|
void (*set_default_value)(Object *obj, const Property *prop);
|
||||||
|
void (*create)(Object *obj, Property *prop, Error **errp);
|
||||||
ObjectPropertyAccessor *get;
|
ObjectPropertyAccessor *get;
|
||||||
ObjectPropertyAccessor *set;
|
ObjectPropertyAccessor *set;
|
||||||
ObjectPropertyRelease *release;
|
ObjectPropertyRelease *release;
|
||||||
|
2
qmp.c
2
qmp.c
@ -480,7 +480,7 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
|
|||||||
* for removal. This conditional should be removed along with
|
* for removal. This conditional should be removed along with
|
||||||
* it.
|
* it.
|
||||||
*/
|
*/
|
||||||
if (!prop->info->set) {
|
if (!prop->info->set && !prop->info->create) {
|
||||||
return NULL; /* no way to set it, don't show */
|
return NULL; /* no way to set it, don't show */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user