[IOT-1391] fix BLE scan logic which create thread.
authorjihwan.seo <jihwan.seo@samsung.com>
Wed, 5 Oct 2016 05:06:04 +0000 (14:06 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Thu, 20 Oct 2016 07:03:15 +0000 (07:03 +0000)
scan thread was made by unicast/multicast request in BLE client.
it causes a big problem which memory overflow issue related Thread.
so, scan thread will be working as one thread.

Change-Id: I87564f88b67d88781366523ae014c29fe1b13e2e
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12781
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c

index 3e7fd41..e5af799 100644 (file)
@@ -750,6 +750,7 @@ CAResult_t CALEClientIsThereScannedDevices(JNIEnv *env, const char* address)
 
     if (!g_deviceList)
     {
+        OIC_LOG(ERROR, TAG, "g_deviceList is not available");
         return CA_STATUS_FAILED;
     }
 
@@ -826,6 +827,10 @@ CAResult_t CALEClientIsThereScannedDevices(JNIEnv *env, const char* address)
             return CA_STATUS_FAILED;
         }
     }
+    else
+    {
+        OIC_LOG(DEBUG, TAG, "there is a target device in the scanned devices");
+    }
 
     return CA_STATUS_OK;
 }
@@ -904,9 +909,6 @@ CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t*
                 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
                 (*env)->DeleteLocalRef(env, jni_setAddress);
 
-                // stop scan while sending
-                CALEClientStopScanWithInterval();
-
                 if (g_sendBuffer)
                 {
                     (*env)->DeleteGlobalRef(env, g_sendBuffer);
@@ -952,15 +954,6 @@ CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t*
         (*g_jvm)->DetachCurrentThread(g_jvm);
     }
 
-    // start LE Scan again
-    ret = CALEClientStartScanWithInterval();
-    if (CA_STATUS_OK != ret)
-    {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
-        oc_mutex_unlock(g_threadSendMutex);
-        return ret;
-    }
-
     oc_mutex_unlock(g_threadSendMutex);
     OIC_LOG(INFO, TAG, "unicast - send logic has finished");
     if (CALEClientIsValidState(address, CA_LE_SEND_STATE,
@@ -986,20 +979,6 @@ CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t*
 
     // error label.
 error_exit:
-
-    // start LE Scan again
-    ret = CALEClientStartScanWithInterval();
-    if (CA_STATUS_OK != ret)
-    {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
-        oc_mutex_unlock(g_threadSendMutex);
-        if (isAttached)
-        {
-            (*g_jvm)->DetachCurrentThread(g_jvm);
-        }
-        return ret;
-    }
-
     if (isAttached)
     {
         (*g_jvm)->DetachCurrentThread(g_jvm);
@@ -1040,9 +1019,6 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t* data,
         goto error_exit;
     }
 
-    // stop scan while sending
-    CALEClientStopScanWithInterval();
-
     uint32_t length = u_arraylist_length(g_deviceList);
     g_targetCnt = length;
 
@@ -1077,31 +1053,13 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t* data,
         OIC_LOG(DEBUG, TAG, "the data was sent");
     }
     oc_mutex_unlock(g_threadMutex);
-
-    // start LE Scan again
-    res = CALEClientStartScanWithInterval();
-    if (CA_STATUS_OK != res)
-    {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
-        oc_mutex_unlock(g_threadSendMutex);
-        return res;
-    }
-
     oc_mutex_unlock(g_threadSendMutex);
     OIC_LOG(DEBUG, TAG, "OUT - CALEClientSendMulticastMessageImpl");
     return CA_STATUS_OK;
 
 error_exit:
-    res = CALEClientStartScanWithInterval();
-    if (CA_STATUS_OK != res)
-    {
-        OIC_LOG(ERROR, TAG, "CALEClientStartScanWithInterval has failed");
-        oc_mutex_unlock(g_threadSendMutex);
-        return res;
-    }
-
     oc_mutex_unlock(g_threadSendMutex);
-    OIC_LOG(DEBUG, TAG, "OUT - CALEClientSendMulticastMessageImpl");
+    OIC_LOG(ERROR, TAG, "OUT - CALEClientSendMulticastMessageImpl");
     return CA_SEND_FAILED;
 }
 
@@ -2783,8 +2741,6 @@ CAResult_t CALEClientAddScanDeviceToList(JNIEnv *env, jobject device)
     if (!g_deviceList)
     {
         OIC_LOG(ERROR, TAG, "gdevice_list is null");
-        CALEClientStopScanWithInterval();
-
         oc_mutex_unlock(g_deviceListMutex);
         return CA_STATUS_FAILED;
     }