mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 11:10:09 +01:00
core: add nm_utils_cmp_connection_by_autoconnect_priority_p_with_data() function
Have a proper cmp() function and a wrapper *_p_with_data() that can be used for g_qsort_with_data(). Thus, establish a naming scheme (*_p_with_data()) for these compare wrappers that we need all over the place. Note, we also have nm_strcmp_p_with_data() for the same reason and later more such functions will follow.
This commit is contained in:
parent
f3504c9bc2
commit
eb5ceedbba
4 changed files with 17 additions and 7 deletions
|
|
@ -1976,14 +1976,14 @@ nm_utils_read_resolv_conf_dns_options (const char *rc_contents)
|
|||
}
|
||||
|
||||
int
|
||||
nm_utils_cmp_connection_by_autoconnect_priority (NMConnection **a, NMConnection **b)
|
||||
nm_utils_cmp_connection_by_autoconnect_priority (NMConnection *a, NMConnection *b)
|
||||
{
|
||||
NMSettingConnection *a_s_con, *b_s_con;
|
||||
gboolean a_ac, b_ac;
|
||||
gint a_ap, b_ap;
|
||||
|
||||
a_s_con = nm_connection_get_setting_connection (*a);
|
||||
b_s_con = nm_connection_get_setting_connection (*b);
|
||||
a_s_con = nm_connection_get_setting_connection (a);
|
||||
b_s_con = nm_connection_get_setting_connection (b);
|
||||
|
||||
a_ac = !!nm_setting_connection_get_autoconnect (a_s_con);
|
||||
b_ac = !!nm_setting_connection_get_autoconnect (b_s_con);
|
||||
|
|
@ -2000,6 +2000,15 @@ nm_utils_cmp_connection_by_autoconnect_priority (NMConnection **a, NMConnection
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nm_utils_cmp_connection_by_autoconnect_priority_p_with_data (gconstpointer pa, gconstpointer pb, gpointer user_data)
|
||||
{
|
||||
nm_assert (pa);
|
||||
nm_assert (pb);
|
||||
return nm_utils_cmp_connection_by_autoconnect_priority (*((NMConnection **) pa),
|
||||
*((NMConnection **) pb));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gint64 monotonic_timestamp_offset_sec;
|
||||
|
|
|
|||
|
|
@ -272,7 +272,8 @@ const char *nm_utils_new_infiniband_name (char *name, const char *parent_name, i
|
|||
GPtrArray *nm_utils_read_resolv_conf_nameservers (const char *rc_contents);
|
||||
GPtrArray *nm_utils_read_resolv_conf_dns_options (const char *rc_contents);
|
||||
|
||||
int nm_utils_cmp_connection_by_autoconnect_priority (NMConnection **a, NMConnection **b);
|
||||
int nm_utils_cmp_connection_by_autoconnect_priority (NMConnection *a, NMConnection *b);
|
||||
int nm_utils_cmp_connection_by_autoconnect_priority_p_with_data (gconstpointer pa, gconstpointer pb, gpointer user_data);
|
||||
|
||||
void nm_utils_log_connection_diff (NMConnection *connection, NMConnection *diff_base, guint32 level, guint64 domain, const char *name, const char *prefix);
|
||||
|
||||
|
|
|
|||
|
|
@ -985,7 +985,7 @@ auto_activate_device (NMPolicy *self,
|
|||
|
||||
/* sort is stable (which is important at this point) so that connections
|
||||
* with same priority are still sorted by last-connected-timestamp. */
|
||||
g_ptr_array_sort (connections, (GCompareFunc) nm_utils_cmp_connection_by_autoconnect_priority);
|
||||
g_ptr_array_sort_with_data (connections, nm_utils_cmp_connection_by_autoconnect_priority_p_with_data, NULL);
|
||||
|
||||
/* Find the first connection that should be auto-activated */
|
||||
best_connection = NULL;
|
||||
|
|
|
|||
|
|
@ -892,12 +892,12 @@ _test_connection_sort_autoconnect_priority_one (NMConnection **list, gboolean sh
|
|||
}
|
||||
|
||||
/* sort it... */
|
||||
g_ptr_array_sort (connections, (GCompareFunc) nm_utils_cmp_connection_by_autoconnect_priority);
|
||||
g_ptr_array_sort_with_data (connections, nm_utils_cmp_connection_by_autoconnect_priority_p_with_data, NULL);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (list[i] == connections->pdata[i])
|
||||
continue;
|
||||
if (shuffle && nm_utils_cmp_connection_by_autoconnect_priority (&list[i], (NMConnection **) &connections->pdata[i]) == 0)
|
||||
if (shuffle && nm_utils_cmp_connection_by_autoconnect_priority (list[i], connections->pdata[i]) == 0)
|
||||
continue;
|
||||
g_message ("After sorting, the order of connections is not as expected!! Offending index: %d", i);
|
||||
for (j = 0; j < count; j++)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue