Fix in Tizen 2.4 BLE client to discover services when the remote device is already...
authorvimala.v <vimala.v@samsung.com>
Wed, 24 Feb 2016 04:27:41 +0000 (09:57 +0530)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 2 Mar 2016 04:23:09 +0000 (04:23 +0000)
Change-Id: I834c110425beaec330368eb6a5a1b1e79213213f
Signed-off-by: vimala.v <vimala.v@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5155
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c

index c30ad82..3732bc9 100644 (file)
@@ -834,20 +834,64 @@ CAResult_t CALEGattConnect(const char *remoteAddress)
                         "remote address is NULL", CA_STATUS_FAILED);
 
     ca_mutex_lock(g_LEClientConnectMutex);
-
-    int ret = bt_gatt_connect(remoteAddress, true);
-
+    bool isConnected = false;
+    int ret = bt_device_is_profile_connected(remoteAddress, BT_PROFILE_GATT, &isConnected);
     if (BT_ERROR_NONE != ret)
     {
-        OIC_LOG_V(ERROR, TAG, "bt_gatt_connect Failed with ret value [%s] ",
+        OIC_LOG_V(ERROR, TAG, "bt_device_is_profile_connected Failed with ret value [%s] ",
                   CALEGetErrorMsg(ret));
         ca_mutex_unlock(g_LEClientConnectMutex);
         return CA_STATUS_FAILED;
     }
+
+    CAResult_t result = CA_STATUS_OK;
+    if (!isConnected)
+    {
+        ret = bt_gatt_connect(remoteAddress, true);
+
+        if (BT_ERROR_NONE != ret)
+        {
+            OIC_LOG_V(ERROR, TAG, "bt_gatt_connect Failed with ret value [%s] ",
+                      CALEGetErrorMsg(ret));
+            ca_mutex_unlock(g_LEClientConnectMutex);
+            return CA_STATUS_FAILED;
+        }
+    }
+    else
+    {
+        OIC_LOG_V(INFO, TAG, "Remote address[%s] is already connected",
+                  remoteAddress);
+        char *addr = OICStrdup(remoteAddress);
+        if (NULL == addr)
+        {
+            OIC_LOG(ERROR, TAG, "addr is NULL");
+            ca_mutex_unlock(g_LEClientConnectMutex);
+            return CA_STATUS_FAILED;
+        }
+
+        ca_mutex_lock(g_LEClientThreadPoolMutex);
+        if (NULL == g_LEClientThreadPool)
+        {
+            OIC_LOG(ERROR, TAG, "g_LEClientThreadPool is NULL");
+            OICFree(addr);
+            ca_mutex_unlock(g_LEClientThreadPoolMutex);
+            ca_mutex_unlock(g_LEClientConnectMutex);
+            return CA_STATUS_FAILED;
+        }
+
+        result = ca_thread_pool_add_task(g_LEClientThreadPool, CADiscoverLEServicesThread,
+                                      addr);
+        if (CA_STATUS_OK != result)
+        {
+            OIC_LOG_V(ERROR, TAG, "ca_thread_pool_add_task failed with ret [%d]", result);
+            OICFree(addr);
+        }
+        ca_mutex_unlock(g_LEClientThreadPoolMutex);
+    }
     ca_mutex_unlock(g_LEClientConnectMutex);
 
     OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
+    return result;
 }
 
 CAResult_t CALEGattDisConnect(const char *remoteAddress)