[PATCH v3 48/53] qom: object_class_property_add_field() function

Eduardo Habkost posted 53 patches 5 years, 2 months ago
Maintainers: Halil Pasic <pasic@linux.ibm.com>, Gerd Hoffmann <kraxel@redhat.com>, Antony Pavlov <antonynpavlov@gmail.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Michael Rolnik <mrolnik@gmail.com>, Magnus Damm <magnus.damm@gmail.com>, John Snow <jsnow@redhat.com>, Alistair Francis <alistair@alistair23.me>, Michael Walle <michael@walle.cc>, Joel Stanley <joel@jms.id.au>, Fabien Chouteau <chouteau@adacore.com>, "Cédric Le Goater" <clg@kaod.org>, Alberto Garcia <berto@igalia.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, "Michael S. Tsirkin" <mst@redhat.com>, Andrzej Zaborowski <balrogg@gmail.com>, Max Reitz <mreitz@redhat.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, David Gibson <david@gibson.dropbear.id.au>, "Daniel P. Berrangé" <berrange@redhat.com>, Yuval Shaia <yuval.shaia.ml@gmail.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>, Kevin Wolf <kwolf@redhat.com>, Sarah Harris <S.E.Harris@kent.ac.uk>, Corey Minyard <minyard@acm.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Paul Durrant <paul@xen.org>, Christian Borntraeger <borntraeger@de.ibm.com>, Alex Williamson <alex.williamson@redhat.com>, Andrew Baumann <Andrew.Baumann@microsoft.com>, Ben Warren <ben@skyportsystems.com>, Jiri Pirko <jiri@resnulli.us>, Cornelia Huck <cohuck@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Fam Zheng <fam@euphon.net>, Igor Mitsyanko <i.mitsyanko@gmail.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, KONRAD Frederic <frederic.konrad@adacore.com>, Laurent Vivier <lvivier@redhat.com>, Amit Shah <amit@kernel.org>, Raphael Norwitz <raphael.norwitz@nutanix.com>, Eduardo Habkost <ehabkost@redhat.com>, Thomas Huth <huth@tuxfamily.org>, Anthony Perard <anthony.perard@citrix.com>, Richard Henderson <rth@twiddle.net>, Eric Auger <eric.auger@redhat.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Jason Wang <jasowang@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Peter Chubb <peter.chubb@nicta.com.au>, Beniamino Galvani <b.galvani@gmail.com>, Igor Mammedov <imammedo@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Juan Quintela <quintela@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Peter Maydell <peter.maydell@linaro.org>
[PATCH v3 48/53] qom: object_class_property_add_field() function
Posted by Eduardo Habkost 5 years, 2 months ago
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(+)

diff --git a/include/qom/field-property.h b/include/qom/field-property.h
index 419e5eef75..a904f98609 100644
--- a/include/qom/field-property.h
+++ b/include/qom/field-property.h
@@ -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
diff --git a/qom/field-property.c b/qom/field-property.c
index 1fd11f2ad3..cb729626ce 100644
--- a/qom/field-property.c
+++ b/qom/field-property.c
@@ -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)
 {
-- 
2.28.0