diff options
author | Thomas Haller <thaller@redhat.com> | 2019-01-09 09:08:39 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-01-11 11:48:47 +0100 |
commit | 885c872d5a542f820afdf4e8ca59c55f39467c7a (patch) | |
tree | 1982a91850189b7b13ba9c309c26236fae2b2e8f /libnm-core/nm-setting-user.c | |
parent | 5aace3dfea61b2409d6b62127853bd5ed4721bf2 (diff) | |
download | NetworkManager-885c872d5a542f820afdf4e8ca59c55f39467c7a.tar.gz |
libnm: rework compare_property() implementation for NMSetting
NMSetting's compare_property() has and had two callers:
nm_setting_compare() and nm_setting_diff().
compare_property() accepts a NMSettingCompareFlags argument, but
at the same time, both callers have another complex (and
inconsistent!) set of pre-checks for shortcuting the call of
compare_property(): should_compare_prop().
Merge should_compare_prop() into compare_property(). This way,
nm_setting_compare() and nm_setting_diff() has less additional
code, and are simpler to follow. Especially nm_setting_compare()
is now trivial. And nm_setting_diff() is still complicated, but
not related to the question how the property compares or whether
it should be compared at all.
If you want to know whether it should be compared, all you need to do
now is follow NMSettingClass.compare_property().
This changes function pointer NMSettingClass.compare_property(),
which is public API. However, no user can actually use this (and shall
not!), because _nm_setting_class_commit_full() etc. is private API. A
user outside of libnm-core cannot create his/her own subclasses of
NMSetting, and never could in the past. So, this API/ABI change doesn't
matter.
Diffstat (limited to 'libnm-core/nm-setting-user.c')
-rw-r--r-- | libnm-core/nm-setting-user.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index d72c909462..cef02092c8 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -395,33 +395,34 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return TRUE; } -static gboolean -compare_property (NMSetting *setting, +static NMTernary +compare_property (const NMSettInfoSetting *sett_info, + guint property_idx, + NMSetting *setting, NMSetting *other, - const GParamSpec *prop_spec, NMSettingCompareFlags flags) { NMSettingUserPrivate *priv, *pri2; - g_return_val_if_fail (NM_IS_SETTING_USER (setting), FALSE); - g_return_val_if_fail (NM_IS_SETTING_USER (other), FALSE); - - if (!nm_streq0 (prop_spec->name, NM_SETTING_USER_DATA)) - goto call_parent; + if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_USER_DATA)) { - priv = NM_SETTING_USER_GET_PRIVATE (NM_SETTING_USER (setting)); - pri2 = NM_SETTING_USER_GET_PRIVATE (NM_SETTING_USER (other)); - - if (!nm_utils_hash_table_equal (priv->data, pri2->data, TRUE, g_str_equal)) - return FALSE; + if (NM_FLAGS_HAS (flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) + return NM_TERNARY_DEFAULT; - if (!nm_utils_hash_table_equal (priv->data_invalid, pri2->data_invalid, TRUE, g_str_equal)) - return FALSE; + if (!other) + return TRUE; - return TRUE; + priv = NM_SETTING_USER_GET_PRIVATE (NM_SETTING_USER (setting)); + pri2 = NM_SETTING_USER_GET_PRIVATE (NM_SETTING_USER (other)); + return nm_utils_hash_table_equal (priv->data, pri2->data, TRUE, g_str_equal) + && nm_utils_hash_table_equal (priv->data_invalid, pri2->data_invalid, TRUE, g_str_equal); + } -call_parent: - return NM_SETTING_CLASS (nm_setting_user_parent_class)->compare_property (setting, other, prop_spec, flags); + return NM_SETTING_CLASS (nm_setting_user_parent_class)->compare_property (sett_info, + property_idx, + setting, + other, + flags); } /*****************************************************************************/ |