mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-15 02:10:32 +01:00
libnm: implement "direct" properties for compare_fcn()
This commit is contained in:
parent
dee29e0c1c
commit
b756e058ac
5 changed files with 73 additions and 20 deletions
|
|
@ -1569,13 +1569,13 @@ compare_fcn_id(const NMSettInfoSetting * sett_info,
|
|||
if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_ID))
|
||||
return NM_TERNARY_DEFAULT;
|
||||
|
||||
return _nm_setting_property_compare_fcn_default(sett_info,
|
||||
property_info,
|
||||
con_a,
|
||||
set_a,
|
||||
con_b,
|
||||
set_b,
|
||||
flags);
|
||||
return _nm_setting_property_compare_fcn_direct(sett_info,
|
||||
property_info,
|
||||
con_a,
|
||||
set_a,
|
||||
con_b,
|
||||
set_b,
|
||||
flags);
|
||||
}
|
||||
|
||||
static NMTernary
|
||||
|
|
@ -2022,7 +2022,7 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
|
|||
NM_SETTING_PARAM_INFERRABLE,
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING,
|
||||
.direct_type = NM_VALUE_TYPE_STRING,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_default,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_direct,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
|
||||
.missing_from_dbus_fcn =
|
||||
nm_setting_connection_no_interface_name),
|
||||
|
|
|
|||
|
|
@ -5802,7 +5802,7 @@ _nm_sett_info_property_override_create_array_ip_config(void)
|
|||
obj_properties[PROP_GATEWAY],
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING,
|
||||
.direct_type = NM_VALUE_TYPE_STRING,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_default,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_direct,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
|
||||
.from_dbus_fcn = ip_gateway_set),
|
||||
.direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, gateway),
|
||||
|
|
|
|||
|
|
@ -316,6 +316,14 @@ NMTernary _nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett
|
|||
NMSetting * set_b,
|
||||
NMSettingCompareFlags flags);
|
||||
|
||||
NMTernary _nm_setting_property_compare_fcn_direct(const NMSettInfoSetting * sett_info,
|
||||
const NMSettInfoProperty *property_info,
|
||||
NMConnection * con_a,
|
||||
NMSetting * set_a,
|
||||
NMConnection * con_b,
|
||||
NMSetting * set_b,
|
||||
NMSettingCompareFlags flags);
|
||||
|
||||
NMTernary _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info,
|
||||
const NMSettInfoProperty *property_info,
|
||||
NMConnection * con_a,
|
||||
|
|
|
|||
|
|
@ -1761,6 +1761,44 @@ _nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett_info,
|
|||
return NM_TERNARY_DEFAULT;
|
||||
}
|
||||
|
||||
NMTernary
|
||||
_nm_setting_property_compare_fcn_direct(const NMSettInfoSetting * sett_info,
|
||||
const NMSettInfoProperty *property_info,
|
||||
NMConnection * con_a,
|
||||
NMSetting * set_a,
|
||||
NMConnection * con_b,
|
||||
NMSetting * set_b,
|
||||
NMSettingCompareFlags flags)
|
||||
{
|
||||
gconstpointer p_a;
|
||||
gconstpointer p_b;
|
||||
|
||||
nm_assert(property_info->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct);
|
||||
|
||||
if (!property_info->param_spec)
|
||||
return nm_assert_unreachable_val(NM_TERNARY_DEFAULT);
|
||||
|
||||
if (!_nm_setting_compare_flags_check(property_info->param_spec, flags, set_a, set_b))
|
||||
return NM_TERNARY_DEFAULT;
|
||||
|
||||
if (!set_b)
|
||||
return TRUE;
|
||||
|
||||
p_a = _nm_setting_get_private(set_a, sett_info, property_info->direct_offset);
|
||||
p_b = _nm_setting_get_private(set_b, sett_info, property_info->direct_offset);
|
||||
|
||||
switch (property_info->property_type->direct_type) {
|
||||
case NM_VALUE_TYPE_BOOL:
|
||||
return *((const bool *) p_a) == *((const bool *) p_b);
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
return *((const guint32 *) p_a) == *((const guint32 *) p_b);
|
||||
case NM_VALUE_TYPE_STRING:
|
||||
return nm_streq0(*((const char *const *) p_a), *((const char *const *) p_b));
|
||||
default:
|
||||
return nm_assert_unreachable_val(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
NMTernary
|
||||
_nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info,
|
||||
const NMSettInfoProperty *property_info,
|
||||
|
|
@ -1770,15 +1808,18 @@ _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info,
|
|||
NMSetting * set_b,
|
||||
NMSettingCompareFlags flags)
|
||||
{
|
||||
const GParamSpec *param_spec = property_info->param_spec;
|
||||
nm_assert(property_info->property_type->direct_type == NM_VALUE_TYPE_NONE);
|
||||
|
||||
if (!param_spec)
|
||||
if (!property_info->param_spec)
|
||||
return nm_assert_unreachable_val(NM_TERNARY_DEFAULT);
|
||||
|
||||
if (!_nm_setting_compare_flags_check(param_spec, flags, set_a, set_b))
|
||||
if (!_nm_setting_compare_flags_check(property_info->param_spec, flags, set_a, set_b))
|
||||
return NM_TERNARY_DEFAULT;
|
||||
|
||||
if (set_b) {
|
||||
if (!set_b)
|
||||
return TRUE;
|
||||
|
||||
{
|
||||
gs_unref_variant GVariant *value1 = NULL;
|
||||
gs_unref_variant GVariant *value2 = NULL;
|
||||
|
||||
|
|
@ -1796,11 +1837,8 @@ _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info,
|
|||
NM_CONNECTION_SERIALIZE_ALL,
|
||||
NULL,
|
||||
TRUE);
|
||||
if (nm_property_compare(value1, value2) != 0)
|
||||
return NM_TERNARY_FALSE;
|
||||
return nm_property_compare(value1, value2) == 0;
|
||||
}
|
||||
|
||||
return NM_TERNARY_TRUE;
|
||||
}
|
||||
|
||||
static NMTernary
|
||||
|
|
@ -2784,19 +2822,19 @@ const NMSettInfoPropertType nm_sett_info_propert_type_plain_u =
|
|||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BOOLEAN,
|
||||
.direct_type = NM_VALUE_TYPE_BOOL,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_default,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_direct,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32 =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT32,
|
||||
.direct_type = NM_VALUE_TYPE_UINT32,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_default,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_direct,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_string =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING,
|
||||
.direct_type = NM_VALUE_TYPE_STRING,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_default,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_direct,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -4527,6 +4527,11 @@ check_done:;
|
|||
if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_default) {
|
||||
g_assert(sip->param_spec);
|
||||
g_assert_cmpstr(sip->name, !=, NM_SETTING_NAME);
|
||||
} else if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_direct) {
|
||||
g_assert(sip->param_spec);
|
||||
g_assert(sip->property_type->direct_type != NM_VALUE_TYPE_NONE);
|
||||
g_assert(sip->property_type->to_dbus_fcn
|
||||
== _nm_setting_property_to_dbus_fcn_direct);
|
||||
} else if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_ignore) {
|
||||
if (NM_IN_SET(sip->property_type,
|
||||
&nm_sett_info_propert_type_deprecated_ignore_i,
|
||||
|
|
@ -4546,6 +4551,8 @@ check_done:;
|
|||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
g_assert((sip->property_type->compare_fcn != _nm_setting_property_compare_fcn_direct)
|
||||
|| (sip->property_type->direct_type != NM_VALUE_TYPE_NONE));
|
||||
|
||||
property_types_data = g_hash_table_lookup(h_property_types, sip->property_type);
|
||||
if (!property_types_data) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue