summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-12-08 12:15:02 +0100
committerThomas Haller <thaller@redhat.com>2015-02-24 11:49:03 +0100
commit364c4476e392cad1ef076a473e0462174cf14bd0 (patch)
treeb732159b36ec97dc13138a5b61606b65828068da
parenta7e0a038bf35e7d19ef859ff5035019c1bc0cad3 (diff)
downloadNetworkManager-364c4476e392cad1ef076a473e0462174cf14bd0.tar.gz
device: refactor nm_device_connection_is_available()
No functional change, but refactor the function to return early.
-rw-r--r--src/devices/nm-device.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 9034df9fcd..0219a40fe6 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -6908,30 +6908,44 @@ nm_device_connection_is_available (NMDevice *self,
gboolean for_user_activation_request)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
- gboolean available = FALSE;
+ gboolean is_default_unmanaged;
- if (nm_device_get_default_unmanaged (self) && (priv->state == NM_DEVICE_STATE_UNMANAGED)) {
+ if (g_hash_table_contains (priv->available_connections, connection))
+ return TRUE;
+
+ is_default_unmanaged = priv->state == NM_DEVICE_STATE_UNMANAGED && nm_device_get_default_unmanaged (self);
+
+ if (!for_user_activation_request && !is_default_unmanaged) {
+ /* Shortcut: there are only additional checks for either @for_user_activation_request
+ * or @is_default_unmanaged. Return FALSE right away. */
+ return FALSE;
+ }
+
+ if (!nm_device_check_connection_compatible (self, connection)) {
+ /* An incompatilbe connection is never available. */
+ return FALSE;
+ }
+
+ if ( is_default_unmanaged
+ && NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, NULL)) {
/* default-unmanaged devices in UNMANAGED state have no available connections
- * so we must manually check whether the connection is available here.
- */
- if ( nm_device_check_connection_compatible (self, connection)
- && NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, NULL))
- return TRUE;
+ * so we must manually check whether the connection is available here. */
+ return TRUE;
}
- available = !!g_hash_table_lookup (priv->available_connections, connection);
- if (!available && for_user_activation_request) {
- /* FIXME: hack for hidden WiFi becuase clients didn't consistently
- * set the 'hidden' property to indicate hidden SSID networks. If
- * activating but the network isn't available let the device recheck
- * availability.
+ if ( for_user_activation_request
+ && NM_DEVICE_GET_CLASS (self)->check_connection_available_wifi_hidden
+ && NM_DEVICE_GET_CLASS (self)->check_connection_available_wifi_hidden (self, connection)) {
+ /* Connections for an explicit user activation request might only be available after
+ * additional checking.
+ *
+ * For example in case of hidden Wi-Fi, the connection might not have the 'hidden' property
+ * set. Support this by allowing device specific overrides.
*/
- if ( nm_device_check_connection_compatible (self, connection)
- && NM_DEVICE_GET_CLASS (self)->check_connection_available_wifi_hidden)
- available = NM_DEVICE_GET_CLASS (self)->check_connection_available_wifi_hidden (self, connection);
+ return TRUE;
}
- return available;
+ return FALSE;
}
static void