[PATCH v3 4/6] android/gatt: Refactor trigger connection function.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Refactor code so it is clear what action we take in different connection
states.
---
 android/gatt.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 11d7a2c..448bcb8 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1751,31 +1751,42 @@ static int connect_bredr(struct gatt_device *dev)
 
 static bool trigger_connection(struct app_connection *connection)
 {
+	bool ret;
+
 	switch (connection->device->state) {
 	case DEVICE_DISCONNECTED:
+		/*
+		 *  If device was last seen over BR/EDR connect over it.
+		 *  Note: Connection state is handled in connect_bredr() func
+		 */
+		if (bt_device_last_seen_bearer(&connection->device->bdaddr) ==
+								BDADDR_BREDR)
+			return connect_bredr(connection->device) == 0;
+
+		/* Trigger discovery if not already started */
+		if (!scanning) {
+			if (!bt_le_discovery_start()) {
+				error("gatt: Could not start scan");
+				ret = false;
+				break;
+			}
+		}
+		ret = true;
 		device_set_state(connection->device, DEVICE_CONNECT_INIT);
 		break;
 	case DEVICE_CONNECTED:
 		send_app_connect_notify(connection, GATT_SUCCESS);
+		ret = true;
 		break;
+	case DEVICE_CONNECT_READY:
+	case DEVICE_CONNECT_INIT:
 	default:
+		/* In those cases connection is already triggered. */
+		ret = true;
 		break;
 	}
 
-	/* If device was last seen over BR/EDR connect over it */
-	if (bt_device_last_seen_bearer(&connection->device->bdaddr) ==
-								BDADDR_BREDR)
-		return connect_bredr(connection->device) == 0;
-
-	/* after state change trigger discovering */
-	if (!scanning && (connection->device->state == DEVICE_CONNECT_INIT))
-		if (!bt_le_discovery_start()) {
-			error("gatt: Could not start scan");
-
-			return false;
-		}
-
-	return true;
+	return ret;
 }
 
 static uint8_t unregister_app(int client_if)
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux