mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-02 07:40:12 +01:00
core: merge nm_settings_get_connections_sorted() with nm_settings_get_connections_clone()
(cherry picked from commit 51531c9539)
This commit is contained in:
parent
bfd4a70cc3
commit
4b8afb752d
5 changed files with 39 additions and 49 deletions
|
|
@ -1428,8 +1428,8 @@ build_hidden_probe_list (NMDeviceWifi *self)
|
|||
|
||||
connections = nm_settings_get_connections_clone (nm_device_get_settings ((NMDevice *) self),
|
||||
&len,
|
||||
hidden_filter_func,
|
||||
NULL);
|
||||
hidden_filter_func, NULL,
|
||||
NULL, NULL);
|
||||
if (!connections[0])
|
||||
return NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -335,7 +335,9 @@ next_dev:
|
|||
guint i;
|
||||
|
||||
g_return_val_if_fail (priv->connection_uuids, NULL);
|
||||
list = nm_settings_get_connections_sorted (nm_settings_get (), NULL);
|
||||
list = nm_settings_get_connections_clone (nm_settings_get (), NULL,
|
||||
NULL, NULL,
|
||||
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
|
||||
|
||||
for (i = 0; list[i]; i++) {
|
||||
con = list[i];
|
||||
|
|
|
|||
|
|
@ -510,26 +510,16 @@ _get_activatable_connections_filter (NMSettings *settings,
|
|||
return !active_connection_find_first (user_data, connection, NULL, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING);
|
||||
}
|
||||
|
||||
/* Filter out connections that are already active.
|
||||
* nm_settings_get_connections_sorted() returns sorted list. We need to preserve the
|
||||
* order so that we didn't change auto-activation order (recent timestamps
|
||||
* are first).
|
||||
* Caller is responsible for freeing the returned list with g_slist_free().
|
||||
*/
|
||||
NMSettingsConnection **
|
||||
nm_manager_get_activatable_connections (NMManager *manager, guint *out_len, gboolean sort)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||
NMSettingsConnection **connections;
|
||||
guint len;
|
||||
|
||||
connections = nm_settings_get_connections_clone (priv->settings, &len,
|
||||
_get_activatable_connections_filter,
|
||||
manager);
|
||||
if (sort && len > 1)
|
||||
g_qsort_with_data (connections, len, sizeof (connections[0]), nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
|
||||
NM_SET_OUT (out_len, len);
|
||||
return connections;
|
||||
return nm_settings_get_connections_clone (priv->settings, out_len,
|
||||
_get_activatable_connections_filter,
|
||||
manager,
|
||||
sort ? nm_settings_connection_cmp_autoconnect_priority_p_with_data : NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static NMActiveConnection *
|
||||
|
|
@ -1391,7 +1381,9 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
|
|||
}
|
||||
|
||||
/* Create backing resources if the device has any autoconnect connections */
|
||||
connections = nm_settings_get_connections_sorted (priv->settings, NULL);
|
||||
connections = nm_settings_get_connections_clone (priv->settings, NULL,
|
||||
NULL, NULL,
|
||||
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
|
||||
for (i = 0; connections[i]; i++) {
|
||||
NMConnection *candidate = NM_CONNECTION (connections[i]);
|
||||
NMSettingConnection *s_con;
|
||||
|
|
@ -1435,7 +1427,9 @@ retry_connections_for_parent_device (NMManager *self, NMDevice *device)
|
|||
|
||||
g_return_if_fail (device);
|
||||
|
||||
connections = nm_settings_get_connections_sorted (priv->settings, NULL);
|
||||
connections = nm_settings_get_connections_clone (priv->settings, NULL,
|
||||
NULL, NULL,
|
||||
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
|
||||
for (i = 0; connections[i]; i++) {
|
||||
NMConnection *candidate = NM_CONNECTION (connections[i]);
|
||||
gs_free_error GError *error = NULL;
|
||||
|
|
@ -3021,7 +3015,9 @@ find_slaves (NMManager *manager,
|
|||
* even if a slave was already active, it might be deactivated during
|
||||
* master reactivation.
|
||||
*/
|
||||
all_connections = nm_settings_get_connections_sorted (priv->settings, &n_all_connections);
|
||||
all_connections = nm_settings_get_connections_clone (priv->settings, &n_all_connections,
|
||||
NULL, NULL,
|
||||
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
|
||||
for (i = 0; i < n_all_connections; i++) {
|
||||
NMSettingsConnection *master_connection = NULL;
|
||||
NMDevice *master_device = NULL, *slave_device;
|
||||
|
|
@ -4166,7 +4162,9 @@ impl_manager_add_and_activate_connection (NMManager *self,
|
|||
gs_free NMSettingsConnection **connections = NULL;
|
||||
guint i, len;
|
||||
|
||||
connections = nm_settings_get_connections_sorted (priv->settings, &len);
|
||||
connections = nm_settings_get_connections_clone (priv->settings, &len,
|
||||
NULL, NULL,
|
||||
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
|
||||
all_connections = NULL;
|
||||
for (i = len; i > 0; ) {
|
||||
i--;
|
||||
|
|
@ -5225,7 +5223,9 @@ nm_manager_start (NMManager *self, GError **error)
|
|||
* connection-added signals thus devices have to be created manually.
|
||||
*/
|
||||
_LOGD (LOGD_CORE, "creating virtual devices...");
|
||||
connections = nm_settings_get_connections_sorted (priv->settings, NULL);
|
||||
connections = nm_settings_get_connections_clone (priv->settings, NULL,
|
||||
NULL, NULL,
|
||||
nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
|
||||
for (i = 0; connections[i]; i++)
|
||||
connection_changed (self, NM_CONNECTION (connections[i]));
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue