// it will be prevent to start send logic when adapter has stopped.
static bool g_isStartedLEClient = false;
-static bool g_isStartedMulticastServer = false;
static bool g_isStartedScan = false;
static jbyteArray g_sendBuffer = NULL;
if (g_leScanCallback)
{
(*env)->DeleteGlobalRef(env, g_leScanCallback);
+ g_leScanCallback = NULL;
}
if (g_leGattCallback)
{
(*env)->DeleteGlobalRef(env, g_leGattCallback);
+ g_leGattCallback = NULL;
}
if (g_sendBuffer)
{
(*env)->DeleteGlobalRef(env, g_sendBuffer);
+ g_sendBuffer = NULL;
}
if (g_uuidList)
{
(*env)->DeleteGlobalRef(env, g_uuidList);
+ g_uuidList = NULL;
}
CAResult_t ret = CALEClientRemoveAllDeviceState();
OIC_LOG(ERROR, TAG, "CALEClientRemoveAllGattObjs has failed");
}
- g_isStartedMulticastServer = false;
CALEClientSetScanFlag(false);
- CALEClientSetSendFinishFlag(false);
+ CALEClientSetSendFinishFlag(true);
CALEClientTerminateGattMutexVariables();
CALEClientDestroyJniInterface();
CAResult_t CALEClientStartMulticastServer()
{
- OIC_LOG(DEBUG, TAG, "CALEClientStartMulticastServer");
-
- if (g_isStartedMulticastServer)
- {
- OIC_LOG(ERROR, TAG, "server is already started..it will be skipped");
- return CA_STATUS_FAILED;
- }
-
- if (!g_jvm)
- {
- OIC_LOG(ERROR, TAG, "g_jvm is null");
- return CA_STATUS_FAILED;
- }
-
- bool isAttached = false;
- JNIEnv* env;
- jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
- if (JNI_OK != res)
- {
- OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
- res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
-
- if (JNI_OK != res)
- {
- OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
- return CA_STATUS_FAILED;
- }
- isAttached = true;
- }
+ OIC_LOG(DEBUG, TAG, "it is not needed in this platform");
- g_isStartedMulticastServer = true;
- CAResult_t ret = CALEClientStartScan();
- if (CA_STATUS_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
- }
-
- if (isAttached)
- {
- (*g_jvm)->DetachCurrentThread(g_jvm);
- }
-
- return ret;
+ return CA_NOT_SUPPORTED;
}
void CALEClientStopUnicastServer()
void CALEClientStopMulticastServer()
{
OIC_LOG(DEBUG, TAG, "CALEClientStopMulticastServer");
- g_isStartedMulticastServer = false;
- CAResult_t res = CALEClientStopScan();
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
- return;
- }
}
void CALEClientSetCallback(CAPacketReceiveCallback callback)
CAResult_t CALEClientStartScan()
{
- if (!g_isStartedMulticastServer)
- {
- OIC_LOG(ERROR, TAG, "server is not started yet..scan will be passed");
- return CA_STATUS_FAILED;
- }
-
if (!g_isStartedLEClient)
{
OIC_LOG(ERROR, TAG, "LE client is not started");
jni_mid_startLeScan, callback);
if (!jni_obj_startLeScan)
{
- OIC_LOG(ERROR, TAG, "startLeScan is failed");
- return CA_STATUS_FAILED;
+ OIC_LOG(INFO, TAG, "startLeScan is failed");
}
else
{
jni_mid_startLeScan, uuids, callback);
if (!jni_obj_startLeScan)
{
- OIC_LOG(ERROR, TAG, "startLeScan With UUID is failed");
- return CA_STATUS_FAILED;
+ OIC_LOG(INFO, TAG, "startLeScan With UUID is failed");
}
else
{
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
VERIFY_NON_NULL_RET(bluetoothDevice, TAG, "bluetoothDevice is null", NULL);
+ if (!g_leGattCallback)
+ {
+ OIC_LOG(INFO, TAG, "g_leGattCallback is null");
+ return NULL;
+ }
+
if (!CALEIsEnableBTAdapter(env))
{
OIC_LOG(INFO, TAG, "BT adapter is not enabled");
if (!g_deviceList)
{
OIC_LOG(ERROR, TAG, "gdevice_list is null");
+
+ CALEClientSetScanFlag(false);
+ if (CA_STATUS_OK != CALEClientStopScan())
+ {
+ OIC_LOG(ERROR, TAG, "CALEClientStopScan has failed");
+ }
+
ca_mutex_unlock(g_deviceListMutex);
return CA_STATUS_FAILED;
}
g_threadWriteCharacteristicCond = ca_cond_new();
}
- CAResult_t res = CALEClientStartMulticastServer();
- if (CA_STATUS_OK != res)
- {
- OIC_LOG(ERROR, TAG, "CALEClientStartMulticastServer has failed");
- }
- else
+ CAResult_t ret = CALEClientStartScan();
+ if (CA_STATUS_OK != ret)
{
- g_isStartedLEClient = true;
+ OIC_LOG(ERROR, TAG, "CALEClientStartScan has failed");
+ return ret;
}
- return res;
+ g_isStartedLEClient = true;
+ return CA_STATUS_OK;
}
void CAStopLEGattClient()
ca_mutex_lock(g_threadMutex);
OIC_LOG(DEBUG, TAG, "signal - connection cond");
ca_cond_signal(g_threadCond);
+ CALEClientSetSendFinishFlag(true);
ca_mutex_unlock(g_threadMutex);
ca_mutex_lock(g_threadWriteCharacteristicMutex);
ca_cond_signal(g_threadWriteCharacteristicCond);
ca_mutex_unlock(g_threadWriteCharacteristicMutex);
- ca_mutex_lock(g_threadSendMutex);
- OIC_LOG(DEBUG, TAG, "signal - send cond");
- ca_cond_signal(g_deviceDescCond);
- ca_mutex_unlock(g_threadSendMutex);
-
ca_mutex_lock(g_deviceScanRetryDelayMutex);
OIC_LOG(DEBUG, TAG, "signal - delay cond");
ca_cond_signal(g_deviceScanRetryDelayCond);
ca_mutex_unlock(g_deviceScanRetryDelayMutex);
-
ca_cond_free(g_deviceDescCond);
ca_cond_free(g_threadCond);
ca_cond_free(g_threadWriteCharacteristicCond);
return CA_STATUS_FAILED;
}
+ OIC_LOG(DEBUG, TAG, "CALL API - notifyCharacteristicChanged");
+
jboolean jni_boolean_notifyCharacteristicChanged = (*env)->CallBooleanMethod(
env, g_bluetoothGattServer, jni_mid_notifyCharacteristicChanged, device, responseData,
JNI_FALSE);
if (g_obj_bluetoothDevice)
{
(*env)->DeleteGlobalRef(env, g_obj_bluetoothDevice);
+ g_obj_bluetoothDevice = NULL;
+ }
+
+ if (jarrayObj)
+ {
+ g_obj_bluetoothDevice = (*env)->NewGlobalRef(env, jarrayObj);
}
- g_obj_bluetoothDevice = (*env)->NewGlobalRef(env, jarrayObj);
(*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
break;
}
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "send has failed");
- if (g_obj_bluetoothDevice)
- {
- (*env)->DeleteGlobalRef(env, g_obj_bluetoothDevice);
- g_obj_bluetoothDevice = NULL;
- }
goto error_exit;
}
}
g_sendBuffer = NULL;
}
+ if (g_obj_bluetoothDevice)
+ {
+ (*env)->DeleteGlobalRef(env, g_obj_bluetoothDevice);
+ g_obj_bluetoothDevice = NULL;
+ }
+
ca_mutex_unlock(g_threadSendMutex);
return CA_SEND_FAILED;
}
if (g_obj_bluetoothDevice)
{
(*env)->DeleteGlobalRef(env, g_obj_bluetoothDevice);
+ g_obj_bluetoothDevice = NULL;
+ }
+
+ if (jarrayObj)
+ {
+ g_obj_bluetoothDevice = (*env)->NewGlobalRef(env, jarrayObj);
}
- g_obj_bluetoothDevice = (*env)->NewGlobalRef(env, jarrayObj);
CAResult_t res = CALEServerSend(env, g_obj_bluetoothDevice, jni_bytearr_data);
if (CA_STATUS_OK != res)
(*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
(*env)->ReleaseStringUTFChars(env, address, remoteAddress);
(*env)->DeleteGlobalRef(env, jarrayObj);
+ jarrayObj = NULL;
if (NULL == u_arraylist_remove(g_connectedDeviceList, index))
{