diff options
author | Thomas Haller <thaller@redhat.com> | 2019-07-17 11:42:16 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-07-17 12:51:26 +0200 |
commit | 1735a0a8ab2c3912ee5e2f7285d1cede349cfec4 (patch) | |
tree | fc7d7ec9d27ee66df521de3e70a7a5412e696ac5 | |
parent | e1867d917bf1a767f831b9a0b9b720625d4f8d0e (diff) | |
download | NetworkManager-1735a0a8ab2c3912ee5e2f7285d1cede349cfec4.tar.gz |
settings: add nm_settings_plugin_cmp_by_priority() function
Initially I thought I would use this somewhere else. Didn't do so far,
but this seems a useful function to have on its own because also
NMSettings is concerned about the relative priority of plugins.
-rw-r--r-- | src/settings/nm-settings-plugin.c | 26 | ||||
-rw-r--r-- | src/settings/nm-settings-plugin.h | 6 | ||||
-rw-r--r-- | src/settings/nm-settings-storage.c | 25 |
3 files changed, 35 insertions, 22 deletions
diff --git a/src/settings/nm-settings-plugin.c b/src/settings/nm-settings-plugin.c index 8ae1e6528a..09010931e4 100644 --- a/src/settings/nm-settings-plugin.c +++ b/src/settings/nm-settings-plugin.c @@ -42,6 +42,32 @@ G_DEFINE_TYPE (NMSettingsPlugin, nm_settings_plugin, G_TYPE_OBJECT) /*****************************************************************************/ +int +nm_settings_plugin_cmp_by_priority (const NMSettingsPlugin *a, + const NMSettingsPlugin *b, + const GSList *plugin_list) +{ + nm_assert (NM_IS_SETTINGS_PLUGIN (a)); + nm_assert (NM_IS_SETTINGS_PLUGIN (b)); + + if (a != b) { + int idx_a = g_slist_index ((GSList *) plugin_list, a); + int idx_b = g_slist_index ((GSList *) plugin_list, b); + + /* the plugins must be found in the list. */ + nm_assert (idx_a >= 0); + nm_assert (idx_b >= 0); + + /* plugins that appear first in @plugin_list have higher priority. + * That means: smaller index -> higher priority. Reverse sort. */ + NM_CMP_DIRECT (idx_b, idx_a); + } + + return 0; +} + +/*****************************************************************************/ + GSList * nm_settings_plugin_get_unmanaged_specs (NMSettingsPlugin *self) { diff --git a/src/settings/nm-settings-plugin.h b/src/settings/nm-settings-plugin.h index 188614bed7..4df3472e76 100644 --- a/src/settings/nm-settings-plugin.h +++ b/src/settings/nm-settings-plugin.h @@ -196,6 +196,12 @@ void _nm_settings_plugin_emit_signal_unrecognized_specs_changed (NMSettingsPlugi /*****************************************************************************/ +int nm_settings_plugin_cmp_by_priority (const NMSettingsPlugin *a, + const NMSettingsPlugin *b, + const GSList *plugin_list); + +/*****************************************************************************/ + /* forward declare this function from NMSettings. It's used by the ifcfg-rh plugin, * but that shouldn't include all "nm-settings.h" header. */ NMSettings *nm_settings_get (void); diff --git a/src/settings/nm-settings-storage.c b/src/settings/nm-settings-storage.c index c5942c6e02..935b5b48a7 100644 --- a/src/settings/nm-settings-storage.c +++ b/src/settings/nm-settings-storage.c @@ -34,8 +34,6 @@ nm_settings_storage_cmp (NMSettingsStorage *a, const GSList *plugin_list) { NMSettingsStorageClass *klass; - NMSettingsPlugin *plugin_a; - NMSettingsPlugin *plugin_b; /* Sort by priority. * @@ -51,28 +49,11 @@ nm_settings_storage_cmp (NMSettingsStorage *a, NM_CMP_DIRECT (nm_settings_storage_is_keyfile_run (a), nm_settings_storage_is_keyfile_run (b)); - plugin_a = nm_settings_storage_get_plugin (a); - plugin_b = nm_settings_storage_get_plugin (b); - - if (plugin_a != plugin_b) { - int idx_a = g_slist_index ((GSList *) plugin_list, plugin_a); - int idx_b = g_slist_index ((GSList *) plugin_list, plugin_b); - - /* the plugins must be found in the list. */ - nm_assert (idx_a >= 0); - nm_assert (idx_b >= 0); - nm_assert (idx_a != idx_b); - - /* plugins that appear first in @plugin_list have higher priority. - * That means: smaller index -> higher priority. Reverse sort. */ - NM_CMP_DIRECT (idx_b, idx_a); - - /* undecided. We really don't expect unknown plugins here. */ - return 0; - } + NM_CMP_RETURN (nm_settings_plugin_cmp_by_priority (nm_settings_storage_get_plugin (a), + nm_settings_storage_get_plugin (b), + plugin_list)); klass = NM_SETTINGS_STORAGE_GET_CLASS (a); - if (klass != NM_SETTINGS_STORAGE_GET_CLASS (b)) { /* one plugin must return storages of the same type. Otherwise, it's * unclear how cmp_fcn() should compare them. */ |