[PATCH v3 49/53] qom: FIELD_PROP macro

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 49/53] qom: FIELD_PROP macro
Posted by Eduardo Habkost 5 years, 2 months ago
The FIELD_PROP macro can be used to define a Property struct when
initializing static variables, or as a function parameter (e.g.
as a paramter to object_class_property_add_field()).

The qdev-specific DEFINE_PROP macro can be defined using the new
macro.  The only difference is that DEFINE_PROP gets the property
name as the first argument.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
This is a new patch added in v3 of this series.
---
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 | 17 +++++++++++++++++
 include/qom/property-types.h | 26 +++++++++++++++++++-------
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/include/qom/field-property.h b/include/qom/field-property.h
index a904f98609..0cb1fe2217 100644
--- a/include/qom/field-property.h
+++ b/include/qom/field-property.h
@@ -108,4 +108,21 @@ object_class_property_add_field(ObjectClass *oc, const char *name,
 
 void *object_field_prop_ptr(Object *obj, Property *prop);
 
+/**
+ * FIELD_PROP: Expands to a compound literal for a #Property struct
+ *
+ * @_state: name of the object state structure type
+ * @_field: name of field in @_state
+ * @_prop: name of #PropertyInfo variable with type information
+ * @_type: expected type of field @_field in struct @_state
+ * @...: additional initializers for #Property struct fields
+ */
+#define FIELD_PROP(_state, _field, _prop, _type, ...) \
+    (Property) {                                                 \
+        .info      = &(_prop),                                   \
+        .offset    = offsetof(_state, _field)                    \
+            + type_check(_type, typeof_field(_state, _field)),   \
+        __VA_ARGS__                                              \
+    }
+
 #endif
diff --git a/include/qom/property-types.h b/include/qom/property-types.h
index 46c82da4e3..62551c77e0 100644
--- a/include/qom/property-types.h
+++ b/include/qom/property-types.h
@@ -23,13 +23,25 @@ extern const PropertyInfo prop_info_size32;
 extern const PropertyInfo prop_info_arraylen;
 extern const PropertyInfo prop_info_link;
 
-#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) {  \
-        .name_template = (_name),                           \
-        .info      = &(_prop),                                   \
-        .offset    = offsetof(_state, _field)                    \
-            + type_check(_type, typeof_field(_state, _field)),   \
-        __VA_ARGS__                                              \
-        }
+/**
+ * DEFINE_PROP: Define a #Property struct, including a property name
+ *
+ * @_name: name of the property
+ * @_state: name of the object state structure type
+ * @_field: name of field in @_state
+ * @_prop: name of #PropertyInfo variable with type information
+ * @_type: expected type of field @_field in struct @_state
+ * @...: additional initializers for #Property struct fields
+ *
+ * `DEFINE_PROP` or other ``DEFINE_PROP_*`` macros are normally
+ * used when initialiing static const #Property arrays, to be
+ * used with object_class_add_field_properties() or
+ * device_class_set_props().
+ */
+#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) \
+    FIELD_PROP(_state, _field, _prop, _type,                  \
+               .name_template = (_name),                      \
+               __VA_ARGS__)
 
 #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
     DEFINE_PROP(_name, _state, _field, _prop, _type,                     \
-- 
2.28.0