diff options
author | Thomas Haller <thaller@redhat.com> | 2017-02-03 15:38:58 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-02-10 14:43:24 +0100 |
commit | eb5ceedbba87e5ea4d2b32ecc3e84f930c3d9835 (patch) | |
tree | 604054eb45c2ecb86669b96b185f47ac876e9aef | |
parent | f3504c9bc214aa32f7a498a1adb48b840be8809a (diff) | |
download | NetworkManager-eb5ceedbba87e5ea4d2b32ecc3e84f930c3d9835.tar.gz |
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.
-rw-r--r-- | src/nm-core-utils.c | 15 | ||||
-rw-r--r-- | src/nm-core-utils.h | 3 | ||||
-rw-r--r-- | src/nm-policy.c | 2 | ||||
-rw-r--r-- | src/tests/test-general.c | 4 |
4 files changed, 17 insertions, 7 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 352bde8a54..29c26ba817 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -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; diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index e039760e09..82e10132b3 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -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); diff --git a/src/nm-policy.c b/src/nm-policy.c index a2ff2945b2..aebd843e3e 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -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; diff --git a/src/tests/test-general.c b/src/tests/test-general.c index 81d8e05c1e..f8f8fa2606 100644 --- a/src/tests/test-general.c +++ b/src/tests/test-general.c @@ -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++) |