@@ -2,52 +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 {
- /**
- * @qdev_prop_name: qdev property name
- *
- * qdev_prop_name is used only by TYPE_DEVICE code
- * (device_class_set_props(), qdev_class_add_property(), and
- * others).
- */
- const char *qdev_prop_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, const char *name,
- Property *prop);
- ObjectPropertyAccessor *get;
- ObjectPropertyAccessor *set;
- ObjectPropertyRelease *release;
-};
-
+#include "qom/field-property.h"
/*** qdev-properties.c ***/
@@ -227,28 +182,6 @@ extern const PropertyInfo prop_info_link;
#define PROP_END_OF_LIST(...) \
FIELD_PROP(DEFINE_PROP_END_OF_LIST(NULL, __VA_ARGS__))
-/**
- * object_class_property_add_field: Add a field property to object class
- * @oc: object class
- * @name: property name
- * @prop: property definition
- * @allow_set: check function called when property is set
- *
- * Add a field property to an object class. A field property is
- * a property that will change a field at a specific offset of the
- * object instance struct.
- *
- * *@prop must exist for the life time of @oc.
- *
- * @allow_set should not be NULL. If the property can always be
- * set, `prop_allow_set_always` can be used. If the property can
- * never be set, `prop_allow_set_never` can be used.
- */
-ObjectProperty *
-object_class_property_add_field(ObjectClass *oc, const char *name,
- Property *prop,
- ObjectPropertyAllowSet allow_set);
-
/*
* Set properties between creation and realization.
*
@@ -276,8 +209,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_field_prop_ptr(Object *obj, Property *prop);
-
void qdev_prop_register_global(GlobalProperty *prop);
const GlobalProperty *qdev_find_global_prop(Object *obj,
const char *name);
similarity index 91%
rename from hw/core/qdev-prop-internal.h
rename to include/qom/field-property-internal.h
@@ -1,12 +1,12 @@
/*
- * qdev property parsing
+ * QOM field 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 field_prop_get_enum(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp);
new file mode 100644
@@ -0,0 +1,79 @@
+/*
+ * QOM field property API
+ */
+#ifndef QOM_FIELD_PROPERTY_H
+#define QOM_FIELD_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 {
+ /**
+ * @qdev_prop_name: qdev property name
+ *
+ * qdev_prop_name is used only by TYPE_DEVICE code
+ * (device_class_set_props(), qdev_class_add_property(), and
+ * others).
+ */
+ const char *qdev_prop_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, const char *name,
+ Property *prop);
+ ObjectPropertyAccessor *get;
+ ObjectPropertyAccessor *set;
+ ObjectPropertyRelease *release;
+};
+
+/**
+ * object_class_property_add_field: Add a field property to object class
+ * @oc: object class
+ * @name: property name
+ * @prop: property definition
+ * @allow_set: check function called when property is set
+ *
+ * Add a field property to an object class. A field property is
+ * a property that will change a field at a specific offset of the
+ * object instance struct.
+ *
+ * *@prop must exist for the life time of @oc.
+ *
+ * @allow_set should not be NULL. If the property can always be
+ * set, `prop_allow_set_always` can be used. If the property can
+ * never be set, `prop_allow_set_never` can be used.
+ */
+ObjectProperty *
+object_class_property_add_field(ObjectClass *oc, const char *name,
+ Property *prop,
+ ObjectPropertyAllowSet allow_set);
+
+void *object_field_prop_ptr(Object *obj, Property *prop);
+
+#endif
@@ -24,7 +24,7 @@
#include "qemu/units.h"
#include "qemu/uuid.h"
#include "qemu/error-report.h"
-#include "qdev-prop-internal.h"
+#include "qom/field-property-internal.h"
#include "audio/audio.h"
#include "chardev/char-fe.h"
@@ -8,7 +8,7 @@
#include "qapi/visitor.h"
#include "qemu/units.h"
#include "qemu/cutils.h"
-#include "qdev-prop-internal.h"
+#include "qom/field-property-internal.h"
void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
Error **errp)
@@ -50,48 +50,6 @@ void qdev_prop_allow_set_link_before_realize(const Object *obj,
}
}
-void *object_field_prop_ptr(Object *obj, Property *prop)
-{
- void *ptr = obj;
- ptr += prop->offset;
- 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 field_prop_get_enum(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -801,66 +759,6 @@ const PropertyInfo prop_info_link = {
.create = create_link_property,
};
-ObjectProperty *
-object_property_add_field(Object *obj, const char *name, Property *prop,
- ObjectPropertyAllowSet allow_set)
-{
- ObjectProperty *op;
-
- assert(allow_set);
- assert(!prop->info->create);
-
- op = object_property_add(obj, name, prop->info->name,
- field_prop_getter(prop->info),
- field_prop_setter(prop->info),
- prop->info->release,
- prop);
-
- object_property_set_description(obj, 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_field(ObjectClass *oc, const char *name,
- Property *prop,
- ObjectPropertyAllowSet allow_set)
-{
- ObjectProperty *op;
-
- assert(allow_set);
-
- if (prop->info->create) {
- op = prop->info->create(oc, name, prop);
- } else {
- op = object_class_property_add(oc,
- name, prop->info->name,
- field_prop_getter(prop->info),
- field_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, name,
- prop->info->description);
- }
-
- op->allow_set = allow_set;
- return op;
-}
-
void qdev_property_add_static(DeviceState *dev, Property *prop)
{
object_property_add_field(OBJECT(dev), prop->qdev_prop_name, prop,
new file mode 100644
@@ -0,0 +1,108 @@
+/*
+ * QOM field property API implementation
+ */
+#include "qemu/osdep.h"
+#include "qom/field-property.h"
+#include "qom/field-property-internal.h"
+
+void *object_field_prop_ptr(Object *obj, Property *prop)
+{
+ void *ptr = obj;
+ ptr += prop->offset;
+ 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;
+}
+
+ObjectProperty *
+object_property_add_field(Object *obj, const char *name, Property *prop,
+ ObjectPropertyAllowSet allow_set)
+{
+ ObjectProperty *op;
+
+ assert(allow_set);
+ assert(!prop->info->create);
+
+ op = object_property_add(obj, name, prop->info->name,
+ field_prop_getter(prop->info),
+ field_prop_setter(prop->info),
+ prop->info->release,
+ prop);
+
+ object_property_set_description(obj, 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_field(ObjectClass *oc, const char *name,
+ Property *prop,
+ ObjectPropertyAllowSet allow_set)
+{
+ ObjectProperty *op;
+
+ assert(allow_set);
+
+ if (prop->info->create) {
+ op = prop->info->create(oc, name, prop);
+ } else {
+ op = object_class_property_add(oc,
+ name, prop->info->name,
+ field_prop_getter(prop->info),
+ field_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, name,
+ prop->info->description);
+ }
+
+ op->allow_set = allow_set;
+ return op;
+}
@@ -4,6 +4,7 @@ qom_ss.add(files(
'object.c',
'object_interfaces.c',
'qom-qobject.c',
+ 'field-property.c',
))
qmp_ss.add(files('qom-qmp-cmds.c'))
Move the core of the static property code to qom/field-property.c. The actual property type implementations are still in qdev-properties.c, they will be moved later. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Changes v1 -> v2: * Rename static-property.* to field-property.* --- Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: "Daniel P. Berrangé" <berrange@redhat.com> Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: qemu-devel@nongnu.org --- include/hw/qdev-properties.h | 71 +----------- .../qom/field-property-internal.h | 6 +- include/qom/field-property.h | 79 +++++++++++++ hw/core/qdev-properties-system.c | 2 +- hw/core/qdev-properties.c | 104 +---------------- qom/field-property.c | 108 ++++++++++++++++++ qom/meson.build | 1 + 7 files changed, 194 insertions(+), 177 deletions(-) rename hw/core/qdev-prop-internal.h => include/qom/field-property-internal.h (91%) create mode 100644 include/qom/field-property.h create mode 100644 qom/field-property.c