From da743663c3292b44bf0e3b4a4a4a3b813730cc85 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2024 10:00:50 +0100 Subject: [PATCH] dbus: add helper macros for GDBusAnnotationInfo --- src/core/nm-dbus-utils.c | 12 ++++++++ src/core/nm-dbus-utils.h | 59 +++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/core/nm-dbus-utils.c b/src/core/nm-dbus-utils.c index 05eca84faa..0a1be4a2b6 100644 --- a/src/core/nm-dbus-utils.c +++ b/src/core/nm-dbus-utils.c @@ -11,6 +11,18 @@ /*****************************************************************************/ +const GDBusAnnotationInfo _nm_gdbus_annotation_info_deprecated = { + .key = "org.freedesktop.DBus.Deprecated", + .value = "true", +}; + +const GDBusAnnotationInfo *const _nm_gdbus_annotation_info_list_deprecated[] = { + NM_GDBUS_ANNOTATION_INFO_DEPRECATED(), + NULL, +}; + +/*****************************************************************************/ + GDBusPropertyInfo * nm_dbus_utils_interface_info_lookup_property(const GDBusInterfaceInfo *interface_info, const char *property_name, diff --git a/src/core/nm-dbus-utils.h b/src/core/nm-dbus-utils.h index 54b506343e..237b37d857 100644 --- a/src/core/nm-dbus-utils.h +++ b/src/core/nm-dbus-utils.h @@ -45,34 +45,55 @@ typedef struct { G_STATIC_ASSERT(G_STRUCT_OFFSET(NMDBusPropertyInfoExtended, property_name) == G_STRUCT_OFFSET(struct _NMDBusPropertyInfoExtendedBase, property_name)); -#define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE(m_name, m_signature, m_property_name) \ - ((GDBusPropertyInfo *) &((const struct _NMDBusPropertyInfoExtendedBase){ \ - ._parent = \ - { \ - .ref_count = -1, \ - .name = m_name, \ - .signature = m_signature, \ - .flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE, \ - }, \ - .property_name = m_property_name, \ +extern const GDBusAnnotationInfo _nm_gdbus_annotation_info_deprecated; + +#define NM_GDBUS_ANNOTATION_INFO_DEPRECATED() \ + ((GDBusAnnotationInfo *) &_nm_gdbus_annotation_info_deprecated) + +#define NM_DEFINE_DBUS_ANNOTATION_INFO(a_key, a_value) \ + ((GDBusAnnotationInfo *) &((const GDBusAnnotationInfo){ \ + .key = (a_key), \ + .value = (a_value), \ + })) + +extern const GDBusAnnotationInfo *const _nm_gdbus_annotation_info_list_deprecated[]; + +/* This is a (NULL terminated) list of GDBusAnnotationInfo with only one entry: + * NM_GDBUS_ANNOTATION_INFO_DEPRECATED. This single instance can be reused for the + * common case where we only have one annotation (and it's the deprecation). + * + * Otherwise, NM_DEFINE_DBUS_ANNOTATION_INFOS() is for defining a new list. */ +#define NM_GDBUS_ANNOTATION_INFO_LIST_DEPRECATED() \ + ((GDBusAnnotationInfo **) _nm_gdbus_annotation_info_list_deprecated) + +#define NM_DEFINE_DBUS_ANNOTATION_INFOS(...) \ + ((GDBusAnnotationInfo **) ((const GDBusAnnotationInfo *const[]){__VA_ARGS__, NULL})) + +#define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE(m_name, m_signature, m_property_name, ...) \ + ((GDBusPropertyInfo *) &((const struct _NMDBusPropertyInfoExtendedBase){ \ + ._parent = {.ref_count = -1, \ + .name = m_name, \ + .signature = m_signature, \ + .flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE, \ + __VA_ARGS__}, \ + .property_name = m_property_name, \ })) #define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READWRITABLE(m_name, \ m_signature, \ m_property_name, \ m_permission, \ - m_audit_op) \ + m_audit_op, \ + ...) \ ((GDBusPropertyInfo *) &((const struct _NMDBusPropertyInfoExtendedReadWritable){ \ ._base = \ { \ - ._parent = \ - { \ - .ref_count = -1, \ - .name = m_name, \ - .signature = m_signature, \ - .flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE \ - | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, \ - }, \ + ._parent = {.ref_count = -1, \ + .name = m_name, \ + .signature = m_signature, \ + .flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE \ + | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, \ + __VA_ARGS__}, \ .property_name = m_property_name, \ }, \ .permission = m_permission, \