diff options
author | Thomas Haller <thaller@redhat.com> | 2017-11-22 12:46:58 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-11-27 14:04:11 +0100 |
commit | 51531c953972215e0b15900463378fb8524b4232 (patch) | |
tree | dbfd9234cd28e415df52f2a05ac689ff7fb987e9 /src/settings | |
parent | 3b874554ac4e3267f1b63a58b88239ac6c69282c (diff) | |
download | NetworkManager-51531c953972215e0b15900463378fb8524b4232.tar.gz |
core: merge nm_settings_get_connections_sorted() with nm_settings_get_connections_clone()
Diffstat (limited to 'src/settings')
-rw-r--r-- | src/settings/nm-settings.c | 33 | ||||
-rw-r--r-- | src/settings/nm-settings.h | 7 |
2 files changed, 14 insertions, 26 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 4eeee31554..d52592dd60 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -431,6 +431,9 @@ nm_settings_get_connections (NMSettings *self, guint *out_len) * @out_len: (allow-none): optional output argument * @func: caller-supplied function for filtering connections * @func_data: caller-supplied data passed to @func + * @sort_compare_func: (allow-none): optional function pointer for + * sorting the returned list. + * @sort_data: user data for @sort_compare_func. * * Returns: (transfer container) (element-type NMSettingsConnection): * an NULL terminated array of #NMSettingsConnection objects that were @@ -443,7 +446,9 @@ NMSettingsConnection ** nm_settings_get_connections_clone (NMSettings *self, guint *out_len, NMSettingsConnectionFilterFunc func, - gpointer func_data) + gpointer func_data, + GCompareDataFunc sort_compare_func, + gpointer sort_data) { NMSettingsConnection *const*list_cached; NMSettingsConnection **list; @@ -471,31 +476,15 @@ nm_settings_get_connections_clone (NMSettings *self, } else memcpy (list, list_cached, sizeof (list[0]) * ((gsize) len + 1)); + if ( len > 1 + && sort_compare_func) { + g_qsort_with_data (list, len, sizeof (NMSettingsConnection *), + sort_compare_func, sort_data); + } NM_SET_OUT (out_len, len); return list; } -/* Returns a list of NMSettingsConnections. - * The list is sorted in the order suitable for auto-connecting, i.e. - * first go connections with autoconnect=yes and most recent timestamp. - * Caller must free the list with g_free(), but not the list items. - */ -NMSettingsConnection ** -nm_settings_get_connections_sorted (NMSettings *self, guint *out_len) -{ - NMSettingsConnection **connections; - guint len; - - g_return_val_if_fail (NM_IS_SETTINGS (self), NULL); - - connections = nm_settings_get_connections_clone (self, &len, NULL, NULL); - if (len > 1) - g_qsort_with_data (connections, len, sizeof (NMSettingsConnection *), nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL); - - NM_SET_OUT (out_len, len); - return connections; -} - NMSettingsConnection * nm_settings_get_connection_by_path (NMSettings *self, const char *path) { diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index eede76b029..0e01f6b5fd 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -100,10 +100,9 @@ NMSettingsConnection *const* nm_settings_get_connections (NMSettings *settings, NMSettingsConnection **nm_settings_get_connections_clone (NMSettings *self, guint *out_len, NMSettingsConnectionFilterFunc func, - gpointer func_data); - -NMSettingsConnection **nm_settings_get_connections_sorted (NMSettings *self, - guint *out_len); + gpointer func_data, + GCompareDataFunc sort_compare_func, + gpointer sort_data); NMSettingsConnection *nm_settings_add_connection (NMSettings *settings, NMConnection *connection, |