From 5715499946316f91ab8e1518d421e50e4b0985b8 Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Fri, 19 Feb 2016 10:02:57 +0900 Subject: [PATCH] [IOT-953] coap message is not sent in android ble when message is sent, deadlock is happened. so send flag that whether send is finished or not has to be covered mutex lock. Change-Id: I97698fa67df1bc6dcd04a3e5ef607d02050d1e69 Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/5055 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- .../src/bt_le_adapter/android/caleclient.c | 34 +++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c b/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c index 4d824ee..c3a53de 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c @@ -596,13 +596,14 @@ CAResult_t CALEClientIsThereScannedDevices() { if (ca_cond_wait_for(g_deviceDescCond, g_threadSendMutex, - TIMEOUT) == 0) + TIMEOUT) == CA_WAIT_SUCCESS) { devicesDiscovered = true; break; } } + // time out for scanning devices if (!devicesDiscovered) { return CA_STATUS_FAILED; @@ -722,13 +723,14 @@ CAResult_t CALEClientSendUnicastMessageImpl(const char* address, const uint8_t* // wait for finish to send data through "CALeGattServicesDiscoveredCallback" // if there is no connection state. + ca_mutex_lock(g_threadMutex); if (!g_isFinishedSendData) { - ca_mutex_lock(g_threadMutex); + OIC_LOG(DEBUG, TAG, "waiting send finish signal"); ca_cond_wait(g_threadCond, g_threadMutex); OIC_LOG(DEBUG, TAG, "the data was sent"); - ca_mutex_unlock(g_threadMutex); } + ca_mutex_unlock(g_threadMutex); if (isAttached) { @@ -858,13 +860,14 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t* data, OIC_LOG(DEBUG, TAG, "connection routine is finished for multicast"); // wait for finish to send data through "CALeGattServicesDiscoveredCallback" + ca_mutex_lock(g_threadMutex); if (!g_isFinishedSendData) { - ca_mutex_lock(g_threadMutex); + OIC_LOG(DEBUG, TAG, "waiting send finish signal"); ca_cond_wait(g_threadCond, g_threadMutex); - OIC_LOG(DEBUG, TAG, "the data was sent for All devices"); - ca_mutex_unlock(g_threadMutex); + OIC_LOG(DEBUG, TAG, "the data was sent"); } + ca_mutex_unlock(g_threadMutex); // start LE Scan again res = CALEClientStartScan(); @@ -3093,7 +3096,7 @@ jstring CALEClientGetLEAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice) { OIC_LOG(ERROR, TAG, "jarrayObj is null"); (*env)->ReleaseStringUTFChars(env, jni_btTargetAddress, targetAddress); - return CA_STATUS_FAILED; + return NULL; } OIC_LOG(DEBUG, TAG, "CALL API - bluetoothGatt.getDevice()"); @@ -3484,6 +3487,8 @@ void CALEClientCreateDeviceList() */ void CALEClientUpdateSendCnt(JNIEnv *env) { + OIC_LOG(DEBUG, TAG, "CALEClientUpdateSendCnt"); + VERIFY_NON_NULL_VOID(env, TAG, "env is null"); // mutex lock ca_mutex_lock(g_threadMutex); @@ -4219,12 +4224,21 @@ Java_org_iotivity_ca_CaLeClientInterface_caLeGattDescriptorWriteCallback(JNIEnv VERIFY_NON_NULL_VOID(obj, TAG, "obj is null"); VERIFY_NON_NULL_VOID(gatt, TAG, "gatt is null"); - CAResult_t res = CALEClientWriteCharacteristic(env, gatt); - if (CA_STATUS_OK != res) + jint gatt_success = CALEGetConstantsValue(env, CLASSPATH_BT_GATT, "GATT_SUCCESS"); + if (gatt_success != status) // error { - OIC_LOG(ERROR, TAG, "CALEClientWriteCharacteristic has failed"); goto error_exit; } + + if (g_sendBuffer) + { + CAResult_t res = CALEClientWriteCharacteristic(env, gatt); + if (CA_STATUS_OK != res) + { + OIC_LOG(ERROR, TAG, "CALEClientWriteCharacteristic has failed"); + goto error_exit; + } + } return; // error label. -- 2.7.4