Imported Upstream version 1.1.1
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / caleclient.c
index 3d4fd24..67a44ea 100644 (file)
@@ -247,6 +247,9 @@ void CALEGattConnectionStateChanged(bool connected, const char *remoteAddress)
     if (!connected)
     {
         OIC_LOG_V(DEBUG, TAG, "DisConnected from [%s] ", remoteAddress);
+        ca_mutex_lock(g_LEServerListMutex);
+        CARemoveLEServerInfoFromList(&g_LEServerList, remoteAddress);
+        ca_mutex_unlock(g_LEServerListMutex);
     }
     else
     {
@@ -373,40 +376,12 @@ CAResult_t CAStartLEGattClient()
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
-    ca_mutex_lock(g_LEClientThreadPoolMutex);
-    if (NULL == g_LEClientThreadPool)
-    {
-        OIC_LOG(ERROR, TAG, "gBleServerThreadPool is NULL");
-        CATerminateGattClientMutexVariables();
-        ca_mutex_unlock(g_LEClientThreadPoolMutex);
-        return CA_STATUS_FAILED;
-    }
-
-    CAResult_t result = ca_thread_pool_add_task(g_LEClientThreadPool, CAStartLEGattClientThread,
-                                     NULL);
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, TAG, "ca_thread_pool_add_task failed");
-        CATerminateGattClientMutexVariables();
-        ca_mutex_unlock(g_LEClientThreadPoolMutex);
-        return CA_STATUS_FAILED;
-    }
-    ca_mutex_unlock(g_LEClientThreadPoolMutex);
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-void CAStartLEGattClientThread(void *data)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
     ca_mutex_lock(g_LEClientStateMutex);
     if (true  == g_isLEGattClientStarted)
     {
         OIC_LOG(ERROR, TAG, "Gatt Client is already running!!");
         ca_mutex_unlock(g_LEClientStateMutex);
-        return;
+        return CA_STATUS_FAILED;
     }
 
     CAResult_t  result = CALEGattSetCallbacks();
@@ -415,7 +390,7 @@ void CAStartLEGattClientThread(void *data)
         OIC_LOG(ERROR, TAG, "CABleGattSetCallbacks Failed");
         ca_mutex_unlock(g_LEClientStateMutex);
         CATerminateLEGattClient();
-        return;
+        return CA_STATUS_FAILED;
     }
 
     g_isLEGattClientStarted = true;
@@ -427,7 +402,7 @@ void CAStartLEGattClientThread(void *data)
         OIC_LOG(ERROR, TAG, "gBleServerThreadPool is NULL");
         CATerminateGattClientMutexVariables();
         ca_mutex_unlock(g_LEClientThreadPoolMutex);
-        return;
+        return CA_STATUS_FAILED;
     }
 
     result = ca_thread_pool_add_task(g_LEClientThreadPool, CAStartTimerThread,
@@ -435,22 +410,14 @@ void CAStartLEGattClientThread(void *data)
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, TAG, "ca_thread_pool_add_task failed");
+        CATerminateGattClientMutexVariables();
         ca_mutex_unlock(g_LEClientThreadPoolMutex);
-        return;
+        return CA_STATUS_FAILED;
     }
     ca_mutex_unlock(g_LEClientThreadPoolMutex);
 
-    OIC_LOG(DEBUG, TAG, "Giving the control to threadPool");
-
-    GMainContext *thread_context = g_main_context_new();
-
-    g_eventLoop = g_main_loop_new(thread_context, FALSE);
-
-    g_main_context_push_thread_default(thread_context);
-
-    g_main_loop_run(g_eventLoop);
-
     OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
 }
 
 void CAStartTimerThread(void *data)
@@ -1020,7 +987,7 @@ CAResult_t CALEGattDiscoverServices(const char *remoteAddress)
     CAResult_t result = CAAddLEServerInfoToList(&g_LEServerList, serverInfo);
     if (CA_STATUS_OK != result)
     {
-        OIC_LOG(ERROR, TAG, "CAAddBLEClientInfoToList failed");
+        OIC_LOG(ERROR, TAG, "CAAddLEServerInfoToList failed");
         bt_gatt_client_destroy(clientHandle);
         CALEGattDisConnect(remoteAddress);
         return CA_STATUS_FAILED;