From: jihwan.seo Date: Wed, 9 Mar 2016 00:58:18 +0000 (+0900) Subject: clean up for android BLE client X-Git-Tag: 1.2.0+RC1~538 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a4768ab089d9b091a2b2dfe564364aa8b60d06f8;p=platform%2Fupstream%2Fiotivity.git clean up for android BLE client - release variable related to JNI - terminate Glabal variable - add some comment Change-Id: I342a7fd9a8550d0a3c2bf139254e5a147e2dd4dc Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/5591 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz (cherry picked from commit df1c2dcd5815b6fc069d13552069365c297adc75) Reviewed-on: https://gerrit.iotivity.org/gerrit/5727 --- diff --git a/android/android_api/base/jni/JniCaInterface.c b/android/android_api/base/jni/JniCaInterface.c index 13b7042..d641f3d 100644 --- a/android/android_api/base/jni/JniCaInterface.c +++ b/android/android_api/base/jni/JniCaInterface.c @@ -258,6 +258,8 @@ Java_org_iotivity_ca_CaInterface_caManagerSetAutoConnectionDeviceInfo(JNIEnv *en } CASetAutoConnectionDeviceInfo(address); + + (*env)->ReleaseStringUTFChars(env, jaddress, address); } JNIEXPORT void JNICALL @@ -275,6 +277,8 @@ Java_org_iotivity_ca_CaInterface_caManagerUnsetAutoConnectionDeviceInfo(JNIEnv * } CAUnsetAutoConnectionDeviceInfo(address); + + (*env)->ReleaseStringUTFChars(env, jaddress, address); } JNIEXPORT void JNICALL diff --git a/resource/csdk/connectivity/api/cautilinterface.h b/resource/csdk/connectivity/api/cautilinterface.h index 5e852d4..cdd377b 100644 --- a/resource/csdk/connectivity/api/cautilinterface.h +++ b/resource/csdk/connectivity/api/cautilinterface.h @@ -54,8 +54,20 @@ typedef void (*CAAdapterStateChangedCB)(CATransportAdapter_t adapter, bool enabl CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB, CAConnectionStateChangedCB connStateCB); +/** + * Set device to handle for auto connection. + * @param[in] address LE address to set. + * + * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED. + */ CAResult_t CASetAutoConnectionDeviceInfo(const char* address); +/** + * Unset device to handle for auto connection. + * @param[in] address LE address to unset. + * + * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED. + */ CAResult_t CAUnsetAutoConnectionDeviceInfo(const char* address); #ifdef __ANDROID__ 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 8448de8..525f5e4 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c @@ -1051,7 +1051,7 @@ CAResult_t CALEClientSendData(JNIEnv *env, jobject device) // connection request jobject newGatt = CALEClientConnect(env, device, - CALEClientGetAutoConnectFlag(env, jni_address)); + JNI_FALSE); if (NULL == newGatt) { OIC_LOG(ERROR, TAG, "CALEClientConnect has failed"); @@ -1121,7 +1121,8 @@ CAResult_t CALEClientSendData(JNIEnv *env, jobject device) } OIC_LOG(DEBUG, TAG, "start to connect LE"); - jobject gatt = CALEClientConnect(env, device, JNI_TRUE); + jobject gatt = CALEClientConnect(env, device, + CALEClientGetAutoConnectFlag(env, jni_address)); if (NULL == gatt) { OIC_LOG(ERROR, TAG, "CALEClientConnect has failed"); @@ -2798,6 +2799,7 @@ CAResult_t CALEClientRemoveAllScanDevices(JNIEnv *env) continue; } (*env)->DeleteGlobalRef(env, jarrayObj); + jarrayObj = NULL; } OICFree(g_deviceList); @@ -2862,6 +2864,7 @@ CAResult_t CALEClientRemoveDeviceInScanDeviceList(JNIEnv *env, jstring address) { OIC_LOG_V(DEBUG, TAG, "remove object : %s", remoteAddress); (*env)->DeleteGlobalRef(env, jarrayObj); + jarrayObj = NULL; (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); (*env)->ReleaseStringUTFChars(env, address, remoteAddress); @@ -3052,6 +3055,7 @@ CAResult_t CALEClientRemoveAllGattObjs(JNIEnv *env) continue; } (*env)->DeleteGlobalRef(env, jarrayObj); + jarrayObj = NULL; } OICFree(g_gattObjectList); @@ -3124,6 +3128,7 @@ CAResult_t CALEClientRemoveGattObj(JNIEnv *env, jobject gatt) { OIC_LOG_V(DEBUG, TAG, "remove object : %s", remoteAddress); (*env)->DeleteGlobalRef(env, jarrayObj); + jarrayObj = NULL; (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress); @@ -3199,7 +3204,7 @@ CAResult_t CALEClientRemoveGattObjForAddr(JNIEnv *env, jstring addr) { OIC_LOG_V(DEBUG, TAG, "remove object : %s", remoteAddress); (*env)->DeleteGlobalRef(env, jarrayObj); - + jarrayObj = NULL; (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); (*env)->ReleaseStringUTFChars(env, addr, remoteAddress); if (NULL == u_arraylist_remove(g_gattObjectList, index)) @@ -4255,13 +4260,13 @@ Java_org_iotivity_ca_CaLeClientInterface_caLeGattConnectionStateChangeCallback(J goto error_exit; } - jobject newGatt = CALEClientConnect(env, btObject, - CALEClientGetAutoConnectFlag(env, leAddress)); + jobject newGatt = CALEClientConnect(env, btObject, JNI_TRUE); if (!newGatt) { OIC_LOG(ERROR, TAG, "CALEClientConnect has failed"); goto error_exit; } + return; } else diff --git a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c index 16122fe..6e9eae8 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c @@ -37,7 +37,7 @@ /** * Logging tag for module name. */ -#define CALEADAPTER_TAG "OIC_LE_ADAP" +#define CALEADAPTER_TAG "OIC_CA_LE_ADAP" /** * The MTU supported for BLE adapter @@ -390,6 +390,19 @@ static void CAFreeLEData(CALEData_t *bleData); */ static void CALEDataDestroyer(void *data, uint32_t size); +#ifndef SINGLE_THREAD +/** + * remove request or response data of send queue. + * + * @param[in] queueHandle queue to process the outgoing packets. + * @param[in] mutex mutex related to sender for client / server. + * @param[in] address target address to remove data in queue. + */ +static void CALERemoveSendQueueData(CAQueueingThread_t *queueHandle, + ca_mutex mutex, + const char* address); +#endif + static CAResult_t CAInitLEServerQueues() { OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN"); @@ -2217,25 +2230,19 @@ static void CALEConnectionStateChangedCb(CATransportAdapter_t adapter, const cha } } - if(g_bleServerSenderInfo) + // remove data of send queue. + if (g_bleClientSendQueueHandle) { - CABLESenderInfo_t *senderInfo = NULL; - uint32_t senderIndex = 0; - - if(CA_STATUS_OK == CALEGetSenderInfo(address, g_bleServerSenderInfo, &senderInfo, - &senderIndex)) - { - u_arraylist_remove(g_bleServerSenderInfo, senderIndex); - OICFree(senderInfo->defragData); - OICFree(senderInfo->remoteEndpoint); - OICFree(senderInfo); + CALERemoveSendQueueData(g_bleClientSendQueueHandle, + g_bleClientSendDataMutex, + address); + } - OIC_LOG(DEBUG, CALEADAPTER_TAG, "SenderInfo is removed for disconnection"); - } - else - { - OIC_LOG(DEBUG, CALEADAPTER_TAG, "SenderInfo doesn't exist"); - } + if (g_bleServerSendQueueHandle) + { + CALERemoveSendQueueData(g_bleServerSendQueueHandle, + g_bleServerSendDataMutex, + address); } #endif } @@ -2585,3 +2592,43 @@ static void CALEErrorHandler(const char *remoteAddress, OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler OUT"); } + +#ifndef SINGLE_THREAD +static void CALERemoveSendQueueData(CAQueueingThread_t *queueHandle, ca_mutex mutex, + const char* address) +{ + OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALERemoveSendQueueData"); + + VERIFY_NON_NULL_VOID(queueHandle, CALEADAPTER_TAG, "queueHandle"); + VERIFY_NON_NULL_VOID(address, CALEADAPTER_TAG, "address"); + + ca_mutex_lock(mutex); + while (u_queue_get_size(queueHandle->dataQueue) > 0) + { + OIC_LOG(DEBUG, CALEADAPTER_TAG, "get data from queue"); + u_queue_message_t *message = u_queue_get_element(queueHandle->dataQueue); + if (NULL != message) + { + CALEData_t *bleData = (CALEData_t *) message->msg; + if (bleData && bleData->remoteEndpoint) + { + if (!strcmp(bleData->remoteEndpoint->addr, address)) + { + OIC_LOG(DEBUG, CALEADAPTER_TAG, "found the message of disconnected device"); + if (NULL != queueHandle->destroy) + { + queueHandle->destroy(message->msg, message->size); + } + else + { + OICFree(message->msg); + } + + OICFree(message); + } + } + } + } + ca_mutex_unlock(mutex); +} +#endif