[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 49/53] qom: FIELD_PROP macro
From: |
Eduardo Habkost |
Subject: |
[PATCH v3 49/53] qom: FIELD_PROP macro |
Date: |
Thu, 12 Nov 2020 16:43:46 -0500 |
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
- [PATCH v3 39/53] qdev: Get rid of ArrayElementProperty struct, (continued)
- [PATCH v3 39/53] qdev: Get rid of ArrayElementProperty struct, Eduardo Habkost, 2020/11/12
- [PATCH v3 40/53] qdev: Rename array_element_release() to static_prop_release_dynamic_prop(), Eduardo Habkost, 2020/11/12
- [PATCH v3 41/53] qdev: Make object_property_add_field() copy the Property struct, Eduardo Habkost, 2020/11/12
- [PATCH v3 44/53] qom: Add new qom.h header, Eduardo Habkost, 2020/11/12
- [PATCH v3 43/53] qdev: Move static_prop_release_dynamic_prop() closer to its usage, Eduardo Habkost, 2020/11/12
- [PATCH v3 42/53] qdev: Reuse object_property_add_field() when adding array elements, Eduardo Habkost, 2020/11/12
- [PATCH v3 45/53] qdev: Move core field property code to QOM, Eduardo Habkost, 2020/11/12
- [PATCH v3 46/53] qdev: Move base property types to qom/property-types.c, Eduardo Habkost, 2020/11/12
- [PATCH v3 47/53] qom: Include static property API reference in documentation, Eduardo Habkost, 2020/11/12
- [PATCH v3 48/53] qom: object_class_property_add_field() function, Eduardo Habkost, 2020/11/12
- [PATCH v3 49/53] qom: FIELD_PROP macro,
Eduardo Habkost <=
- [PATCH v3 50/53] qom: Delete DEFINE_PROP_*SIGNED_NODEFAULT macro, Eduardo Habkost, 2020/11/12
- [PATCH v3 52/53] tests: Use field property at check-qom-proplist test case, Eduardo Habkost, 2020/11/12
- [PATCH v3 51/53] qom: PROP_* macros, Eduardo Habkost, 2020/11/12
- [PATCH v3 53/53] sev: Use class properties, Eduardo Habkost, 2020/11/12