core: simplify nm_device_get_best_auto_connection() implementations

Filter out non-autoconnect connections in the generic NMDevice method
rather than requiring each subclass to do it.

https://bugzilla.gnome.org/show_bug.cgi?id=688284
This commit is contained in:
Dan Winship 2012-11-08 13:15:51 -05:00
parent c8eba44cfa
commit 0b57fe0c56
10 changed files with 31 additions and 72 deletions

View file

@ -201,18 +201,9 @@ get_best_auto_connection (NMModem *modem,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if (!nm_setting_connection_get_autoconnect (s_con))
continue;
if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_CDMA_SETTING_NAME))
continue;
return connection;
if (nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME))
return connection;
}
return NULL;
}

View file

@ -475,18 +475,9 @@ get_best_auto_connection (NMModem *modem,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if (!nm_setting_connection_get_autoconnect (s_con))
continue;
if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_GSM_SETTING_NAME))
continue;
return connection;
if (nm_connection_is_type (connection, NM_SETTING_GSM_SETTING_NAME))
return connection;
}
return NULL;
}

View file

@ -208,22 +208,12 @@ get_best_auto_connection (NMDevice *dev,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
NMSettingAdsl *s_adsl;
if (!nm_connection_is_type (connection, NM_SETTING_ADSL_SETTING_NAME))
continue;
s_adsl = nm_connection_get_setting_adsl (connection);
if (!s_adsl)
continue;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if (!nm_setting_connection_get_autoconnect (s_con))
continue;
return connection;
if (nm_connection_get_setting_adsl (connection))
return connection;
}
return NULL;
}

View file

@ -164,12 +164,8 @@ get_best_auto_connection (NMDevice *dev,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if ( nm_setting_connection_get_autoconnect (s_con)
&& match_bond_connection (dev, connection, NULL))
if (match_bond_connection (dev, connection, NULL))
return connection;
}
return NULL;

View file

@ -149,16 +149,9 @@ get_best_auto_connection (NMDevice *device,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
guint32 bt_type;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if (!nm_setting_connection_get_autoconnect (s_con))
continue;
if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_BLUETOOTH_SETTING_NAME))
if (!nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME))
continue;
bt_type = get_connection_bt_type (connection);

View file

@ -624,13 +624,8 @@ get_best_auto_connection (NMDevice *dev,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if ( nm_setting_connection_get_autoconnect (s_con)
&& match_ethernet_connection (dev, connection, TRUE, NULL))
if (match_ethernet_connection (dev, connection, TRUE, NULL))
return connection;
}

View file

@ -158,16 +158,10 @@ get_best_auto_connection (NMDevice *dev,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
NMSettingInfiniband *s_infiniband;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME))
continue;
if (!nm_setting_connection_get_autoconnect (s_con))
continue;
s_infiniband = nm_connection_get_setting_infiniband (connection);
if (!s_infiniband)

View file

@ -300,12 +300,8 @@ get_best_auto_connection (NMDevice *dev,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if ( nm_setting_connection_get_autoconnect (s_con)
&& match_vlan_connection (NM_DEVICE_VLAN (dev), connection, NULL))
if (match_vlan_connection (NM_DEVICE_VLAN (dev), connection, NULL))
return connection;
}
return NULL;

View file

@ -1386,7 +1386,6 @@ get_best_auto_connection (NMDevice *dev,
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
NMSettingWireless *s_wireless;
const GByteArray *mac;
const GSList *mac_blacklist, *mac_blacklist_iter;
@ -1395,12 +1394,7 @@ get_best_auto_connection (NMDevice *dev,
const char *method = NULL;
guint64 timestamp = 0;
s_con = nm_connection_get_setting_connection (connection);
if (s_con == NULL)
continue;
if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_WIRELESS_SETTING_NAME))
continue;
if (!nm_setting_connection_get_autoconnect (s_con))
if (!nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME))
continue;
/* Don't autoconnect to networks that have been tried at least once

View file

@ -1161,6 +1161,8 @@ nm_device_get_best_auto_connection (NMDevice *dev,
char **specific_object)
{
guint32 caps;
GSList *iter, *available_conns;
NMConnection *best_connection;
g_return_val_if_fail (NM_IS_DEVICE (dev), NULL);
g_return_val_if_fail (specific_object != NULL, NULL);
@ -1174,7 +1176,24 @@ nm_device_get_best_auto_connection (NMDevice *dev,
if (!NM_DEVICE_GET_CLASS (dev)->get_best_auto_connection)
return NULL;
return NM_DEVICE_GET_CLASS (dev)->get_best_auto_connection (dev, connections, specific_object);
available_conns = NULL;
for (iter = connections; iter; iter = iter->next) {
NMConnection *connection = NM_CONNECTION (iter->data);
NMSettingConnection *s_con;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if (nm_setting_connection_get_autoconnect (s_con))
available_conns = g_slist_prepend (available_conns, connection);
}
if (!available_conns)
return NULL;
best_connection = NM_DEVICE_GET_CLASS (dev)->get_best_auto_connection (dev, available_conns, specific_object);
g_slist_free (available_conns);
return best_connection;
}
gboolean