OSDN Git Service

core: Move connect_list handling to ATT specific callbacks
authorJohan Hedberg <johan.hedberg@intel.com>
Tue, 29 Jan 2013 23:13:36 +0000 (17:13 -0600)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 29 Jan 2013 23:13:36 +0000 (17:13 -0600)
This is more reliable since we're not always guaranteed to get the right
mgmt events, e.g. a socket connect timeout might not trigger those.

src/adapter.c
src/device.c

index 11be7b5..805a80a 100644 (file)
@@ -4996,11 +4996,6 @@ static void dev_disconnected(struct btd_adapter *adapter,
 
        bonding_complete(adapter, &addr->bdaddr, addr->type,
                                                MGMT_STATUS_DISCONNECTED);
-
-       /* If this device should be connected through passive scanning
-        * add it back to the connect_list */
-       if (device && device_get_auto_connect(device))
-               adapter_connect_list_add(adapter, device);
 }
 
 static void disconnect_complete(uint8_t status, uint16_t length,
@@ -5583,19 +5578,6 @@ static void connected_callback(uint16_t index, uint16_t length,
        }
 
        eir_data_free(&eir_data);
-
-       /*
-        * If this was an LE device being connected through passive
-        * scanning remove the device from the connect_list and give the
-        * passive scanning another chance to be restarted in case
-        * there are other devices in the connect_list.
-        */
-       if (device == adapter->connect_le) {
-               adapter->connect_le = NULL;
-               adapter->connect_list = g_slist_remove(adapter->connect_list,
-                                                               device);
-               trigger_passive_scanning(adapter);
-       }
 }
 
 static void device_blocked_callback(uint16_t index, uint16_t length,
@@ -5663,12 +5645,6 @@ static void connect_failed_callback(uint16_t index, uint16_t length,
                        device_bonding_failed(device, ev->status);
                if (device_is_temporary(device))
                        adapter_remove_device(adapter, device, TRUE);
-               if (device_is_le(device)) {
-                       if (device == adapter->connect_le)
-                               adapter->connect_le = NULL;
-                       if (device_get_auto_connect(device))
-                               adapter_connect_list_add(adapter, device);
-               }
        }
 
        /* In the case of security mode 3 devices */
index c13e2d0..bd0ee75 100644 (file)
@@ -2934,7 +2934,7 @@ static gboolean attrib_disconnected_cb(GIOChannel *io, GIOCondition cond,
 
        g_slist_foreach(device->attios, attio_disconnected, NULL);
 
-       if (device->auto_connect == FALSE) {
+       if (!device_get_auto_connect(device)) {
                DBG("Automatic connection disabled");
                goto done;
        }
@@ -3155,11 +3155,10 @@ static void att_error_cb(const GError *gerr, gpointer user_data)
        if (g_error_matches(gerr, BT_IO_ERROR, ECONNABORTED))
                return;
 
-       if (device->auto_connect == FALSE)
-               return;
-
-       adapter_connect_list_add(device->adapter, device);
-       DBG("Enabling automatic connections");
+       if (device_get_auto_connect(device)) {
+               DBG("Enabling automatic connections");
+               adapter_connect_list_add(device->adapter, device);
+       }
 }
 
 static void att_success_cb(gpointer user_data)
@@ -3170,6 +3169,13 @@ static void att_success_cb(gpointer user_data)
        if (device->attios == NULL)
                return;
 
+       /*
+        * Remove the device from the connect_list and give the passive
+        * scanning another chance to be restarted in case there are
+        * other devices in the connect_list.
+        */
+       adapter_connect_list_remove(device->adapter, device);
+
        g_slist_foreach(device->attios, attio_connected, device->attrib);
 }