core: prefer connections with higher priority for autoconnect

https://bugzilla.gnome.org/show_bug.cgi?id=580018

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-08-26 16:06:39 +02:00
parent 59f2c0fb3e
commit f87e876f79
4 changed files with 131 additions and 0 deletions

View File

@@ -1634,6 +1634,31 @@ nm_utils_match_connection (GSList *connections,
return best_match;
}
int
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_ac = !!nm_setting_connection_get_autoconnect (a_s_con);
b_ac = !!nm_setting_connection_get_autoconnect (b_s_con);
if (a_ac != b_ac)
return ((int) b_ac) - ((int) a_ac);
if (!a_ac)
return 0;
a_ap = nm_setting_connection_get_autoconnect_priority (a_s_con);
b_ap = nm_setting_connection_get_autoconnect_priority (b_s_con);
if (a_ap != b_ap)
return (a_ap > b_ap) ? -1 : 1;
return 0;
}
/* nm_utils_ascii_str_to_int64:
*
* A wrapper for g_ascii_strtoll, that checks whether the whole string