The new helper macros are similar to the old DEFINE_PROP_* macros, but don't take a name argument. They can be used directly as argument to object_class_property_add_field().
The DEFINE_PROP_* macros were redefined to just be wrappers to PROP_*. Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- Changes v2 -> v3: * Now the DEFINE_PROP_* macros are defined using PROP_*, not the other way around * Remove unused macros (PROP_UNSIGNED*, PROP_SIGNED*, PROP_UUID) * Removed PROP_ARRAY because it isn't as trivial as the others * Now PROP_* won't return a pointer to a static variable anymore, but just a compound literal for a Property struct. This is a new patch added in v2 of the series --- Cc: Paolo Bonzini <pbonz...@redhat.com> Cc: "Daniel P. Berrangé" <berra...@redhat.com> Cc: Eduardo Habkost <ehabk...@redhat.com> Cc: qemu-devel@nongnu.org --- include/qom/property-types.h | 141 ++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 51 deletions(-) diff --git a/include/qom/property-types.h b/include/qom/property-types.h index 91b166badf..3132ddafd9 100644 --- a/include/qom/property-types.h +++ b/include/qom/property-types.h @@ -23,6 +23,64 @@ extern const PropertyInfo prop_info_size32; extern const PropertyInfo prop_info_arraylen; extern const PropertyInfo prop_info_link; +#define PROP_SIGNED(_state, _field, _defval, _prop, _type, ...) \ + FIELD_PROP(_state, _field, _prop, _type, \ + .set_default = true, \ + .defval.i = (_type)_defval, \ + __VA_ARGS__) + +#define PROP_UNSIGNED(_state, _field, _defval, _prop, _type, ...) \ + FIELD_PROP(_state, _field, _prop, _type, \ + .set_default = true, \ + .defval.u = (_type)_defval, \ + __VA_ARGS__) + +#define PROP_BIT(_state, _field, _bit, _defval, ...) \ + FIELD_PROP(_state, _field, prop_info_bit, uint32_t, \ + .bitnr = (_bit), \ + .set_default = true, \ + .defval.u = (bool)_defval, \ + __VA_ARGS__) + +#define PROP_BIT64(_state, _field, _bit, _defval, ...) \ + FIELD_PROP(_state, _field, prop_info_bit64, uint64_t, \ + .bitnr = (_bit), \ + .set_default = true, \ + .defval.u = (bool)_defval, \ + __VA_ARGS__) + +#define PROP_BOOL(_state, _field, _defval, ...) \ + FIELD_PROP(_state, _field, prop_info_bool, bool, \ + .set_default = true, \ + .defval.u = (bool)_defval, \ + __VA_ARGS__) + +#define PROP_LINK(_state, _field, _type, _ptr_type, ...) \ + FIELD_PROP(_state, _field, prop_info_link, _ptr_type, \ + .link_type = _type, \ + __VA_ARGS__) + +#define PROP_UINT8(_s, _f, _d, ...) \ + PROP_UNSIGNED(_s, _f, _d, prop_info_uint8, uint8_t, __VA_ARGS__) +#define PROP_UINT16(_s, _f, _d, ...) \ + PROP_UNSIGNED(_s, _f, _d, prop_info_uint16, uint16_t, __VA_ARGS__) +#define PROP_UINT32(_s, _f, _d, ...) \ + PROP_UNSIGNED(_s, _f, _d, prop_info_uint32, uint32_t, __VA_ARGS__) +#define PROP_INT32(_s, _f, _d, ...) \ + PROP_SIGNED(_s, _f, _d, prop_info_int32, int32_t, __VA_ARGS__) +#define PROP_UINT64(_s, _f, _d, ...) \ + PROP_UNSIGNED(_s, _f, _d, prop_info_uint64, uint64_t, __VA_ARGS__) +#define PROP_INT64(_s, _f, _d, ...) \ + PROP_SIGNED(_s, _f, _d, prop_info_int64, int64_t, __VA_ARGS__) +#define PROP_SIZE(_s, _f, _d, ...) \ + PROP_UNSIGNED(_s, _f, _d, prop_info_size, uint64_t, __VA_ARGS__) +#define PROP_STRING(_s, _f, ...) \ + FIELD_PROP(_s, _f, prop_info_string, char*, __VA_ARGS__) +#define PROP_ON_OFF_AUTO(_s, _f, _d, ...) \ + PROP_SIGNED(_s, _f, _d, prop_info_on_off_auto, OnOffAuto, __VA_ARGS__) +#define PROP_SIZE32(_s, _f, _d, ...) \ + PROP_UNSIGNED(_s, _f, _d, prop_info_size32, uint32_t, __VA_ARGS__) + /** * DEFINE_PROP: Define a #Property struct, including a property name * @@ -43,33 +101,6 @@ extern const PropertyInfo prop_info_link; .name_template = (_name), \ __VA_ARGS__) -#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \ - DEFINE_PROP(_name, _state, _field, _prop, _type, \ - .set_default = true, \ - .defval.i = (_type)_defval) - -#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \ - DEFINE_PROP(_name, _state, _field, prop_info_bit, uint32_t, \ - .bitnr = (_bit), \ - .set_default = true, \ - .defval.u = (bool)_defval) - -#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \ - DEFINE_PROP(_name, _state, _field, _prop, _type, \ - .set_default = true, \ - .defval.u = (_type)_defval) - -#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \ - DEFINE_PROP(_name, _state, _field, prop_info_bit64, uint64_t, \ - .bitnr = (_bit), \ - .set_default = true, \ - .defval.u = (bool)_defval) - -#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ - DEFINE_PROP(_name, _state, _field, prop_info_bool, bool, \ - .set_default = true, \ - .defval.u = (bool)_defval) - #define PROP_ARRAY_LEN_PREFIX "len-" /** @@ -106,30 +137,38 @@ extern const PropertyInfo prop_info_link; .arrayfieldsize = sizeof(_arraytype), \ .arrayoffset = offsetof(_state, _arrayfield)) -#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) \ - DEFINE_PROP(_name, _state, _field, prop_info_link, _ptr_type, \ - .link_type = _type) - -#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ - DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint8, uint8_t) -#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ - DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint16, uint16_t) -#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \ - DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint32, uint32_t) -#define DEFINE_PROP_INT32(_n, _s, _f, _d) \ - DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int32, int32_t) -#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \ - DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_uint64, uint64_t) -#define DEFINE_PROP_INT64(_n, _s, _f, _d) \ - DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_int64, int64_t) -#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \ - DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size, uint64_t) -#define DEFINE_PROP_STRING(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, prop_info_string, char*) -#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \ - DEFINE_PROP_SIGNED(_n, _s, _f, _d, prop_info_on_off_auto, OnOffAuto) -#define DEFINE_PROP_SIZE32(_n, _s, _f, _d) \ - DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, prop_info_size32, uint32_t) +#define DEFINE_PROP_SIGNED(_n, ...) \ + PROP_SIGNED(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_BIT(_n, ...) \ + PROP_BIT(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_UNSIGNED(_n, ...) \ + PROP_UNSIGNED(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_BIT64(_n, ...) \ + PROP_BIT64(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_BOOL(_n, ...) \ + PROP_BOOL(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_LINK(_n, ...) \ + PROP_LINK(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_UINT8(_n, ...) \ + PROP_UINT8(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_UINT16(_n, ...) \ + PROP_UINT16(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_UINT32(_n, ...) \ + PROP_UINT32(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_INT32(_n, ...) \ + PROP_INT32(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_UINT64(_n, ...) \ + PROP_UINT64(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_INT64(_n, ...) \ + PROP_INT64(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_SIZE(_n, ...) \ + PROP_SIZE(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_STRING(_n, ...) \ + PROP_STRING(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_ON_OFF_AUTO(_n, ...) \ + PROP_ON_OFF_AUTO(__VA_ARGS__, .name_template = (_n)) +#define DEFINE_PROP_SIZE32(_n, ...) \ + PROP_SIZE32(__VA_ARGS__, .name_template = (_n)) #define DEFINE_PROP_END_OF_LIST() \ {} -- 2.28.0