@@ -83,6 +83,29 @@ struct PropertyInfo {
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.
+ *
+ * Note that data pointed by @prop (like strings or pointers to
+ * other structs) are not copied and must have static life time.
+ *
+ * @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
@@ -125,6 +125,20 @@ object_class_property_add_field_static(ObjectClass *oc, const char *name,
return op;
}
+ObjectProperty *
+object_class_property_add_field(ObjectClass *oc, const char *name,
+ Property prop,
+ ObjectPropertyAllowSet allow_set)
+{
+ /*
+ * QOM classes and class properties are never deallocated, so we don't
+ * have a corresponding release function that will free newprop.
+ */
+ Property *newprop = g_new0(Property, 1);
+ *newprop = prop;
+ return object_class_property_add_field_static(oc, name, newprop, allow_set);
+}
+
void object_class_add_field_properties(ObjectClass *oc, Property *props,
ObjectPropertyAllowSet allow_set)
{
It is similar to object_class_property_add_field_static(), but gets a copy of a Property struct so we don't need static variables. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- This is a new patch added in v3 of this series, but v2 had a object_class_property_add_field() function too. This version of object_class_property_add_field() is slightly different from the one in v2, as it gets a copy of the Property struct (so it won't require static variables anymore). --- 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/qom/field-property.h | 23 +++++++++++++++++++++++ qom/field-property.c | 14 ++++++++++++++ 2 files changed, 37 insertions(+)