libnm: add nm_meta_setting_info helpers

This commit is contained in:
Thomas Haller 2021-06-11 15:28:42 +02:00
parent 1b895d98c0
commit 16b01233fa
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 69 additions and 0 deletions

View file

@ -2426,6 +2426,21 @@ _get_settings_sort(gconstpointer p_a, gconstpointer p_b, gpointer unused)
return 0;
}
int
_nmtst_nm_setting_sort(NMSetting *a, NMSetting *b)
{
g_assert(NM_IS_SETTING(a));
g_assert(NM_IS_SETTING(b));
g_assert(a != b);
g_assert(G_OBJECT_TYPE(a) != G_OBJECT_TYPE(b));
NM_CMP_RETURN(_nm_setting_compare_priority(a, b));
NM_CMP_DIRECT_STRCMP(nm_setting_get_name(a), nm_setting_get_name(b));
g_assert_not_reached();
return 0;
}
/**
* nm_connection_get_settings:
* @connection: the #NMConnection instance

View file

@ -132,6 +132,60 @@ struct _NMSettingIPConfigClass {
NMSettingPriority _nm_setting_get_base_type_priority(NMSetting *setting);
int _nm_setting_compare_priority(gconstpointer a, gconstpointer b);
int _nmtst_nm_setting_sort(NMSetting *a, NMSetting *b);
/*****************************************************************************/
#define _nm_assert_setting_info(setting_info, gtype) \
G_STMT_START \
{ \
const NMMetaSettingInfo *_setting_info = (setting_info); \
\
if (NM_MORE_ASSERTS > 0) { \
GType _gtype = (gtype); \
\
nm_assert(_setting_info); \
nm_assert(_NM_INT_NOT_NEGATIVE(_setting_info->meta_type)); \
nm_assert(_setting_info->meta_type < _NM_META_SETTING_TYPE_NUM); \
nm_assert(_setting_info->get_setting_gtype); \
if (_gtype != 0) \
nm_assert(_setting_info->get_setting_gtype() == _gtype); \
else \
_gtype = _setting_info->get_setting_gtype(); \
nm_assert(g_type_is_a(_gtype, NM_TYPE_SETTING)); \
} \
} \
G_STMT_END
static inline const NMMetaSettingInfo *
_nm_meta_setting_info_from_class(NMSettingClass *klass)
{
const NMMetaSettingInfo *setting_info;
if (!NM_IS_SETTING_CLASS(klass))
return NULL;
setting_info = klass->setting_info;
if (!setting_info)
return NULL;
_nm_assert_setting_info(setting_info, G_OBJECT_CLASS_TYPE(klass));
return setting_info;
}
static inline const NMMetaSettingInfo *
_nm_meta_setting_info_from_gtype(GType gtype)
{
const NMMetaSettingInfo *setting_info;
setting_info = nm_meta_setting_infos_by_gtype(gtype);
if (!setting_info)
return NULL;
_nm_assert_setting_info(setting_info, gtype);
return setting_info;
}
/*****************************************************************************/
void _nm_setting_emit_property_changed(NMSetting *setting);