core: add and use nm_settings_connection_cmp_timestamp*()
Only move the function, no change in behavior.
This commit is contained in:
@@ -1738,7 +1738,7 @@ get_existing_connection (NMManager *self, NMDevice *device, gboolean *out_genera
|
|||||||
* When no configured connection matches the generated connection, we keep
|
* When no configured connection matches the generated connection, we keep
|
||||||
* the generated connection instead.
|
* the generated connection instead.
|
||||||
*/
|
*/
|
||||||
connections = g_slist_reverse (g_slist_sort (connections, nm_settings_sort_connections));
|
connections = g_slist_reverse (g_slist_sort (connections, (GCompareFunc) nm_settings_connection_cmp_timestamp));
|
||||||
matched = NM_SETTINGS_CONNECTION (nm_utils_match_connection (connections,
|
matched = NM_SETTINGS_CONNECTION (nm_utils_match_connection (connections,
|
||||||
connection,
|
connection,
|
||||||
nm_device_has_carrier (device),
|
nm_device_has_carrier (device),
|
||||||
|
@@ -2162,6 +2162,43 @@ nm_settings_connection_set_flags_all (NMSettingsConnection *self, NMSettingsConn
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/* sorting for "best" connections.
|
||||||
|
* The function sorts connections in ascending timestamp order.
|
||||||
|
* That means an older connection (lower timestamp) goes before
|
||||||
|
* a newer one.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
nm_settings_connection_cmp_timestamp (NMSettingsConnection *ac, NMSettingsConnection *bc)
|
||||||
|
{
|
||||||
|
guint64 ats = 0, bts = 0;
|
||||||
|
|
||||||
|
if (ac == bc)
|
||||||
|
return 0;
|
||||||
|
if (!ac)
|
||||||
|
return -1;
|
||||||
|
if (!bc)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* In the future we may use connection priorities in addition to timestamps */
|
||||||
|
nm_settings_connection_get_timestamp (ac, &ats);
|
||||||
|
nm_settings_connection_get_timestamp (bc, &bts);
|
||||||
|
|
||||||
|
if (ats < bts)
|
||||||
|
return -1;
|
||||||
|
else if (ats > bts)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
nm_settings_connection_cmp_timestamp_p_with_data (gconstpointer pa, gconstpointer pb, gpointer user_data)
|
||||||
|
{
|
||||||
|
return nm_settings_connection_cmp_timestamp (*((NMSettingsConnection **) pa),
|
||||||
|
*((NMSettingsConnection **) pb));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_settings_connection_get_timestamp:
|
* nm_settings_connection_get_timestamp:
|
||||||
* @self: the #NMSettingsConnection
|
* @self: the #NMSettingsConnection
|
||||||
|
@@ -184,6 +184,9 @@ NMSettingsConnectionFlags nm_settings_connection_get_flags (NMSettingsConnection
|
|||||||
NMSettingsConnectionFlags nm_settings_connection_set_flags (NMSettingsConnection *self, NMSettingsConnectionFlags flags, gboolean set);
|
NMSettingsConnectionFlags nm_settings_connection_set_flags (NMSettingsConnection *self, NMSettingsConnectionFlags flags, gboolean set);
|
||||||
NMSettingsConnectionFlags nm_settings_connection_set_flags_all (NMSettingsConnection *self, NMSettingsConnectionFlags flags);
|
NMSettingsConnectionFlags nm_settings_connection_set_flags_all (NMSettingsConnection *self, NMSettingsConnectionFlags flags);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
gboolean nm_settings_connection_get_timestamp (NMSettingsConnection *self,
|
gboolean nm_settings_connection_get_timestamp (NMSettingsConnection *self,
|
||||||
guint64 *out_timestamp);
|
guint64 *out_timestamp);
|
||||||
|
|
||||||
|
@@ -2085,36 +2085,6 @@ nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quittin
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
/* GCompareFunc helper for sorting "best" connections.
|
|
||||||
* The function sorts connections in ascending timestamp order.
|
|
||||||
* That means an older connection (lower timestamp) goes before
|
|
||||||
* a newer one.
|
|
||||||
*/
|
|
||||||
gint
|
|
||||||
nm_settings_sort_connections (gconstpointer a, gconstpointer b)
|
|
||||||
{
|
|
||||||
NMSettingsConnection *ac = (NMSettingsConnection *) a;
|
|
||||||
NMSettingsConnection *bc = (NMSettingsConnection *) b;
|
|
||||||
guint64 ats = 0, bts = 0;
|
|
||||||
|
|
||||||
if (ac == bc)
|
|
||||||
return 0;
|
|
||||||
if (!ac)
|
|
||||||
return -1;
|
|
||||||
if (!bc)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* In the future we may use connection priorities in addition to timestamps */
|
|
||||||
nm_settings_connection_get_timestamp (ac, &ats);
|
|
||||||
nm_settings_connection_get_timestamp (bc, &bts);
|
|
||||||
|
|
||||||
if (ats < bts)
|
|
||||||
return -1;
|
|
||||||
else if (ats > bts)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_settings_get_best_connections:
|
* nm_settings_get_best_connections:
|
||||||
* @self: the #NMSetting
|
* @self: the #NMSetting
|
||||||
@@ -2169,7 +2139,7 @@ nm_settings_get_best_connections (NMSettings *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* List is sorted with oldest first */
|
/* List is sorted with oldest first */
|
||||||
sorted = g_slist_insert_sorted (sorted, connection, nm_settings_sort_connections);
|
sorted = g_slist_insert_sorted (sorted, connection, (GCompareFunc) nm_settings_connection_cmp_timestamp);
|
||||||
added++;
|
added++;
|
||||||
|
|
||||||
if (max_requested && added > max_requested) {
|
if (max_requested && added > max_requested) {
|
||||||
|
@@ -126,8 +126,6 @@ void nm_settings_device_added (NMSettings *self, NMDevice *device);
|
|||||||
|
|
||||||
void nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quitting);
|
void nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quitting);
|
||||||
|
|
||||||
gint nm_settings_sort_connections (gconstpointer a, gconstpointer b);
|
|
||||||
|
|
||||||
gboolean nm_settings_get_startup_complete (NMSettings *self);
|
gboolean nm_settings_get_startup_complete (NMSettings *self);
|
||||||
|
|
||||||
void nm_settings_set_transient_hostname (NMSettings *self,
|
void nm_settings_set_transient_hostname (NMSettings *self,
|
||||||
|
Reference in New Issue
Block a user