qdev: Wrap getters and setters in separate helpers
We'll add extra code to the qdev property getters and setters, so add wrapper functions where additional actions can be performed. The new functions have a "field_prop_" prefix instead of "qdev_" because the code will eventually be moved outside qdev-properties.c, to common QOM code. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <20201211220529.2290218-23-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
c80fab0b61
commit
7ed854af14
@ -44,6 +44,40 @@ void *qdev_get_prop_ptr(Object *obj, Property *prop)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void field_prop_get(Object *obj, Visitor *v, const char *name,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
Property *prop = opaque;
|
||||
return prop->info->get(obj, v, name, opaque, errp);
|
||||
}
|
||||
|
||||
/**
|
||||
* field_prop_getter: Return getter function to be used for property
|
||||
*
|
||||
* Return value can be NULL if @info has no getter function.
|
||||
*/
|
||||
static ObjectPropertyAccessor *field_prop_getter(const PropertyInfo *info)
|
||||
{
|
||||
return info->get ? field_prop_get : NULL;
|
||||
}
|
||||
|
||||
static void field_prop_set(Object *obj, Visitor *v, const char *name,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
Property *prop = opaque;
|
||||
return prop->info->set(obj, v, name, opaque, errp);
|
||||
}
|
||||
|
||||
/**
|
||||
* field_prop_setter: Return setter function to be used for property
|
||||
*
|
||||
* Return value can be NULL if @info has not setter function.
|
||||
*/
|
||||
static ObjectPropertyAccessor *field_prop_setter(const PropertyInfo *info)
|
||||
{
|
||||
return info->set ? field_prop_set : NULL;
|
||||
}
|
||||
|
||||
void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
@ -630,8 +664,8 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
|
||||
assert(qdev_get_prop_ptr(obj, &arrayprop->prop) == eltptr);
|
||||
object_property_add(obj, propname,
|
||||
arrayprop->prop.info->name,
|
||||
arrayprop->prop.info->get,
|
||||
arrayprop->prop.info->set,
|
||||
field_prop_getter(arrayprop->prop.info),
|
||||
field_prop_setter(arrayprop->prop.info),
|
||||
array_element_release,
|
||||
arrayprop);
|
||||
}
|
||||
@ -873,7 +907,8 @@ void qdev_property_add_static(DeviceState *dev, Property *prop)
|
||||
assert(!prop->info->create);
|
||||
|
||||
op = object_property_add(obj, prop->name, prop->info->name,
|
||||
prop->info->get, prop->info->set,
|
||||
field_prop_getter(prop->info),
|
||||
field_prop_setter(prop->info),
|
||||
prop->info->release,
|
||||
prop);
|
||||
|
||||
@ -900,7 +935,8 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name,
|
||||
|
||||
op = object_class_property_add(oc,
|
||||
name, prop->info->name,
|
||||
prop->info->get, prop->info->set,
|
||||
field_prop_getter(prop->info),
|
||||
field_prop_setter(prop->info),
|
||||
prop->info->release,
|
||||
prop);
|
||||
if (prop->set_default) {
|
||||
|
Loading…
Reference in New Issue
Block a user