@@ -27,4 +27,15 @@ void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp);
+/**
+ * object_property_add_static: Add a static property to an object instance
+ * @obj: object instance
+ * @prop: property definition
+ *
+ * This function should not be used in new code. Please add class properties
+ * instead, using object_class_add_static_props().
+ */
+ObjectProperty *
+object_property_add_static(Object *obj, Property *prop);
+
#endif
@@ -275,6 +275,30 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
#define DEFINE_PROP_END_OF_LIST() \
{}
+/**
+ * object_class_property_add_static: Add a static property to object class
+ * @oc: object class
+ * @prop: property definition
+ *
+ * Add a property to an object class based on the property definition
+ * at @prop.
+ *
+ * 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);
+
+/**
+ * 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()
+ *
+ * Add properties from @props using object_class_property_add_static()
+ */
+void object_class_add_static_props(ObjectClass *oc, Property *props);
+
/*
* Set properties between creation and realization.
*
@@ -885,9 +885,9 @@ const PropertyInfo qdev_prop_link = {
.create = create_link_property,
};
-void qdev_property_add_static(DeviceState *dev, Property *prop)
+ObjectProperty *
+object_property_add_static(Object *obj, Property *prop)
{
- Object *obj = OBJECT(dev);
ObjectProperty *op;
assert(!prop->info->create);
@@ -907,11 +907,13 @@ void qdev_property_add_static(DeviceState *dev, Property *prop)
op->init(obj, op);
}
}
+
+ return op;
}
-static void qdev_class_add_property(DeviceClass *klass, Property *prop)
+ObjectProperty *
+object_class_property_add_static(ObjectClass *oc, Property *prop)
{
- ObjectClass *oc = OBJECT_CLASS(klass);
ObjectProperty *op;
if (prop->info->create) {
@@ -931,6 +933,21 @@ static void qdev_class_add_property(DeviceClass *klass, Property *prop)
object_class_property_set_description(oc, prop->name,
prop->info->description);
}
+ return op;
+}
+
+void object_class_add_static_props(ObjectClass *oc, Property *props)
+{
+ Property *prop;
+
+ for (prop = props; prop && prop->name; prop++) {
+ object_class_property_add_static(oc, prop);
+ }
+}
+
+void qdev_property_add_static(DeviceState *dev, Property *prop)
+{
+ object_property_add_static(OBJECT(dev), prop);
}
/**
@@ -979,16 +996,19 @@ static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop)
NULL, NULL, prop);
}
-void device_class_set_props(DeviceClass *dc, Property *props)
+static void qdev_class_add_legacy_properties(DeviceClass *dc, Property *props)
{
Property *prop;
-
- dc->props_ = props;
for (prop = props; prop && prop->name; prop++) {
qdev_class_add_legacy_property(dc, prop);
- qdev_class_add_property(dc, prop);
}
}
+void device_class_set_props(DeviceClass *dc, Property *props)
+{
+ dc->props_ = props;
+ qdev_class_add_legacy_properties(dc, props);
+ object_class_add_static_props(OBJECT_CLASS(dc), props);
+}
void qdev_alias_all_properties(DeviceState *target, Object *source)
{
qdev_class_add_property() and qdev_property_add_static() will have code that's specific for device types. object_class_property_add_static(), object_class_add_static_props(), and object_property_add_static() will be generic and part of the QOM static property API. The declarations for the new functions are being added to qdev-properties.h, but they will be moved to a QOM header later. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: "Daniel P. Berrangé" <berrange@redhat.com> Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: qemu-devel@nongnu.org --- hw/core/qdev-prop-internal.h | 11 +++++++++++ include/hw/qdev-properties.h | 24 ++++++++++++++++++++++++ hw/core/qdev-properties.c | 36 ++++++++++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 8 deletions(-)