else
{
oc_mutex_unlock(g_LEServerListMutex);
- OIC_LOG(ERROR, TAG, "Previous connection attempt failed, attempting to retry again");
- OIC_LOG_V(DEBUG, TAG, "Retry count left %d time(s)", g_retrycount);
+ OIC_LOG(ERROR, TAG, "Previous connection attempt failed, attempting to retry again");
+ OIC_LOG_V(DEBUG, TAG, "Retry count left %d time(s)", g_retrycount);
return CA_STATUS_FAILED;
}
}
}
LEServerInfo *serverInfo = NULL;
+ bool isConnected = false;
oc_mutex_lock(g_LEServerListMutex);
if (LE_UNICAST == type)
{
if(serverInfo->status == LE_STATUS_UNICAST_PENDING)
{
- oc_mutex_lock(g_scanMutex);
- if (!g_isMulticastInProgress && !g_isUnicastScanInProgress)
+
+ int ret = bt_device_is_profile_connected(remoteAddress, BT_PROFILE_GATT, &isConnected);
+ if (BT_ERROR_NONE != ret)
{
- CAResult_t result = CALEGattStartDeviceScanning();
- if (CA_STATUS_OK != result)
+ OIC_LOG_V(ERROR, TAG, "bt_device_is_profile_connected Failed with ret value [%s] ",
+ CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEServerListMutex);
+ return CA_STATUS_FAILED;
+ }
+
+ if (isConnected){
+ OIC_LOG_V(DEBUG, TAG, "Already connected to address [%s]", remoteAddress);
+ serverInfo->status = LE_STATUS_CONNECTED;
+ } else {
+ oc_mutex_lock(g_scanMutex);
+ if (!g_isMulticastInProgress && !g_isUnicastScanInProgress)
+ {
+ CAResult_t result = CALEGattStartDeviceScanning();
+ if (CA_STATUS_OK != result)
+ {
+ oc_mutex_unlock(g_scanMutex);
+ OIC_LOG(ERROR, TAG, "CALEGattStartDeviceScanning failed");
+ oc_mutex_unlock(g_LEServerListMutex);
+ return CA_STATUS_FAILED;
+ }
+ g_isUnicastScanInProgress = true;
+ // Start Timer
+ oc_cond_signal(g_startTimerCond);
+ }
+ else
{
- oc_mutex_unlock(g_scanMutex);
- OIC_LOG(ERROR, TAG, "CALEGattStartDeviceScanning failed");
- return CA_STATUS_FAILED;
+ g_isUnicastScanInProgress = true;
+ // Reset Timer
+ oc_cond_signal(g_scanningTimeCond);
}
- g_isUnicastScanInProgress = true;
- // Start Timer
- oc_cond_signal(g_startTimerCond);
+ oc_mutex_unlock(g_scanMutex);
+ }
+
+ }
+
+ if (serverInfo->status == LE_STATUS_CONNECTED)
+ {
+ oc_mutex_lock(g_LEClientThreadPoolMutex);
+ if (NULL == g_LEClientThreadPool)
+ {
+ oc_mutex_unlock(g_LEClientThreadPoolMutex);
+ OIC_LOG(ERROR, TAG, "g_LEClientThreadPool is NULL");
+ oc_mutex_unlock(g_LEServerListMutex);
+ return CA_STATUS_FAILED;
}
- else
+ char *addr = OICStrdup(remoteAddress);
+ if (NULL == addr)
{
- g_isUnicastScanInProgress = true;
- // Reset Timer
- oc_cond_signal(g_scanningTimeCond);
+ oc_mutex_unlock(g_LEClientThreadPoolMutex);
+ OIC_LOG(ERROR, TAG, "addr is NULL");
+ oc_mutex_unlock(g_LEServerListMutex);
+ return CA_STATUS_FAILED;
+ }
+ CAResult_t ret = ca_thread_pool_add_task(g_LEClientThreadPool, CADiscoverLEServicesThread,
+ addr, NULL);
+ oc_mutex_unlock(g_LEClientThreadPoolMutex);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "ca_thread_pool_add_task failed with ret [%d]", ret);
+ OICFree(addr);
}
- oc_mutex_unlock(g_scanMutex);
-
}
if (serverInfo->status == LE_STATUS_DISCOVERED)
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_create Failed with ret value [%s] ", CALEGetErrorMsg(ret));
CALEGattDisConnect(serverInfo->remoteAddress);
+ oc_mutex_unlock(g_LEServerListMutex);
return CA_STATUS_FAILED;
}
serverInfo->clientHandle = clientHandle;