diff options
author | Thomas Haller <thaller@redhat.com> | 2017-02-03 16:00:33 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-02-10 14:43:24 +0100 |
commit | 4a2572fcc1e52cd3f4cf029ce88db6af86653d7d (patch) | |
tree | bcc2bfd1a735e5f5b52f771f4e25cd6e0a22fb80 | |
parent | 5c5845c649d3d6ac814f43c4500b7ae4cea68f5a (diff) |
core: add and use nm_settings_connection_cmp_default*()
Only move the function, no change in behavior.
-rw-r--r-- | src/settings/nm-settings-connection.c | 32 | ||||
-rw-r--r-- | src/settings/nm-settings-connection.h | 2 | ||||
-rw-r--r-- | src/settings/nm-settings.c | 31 |
3 files changed, 35 insertions, 30 deletions
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 66069e740..453b3c5b3 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -2197,6 +2197,38 @@ nm_settings_connection_cmp_timestamp_p_with_data (gconstpointer pa, gconstpointe *((NMSettingsConnection **) pb)); } +int +nm_settings_connection_cmp_default (NMSettingsConnection *a, NMSettingsConnection *b) +{ + NMSettingConnection *con_a; + NMSettingConnection *con_b; + guint64 ts_a = 0, ts_b = 0; + gboolean can_ac_a, can_ac_b; + + con_a = nm_connection_get_setting_connection (NM_CONNECTION (a)); + con_b = nm_connection_get_setting_connection (NM_CONNECTION (b)); + + can_ac_a = !!nm_setting_connection_get_autoconnect (con_a); + can_ac_b = !!nm_setting_connection_get_autoconnect (con_b); + if (can_ac_a != can_ac_b) + return can_ac_a ? -1 : 1; + + nm_settings_connection_get_timestamp (a, &ts_a); + nm_settings_connection_get_timestamp (b, &ts_b); + if (ts_a > ts_b) + return -1; + else if (ts_a == ts_b) + return 0; + return 1; +} + +int +nm_settings_connection_cmp_default_p_with_data (gconstpointer pa, gconstpointer pb, gpointer user_data) +{ + return nm_settings_connection_cmp_default (*((NMSettingsConnection **) pa), + *((NMSettingsConnection **) pb)); +} + /*****************************************************************************/ /** diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index fa7e4b559..8fe9533a8 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -186,6 +186,8 @@ NMSettingsConnectionFlags nm_settings_connection_set_flags_all (NMSettingsConnec int nm_settings_connection_cmp_timestamp (NMSettingsConnection *ac, NMSettingsConnection *ab); int nm_settings_connection_cmp_timestamp_p_with_data (gconstpointer pa, gconstpointer pb, gpointer user_data); +int nm_settings_connection_cmp_default (NMSettingsConnection *a, NMSettingsConnection *b); +int nm_settings_connection_cmp_default_p_with_data (gconstpointer pa, gconstpointer pb, gpointer user_data); gboolean nm_settings_connection_get_timestamp (NMSettingsConnection *self, guint64 *out_timestamp); diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index dba9332d2..0189d842b 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -393,35 +393,6 @@ error: g_clear_object (&subject); } -static int -connection_sort (gconstpointer pa, gconstpointer pb) -{ - NMConnection *a = NM_CONNECTION (pa); - NMSettingConnection *con_a; - NMConnection *b = NM_CONNECTION (pb); - NMSettingConnection *con_b; - guint64 ts_a = 0, ts_b = 0; - gboolean can_ac_a, can_ac_b; - - con_a = nm_connection_get_setting_connection (a); - g_assert (con_a); - con_b = nm_connection_get_setting_connection (b); - g_assert (con_b); - - can_ac_a = !!nm_setting_connection_get_autoconnect (con_a); - can_ac_b = !!nm_setting_connection_get_autoconnect (con_b); - if (can_ac_a != can_ac_b) - return can_ac_a ? -1 : 1; - - nm_settings_connection_get_timestamp (NM_SETTINGS_CONNECTION (pa), &ts_a); - nm_settings_connection_get_timestamp (NM_SETTINGS_CONNECTION (pb), &ts_b); - if (ts_a > ts_b) - return -1; - else if (ts_a == ts_b) - return 0; - return 1; -} - /** * nm_settings_get_connections: * @self: the #NMSettings @@ -485,7 +456,7 @@ nm_settings_get_connections_sorted (NMSettings *self) g_hash_table_iter_init (&iter, NM_SETTINGS_GET_PRIVATE (self)->connections); while (g_hash_table_iter_next (&iter, NULL, &data)) - list = g_slist_insert_sorted (list, data, connection_sort); + list = g_slist_insert_sorted (list, data, (GCompareFunc) nm_settings_connection_cmp_default); return list; } |