mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 04:48:10 +02: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),
|
connections = nm_settings_get_connections_clone (nm_device_get_settings ((NMDevice *) self),
|
||||||
&len,
|
&len,
|
||||||
hidden_filter_func,
|
hidden_filter_func, NULL,
|
||||||
NULL);
|
NULL, NULL);
|
||||||
if (!connections[0])
|
if (!connections[0])
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -335,7 +335,9 @@ next_dev:
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_return_val_if_fail (priv->connection_uuids, NULL);
|
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++) {
|
for (i = 0; list[i]; i++) {
|
||||||
con = list[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);
|
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 **
|
NMSettingsConnection **
|
||||||
nm_manager_get_activatable_connections (NMManager *manager, guint *out_len, gboolean sort)
|
nm_manager_get_activatable_connections (NMManager *manager, guint *out_len, gboolean sort)
|
||||||
{
|
{
|
||||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||||
NMSettingsConnection **connections;
|
|
||||||
guint len;
|
|
||||||
|
|
||||||
connections = nm_settings_get_connections_clone (priv->settings, &len,
|
return nm_settings_get_connections_clone (priv->settings, out_len,
|
||||||
_get_activatable_connections_filter,
|
_get_activatable_connections_filter,
|
||||||
manager);
|
manager,
|
||||||
if (sort && len > 1)
|
sort ? nm_settings_connection_cmp_autoconnect_priority_p_with_data : NULL,
|
||||||
g_qsort_with_data (connections, len, sizeof (connections[0]), nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
|
NULL);
|
||||||
NM_SET_OUT (out_len, len);
|
|
||||||
return connections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NMActiveConnection *
|
static NMActiveConnection *
|
||||||
|
|
@ -1391,7 +1381,9 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create backing resources if the device has any autoconnect connections */
|
/* 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++) {
|
for (i = 0; connections[i]; i++) {
|
||||||
NMConnection *candidate = NM_CONNECTION (connections[i]);
|
NMConnection *candidate = NM_CONNECTION (connections[i]);
|
||||||
NMSettingConnection *s_con;
|
NMSettingConnection *s_con;
|
||||||
|
|
@ -1435,7 +1427,9 @@ retry_connections_for_parent_device (NMManager *self, NMDevice *device)
|
||||||
|
|
||||||
g_return_if_fail (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++) {
|
for (i = 0; connections[i]; i++) {
|
||||||
NMConnection *candidate = NM_CONNECTION (connections[i]);
|
NMConnection *candidate = NM_CONNECTION (connections[i]);
|
||||||
gs_free_error GError *error = NULL;
|
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
|
* even if a slave was already active, it might be deactivated during
|
||||||
* master reactivation.
|
* 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++) {
|
for (i = 0; i < n_all_connections; i++) {
|
||||||
NMSettingsConnection *master_connection = NULL;
|
NMSettingsConnection *master_connection = NULL;
|
||||||
NMDevice *master_device = NULL, *slave_device;
|
NMDevice *master_device = NULL, *slave_device;
|
||||||
|
|
@ -4166,7 +4162,9 @@ impl_manager_add_and_activate_connection (NMManager *self,
|
||||||
gs_free NMSettingsConnection **connections = NULL;
|
gs_free NMSettingsConnection **connections = NULL;
|
||||||
guint i, len;
|
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;
|
all_connections = NULL;
|
||||||
for (i = len; i > 0; ) {
|
for (i = len; i > 0; ) {
|
||||||
i--;
|
i--;
|
||||||
|
|
@ -5225,7 +5223,9 @@ nm_manager_start (NMManager *self, GError **error)
|
||||||
* connection-added signals thus devices have to be created manually.
|
* connection-added signals thus devices have to be created manually.
|
||||||
*/
|
*/
|
||||||
_LOGD (LOGD_CORE, "creating virtual devices...");
|
_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++)
|
for (i = 0; connections[i]; i++)
|
||||||
connection_changed (self, NM_CONNECTION (connections[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
|
* @out_len: (allow-none): optional output argument
|
||||||
* @func: caller-supplied function for filtering connections
|
* @func: caller-supplied function for filtering connections
|
||||||
* @func_data: caller-supplied data passed to @func
|
* @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):
|
* Returns: (transfer container) (element-type NMSettingsConnection):
|
||||||
* an NULL terminated array of #NMSettingsConnection objects that were
|
* an NULL terminated array of #NMSettingsConnection objects that were
|
||||||
|
|
@ -443,7 +446,9 @@ NMSettingsConnection **
|
||||||
nm_settings_get_connections_clone (NMSettings *self,
|
nm_settings_get_connections_clone (NMSettings *self,
|
||||||
guint *out_len,
|
guint *out_len,
|
||||||
NMSettingsConnectionFilterFunc func,
|
NMSettingsConnectionFilterFunc func,
|
||||||
gpointer func_data)
|
gpointer func_data,
|
||||||
|
GCompareDataFunc sort_compare_func,
|
||||||
|
gpointer sort_data)
|
||||||
{
|
{
|
||||||
NMSettingsConnection *const*list_cached;
|
NMSettingsConnection *const*list_cached;
|
||||||
NMSettingsConnection **list;
|
NMSettingsConnection **list;
|
||||||
|
|
@ -471,31 +476,15 @@ nm_settings_get_connections_clone (NMSettings *self,
|
||||||
} else
|
} else
|
||||||
memcpy (list, list_cached, sizeof (list[0]) * ((gsize) len + 1));
|
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);
|
NM_SET_OUT (out_len, len);
|
||||||
return list;
|
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 *
|
NMSettingsConnection *
|
||||||
nm_settings_get_connection_by_path (NMSettings *self, const char *path)
|
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,
|
NMSettingsConnection **nm_settings_get_connections_clone (NMSettings *self,
|
||||||
guint *out_len,
|
guint *out_len,
|
||||||
NMSettingsConnectionFilterFunc func,
|
NMSettingsConnectionFilterFunc func,
|
||||||
gpointer func_data);
|
gpointer func_data,
|
||||||
|
GCompareDataFunc sort_compare_func,
|
||||||
NMSettingsConnection **nm_settings_get_connections_sorted (NMSettings *self,
|
gpointer sort_data);
|
||||||
guint *out_len);
|
|
||||||
|
|
||||||
NMSettingsConnection *nm_settings_add_connection (NMSettings *settings,
|
NMSettingsConnection *nm_settings_add_connection (NMSettings *settings,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue