Move the core of the static property code to qom/static-property.c. The actual property type implementations are still in qdev-properties.c, they will be moved later.
Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- Cc: Paolo Bonzini <pbonz...@redhat.com> Cc: "Daniel P. Berrangé" <berra...@redhat.com> Cc: Eduardo Habkost <ehabk...@redhat.com> Cc: qemu-devel@nongnu.org --- include/hw/qdev-properties.h | 71 +---------- .../qom/static-property-internal.h | 6 +- include/qom/static-property.h | 79 ++++++++++++ hw/core/qdev-properties-system.c | 2 +- hw/core/qdev-properties.c | 110 +---------------- qom/static-property.c | 114 ++++++++++++++++++ qom/meson.build | 1 + 7 files changed, 200 insertions(+), 183 deletions(-) rename hw/core/qdev-prop-internal.h => include/qom/static-property-internal.h (91%) create mode 100644 include/qom/static-property.h create mode 100644 qom/static-property.c diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index f9a4c132e7..e1ef466790 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -2,44 +2,7 @@ #define QEMU_QDEV_PROPERTIES_H #include "hw/qdev-core.h" - -/** - * Property: - * @set_default: true if the default value should be set from @defval, - * in which case @info->set_default_value must not be NULL - * (if false then no default value is set by the property system - * and the field retains whatever value it was given by instance_init). - * @defval: default value for the property. This is used only if @set_default - * is true. - */ -struct Property { - const char *name; - const PropertyInfo *info; - ptrdiff_t offset; - uint8_t bitnr; - bool set_default; - union { - int64_t i; - uint64_t u; - } defval; - int arrayoffset; - const PropertyInfo *arrayinfo; - int arrayfieldsize; - const char *link_type; -}; - -struct PropertyInfo { - const char *name; - const char *description; - const QEnumLookup *enum_table; - int (*print)(Object *obj, Property *prop, char *dest, size_t len); - void (*set_default_value)(ObjectProperty *op, const Property *prop); - ObjectProperty *(*create)(ObjectClass *oc, Property *prop); - ObjectPropertyAccessor *get; - ObjectPropertyAccessor *set; - ObjectPropertyRelease *release; -}; - +#include "qom/static-property.h" /*** qdev-properties.c ***/ @@ -172,36 +135,6 @@ extern const PropertyInfo qdev_prop_link; #define DEFINE_PROP_END_OF_LIST() \ {} -/** - * object_class_property_add_static: Add a static property to object class - * @oc: object class - * @prop: property definition - * @allow_set: optional check function - * - * Add a property to an object class based on the property definition - * at @prop. - * - * If @allow_set is NULL, the property will always be allowed to be set. - * - * The property definition at @prop should be defined using the - * ``DEFINE_PROP`` family of macros. *@prop must exist for the - * life time of @oc. - */ -ObjectProperty * -object_class_property_add_static(ObjectClass *oc, Property *prop, - ObjectPropertyAllowSet allow_set); - -/** - * object_class_add_static_props: Add multiple static properties to object class - * @oc: object class - * @props: property definition array, terminated by DEFINED_PROP_END_OF_LIST() - * @allow_set: optional check function - * - * Add properties from @props using object_class_property_add_static() - */ -void object_class_add_static_props(ObjectClass *oc, Property *props, - ObjectPropertyAllowSet allow_set); - /* * Set properties between creation and realization. * @@ -229,8 +162,6 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, const uint8_t *value); void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); -void *object_static_prop_ptr(Object *obj, Property *prop); - void qdev_prop_register_global(GlobalProperty *prop); const GlobalProperty *qdev_find_global_prop(Object *obj, const char *name); diff --git a/hw/core/qdev-prop-internal.h b/include/qom/static-property-internal.h similarity index 91% rename from hw/core/qdev-prop-internal.h rename to include/qom/static-property-internal.h index 41ec9e8942..7cde883a04 100644 --- a/hw/core/qdev-prop-internal.h +++ b/include/qom/static-property-internal.h @@ -1,12 +1,12 @@ /* - * qdev property parsing + * QOM static property internal API (for implementing custom types) * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ -#ifndef HW_CORE_QDEV_PROP_INTERNAL_H -#define HW_CORE_QDEV_PROP_INTERNAL_H +#ifndef QOM_STATIC_PROPERTY_INTERNAL_H +#define QOM_STATIC_PROPERTY_INTERNAL_H void object_propinfo_get_enum(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp); diff --git a/include/qom/static-property.h b/include/qom/static-property.h new file mode 100644 index 0000000000..125ff06327 --- /dev/null +++ b/include/qom/static-property.h @@ -0,0 +1,79 @@ +/* + * QOM static property API + */ +#ifndef QOM_STATIC_PROPERTY_H +#define QOM_STATIC_PROPERTY_H + +#include "qom/object.h" +#include "qapi/util.h" + +/** + * Property: + * @set_default: true if the default value should be set from @defval, + * in which case @info->set_default_value must not be NULL + * (if false then no default value is set by the property system + * and the field retains whatever value it was given by instance_init). + * @defval: default value for the property. This is used only if @set_default + * is true. + */ +struct Property { + const char *name; + const PropertyInfo *info; + ptrdiff_t offset; + uint8_t bitnr; + bool set_default; + union { + int64_t i; + uint64_t u; + } defval; + int arrayoffset; + const PropertyInfo *arrayinfo; + int arrayfieldsize; + const char *link_type; +}; + +struct PropertyInfo { + const char *name; + const char *description; + const QEnumLookup *enum_table; + int (*print)(Object *obj, Property *prop, char *dest, size_t len); + void (*set_default_value)(ObjectProperty *op, const Property *prop); + ObjectProperty *(*create)(ObjectClass *oc, Property *prop); + ObjectPropertyAccessor *get; + ObjectPropertyAccessor *set; + ObjectPropertyRelease *release; +}; + +/** + * object_class_property_add_static: Add a static property to object class + * @oc: object class + * @prop: property definition + * @allow_set: optional check function + * + * Add a property to an object class based on the property definition + * at @prop. + * + * If @allow_set is NULL, the property will always be allowed to be set. + * + * The property definition at @prop should be defined using the + * ``DEFINE_PROP`` family of macros. *@prop must exist for the + * life time of @oc. + */ +ObjectProperty * +object_class_property_add_static(ObjectClass *oc, Property *prop, + ObjectPropertyAllowSet allow_set); + +/** + * object_class_add_static_props: Add multiple static properties to object class + * @oc: object class + * @props: property definition array, terminated by DEFINED_PROP_END_OF_LIST() + * @allow_set: optional check function + * + * Add properties from @props using object_class_property_add_static() + */ +void object_class_add_static_props(ObjectClass *oc, Property *props, + ObjectPropertyAllowSet allow_set); + +void *object_static_prop_ptr(Object *obj, Property *prop); + +#endif diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 8cfa9a3d20..232ff955fa 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -23,7 +23,7 @@ #include "qemu/cutils.h" #include "qemu/units.h" #include "qemu/error-report.h" -#include "qdev-prop-internal.h" +#include "qom/static-property-internal.h" #include "audio/audio.h" #include "chardev/char-fe.h" diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 0b53e5ba63..1b27ba7236 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -9,7 +9,7 @@ #include "qemu/uuid.h" #include "qemu/units.h" #include "qemu/cutils.h" -#include "qdev-prop-internal.h" +#include "qom/static-property-internal.h" void qdev_prop_set_after_realize(DeviceState *dev, const char *name, Error **errp) @@ -51,48 +51,6 @@ void qdev_prop_allow_set_link_before_realize(const Object *obj, } } -void *object_static_prop_ptr(Object *obj, Property *prop) -{ - void *ptr = obj; - ptr += prop->offset; - return ptr; -} - -static void static_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); -} - -/** - * static_prop_getter: Return getter function to be used for property - * - * Return value can be NULL if @info has no getter function. - */ -static ObjectPropertyAccessor *static_prop_getter(const PropertyInfo *info) -{ - return info->get ? static_prop_get : NULL; -} - -static void static_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); -} - -/** - * static_prop_setter: Return setter function to be used for property - * - * Return value can be NULL if @info has not setter function. - */ -static ObjectPropertyAccessor *static_prop_setter(const PropertyInfo *info) -{ - return info->set ? static_prop_set : NULL; -} - void object_propinfo_get_enum(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { @@ -907,72 +865,6 @@ const PropertyInfo qdev_prop_link = { .create = create_link_property, }; -ObjectProperty * -object_property_add_static(Object *obj, Property *prop, - ObjectPropertyAllowSet allow_set) -{ - ObjectProperty *op; - - assert(!prop->info->create); - - op = object_property_add(obj, prop->name, prop->info->name, - static_prop_getter(prop->info), - static_prop_setter(prop->info), - prop->info->release, - prop); - - object_property_set_description(obj, prop->name, - prop->info->description); - - if (prop->set_default) { - prop->info->set_default_value(op, prop); - if (op->init) { - op->init(obj, op); - } - } - - op->allow_set = allow_set; - return op; -} - -ObjectProperty * -object_class_property_add_static(ObjectClass *oc, Property *prop, - ObjectPropertyAllowSet allow_set) -{ - ObjectProperty *op; - - if (prop->info->create) { - op = prop->info->create(oc, prop); - } else { - op = object_class_property_add(oc, - prop->name, prop->info->name, - static_prop_getter(prop->info), - static_prop_setter(prop->info), - prop->info->release, - prop); - } - if (prop->set_default) { - prop->info->set_default_value(op, prop); - } - if (prop->info->description) { - object_class_property_set_description(oc, prop->name, - prop->info->description); - } - - op->allow_set = allow_set; - return op; -} - -void object_class_add_static_props(ObjectClass *oc, Property *props, - ObjectPropertyAllowSet allow_set) -{ - Property *prop; - - for (prop = props; prop && prop->name; prop++) { - object_class_property_add_static(oc, prop, allow_set); - } -} - void qdev_property_add_static(DeviceState *dev, Property *prop) { object_property_add_static(OBJECT(dev), prop, qdev_prop_allow_set); diff --git a/qom/static-property.c b/qom/static-property.c new file mode 100644 index 0000000000..a9e0b8a48b --- /dev/null +++ b/qom/static-property.c @@ -0,0 +1,114 @@ +/* + * QOM static property API implementation + */ +#include "qemu/osdep.h" +#include "qom/static-property.h" +#include "qom/static-property-internal.h" + +void *object_static_prop_ptr(Object *obj, Property *prop) +{ + void *ptr = obj; + ptr += prop->offset; + return ptr; +} + +static void static_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); +} + +/** + * static_prop_getter: Return getter function to be used for property + * + * Return value can be NULL if @info has no getter function. + */ +static ObjectPropertyAccessor *static_prop_getter(const PropertyInfo *info) +{ + return info->get ? static_prop_get : NULL; +} + +static void static_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); +} + +/** + * static_prop_setter: Return setter function to be used for property + * + * Return value can be NULL if @info has not setter function. + */ +static ObjectPropertyAccessor *static_prop_setter(const PropertyInfo *info) +{ + return info->set ? static_prop_set : NULL; +} + +ObjectProperty * +object_property_add_static(Object *obj, Property *prop, + ObjectPropertyAllowSet allow_set) +{ + ObjectProperty *op; + + assert(!prop->info->create); + + op = object_property_add(obj, prop->name, prop->info->name, + static_prop_getter(prop->info), + static_prop_setter(prop->info), + prop->info->release, + prop); + + object_property_set_description(obj, prop->name, + prop->info->description); + + if (prop->set_default) { + prop->info->set_default_value(op, prop); + if (op->init) { + op->init(obj, op); + } + } + + op->allow_set = allow_set; + return op; +} + +ObjectProperty * +object_class_property_add_static(ObjectClass *oc, Property *prop, + ObjectPropertyAllowSet allow_set) +{ + ObjectProperty *op; + + if (prop->info->create) { + op = prop->info->create(oc, prop); + } else { + op = object_class_property_add(oc, + prop->name, prop->info->name, + static_prop_getter(prop->info), + static_prop_setter(prop->info), + prop->info->release, + prop); + } + if (prop->set_default) { + prop->info->set_default_value(op, prop); + } + if (prop->info->description) { + object_class_property_set_description(oc, prop->name, + prop->info->description); + } + + op->allow_set = allow_set; + return op; +} + +void object_class_add_static_props(ObjectClass *oc, Property *props, + ObjectPropertyAllowSet allow_set) +{ + Property *prop; + + for (prop = props; prop && prop->name; prop++) { + object_class_property_add_static(oc, prop, allow_set); + } +} diff --git a/qom/meson.build b/qom/meson.build index 062a3789d8..aaebae66b4 100644 --- a/qom/meson.build +++ b/qom/meson.build @@ -4,6 +4,7 @@ qom_ss.add(files( 'object.c', 'object_interfaces.c', 'qom-qobject.c', + 'static-property.c', )) qmp_ss.add(files('qom-qmp-cmds.c')) -- 2.28.0