From 7f826e3de315dbddbd979c841a106fc50091d95f Mon Sep 17 00:00:00 2001 From: "vimala.v" Date: Wed, 24 Feb 2016 09:57:41 +0530 Subject: [PATCH] Fix in Tizen 2.4 BLE client to discover services when the remote device is already connected via GATT profile. Change-Id: I834c110425beaec330368eb6a5a1b1e79213213f Signed-off-by: vimala.v Reviewed-on: https://gerrit.iotivity.org/gerrit/5155 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz Reviewed-by: Ashok Babu Channa --- .../src/bt_le_adapter/tizen/caleclient.c | 54 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c index c30ad82..3732bc9 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c @@ -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) -- 2.7.4