static CABLEDataReceivedCallback g_CABLEClientDataReceivedCallback = NULL;
-static jboolean g_autoConnectFlag = JNI_FALSE;
-
/**
* check if retry logic for connection routine has to be stopped or not.
* in case of error value including this method, connection routine has to be stopped.
g_threadCond = NULL;
g_threadWriteCharacteristicCond = NULL;
g_isSignalSetFlag = false;
- CALEClientSetAutoConnectFlag(JNI_FALSE);
if (isAttached)
{
}
// connection request
- jobject newGatt = CALEClientConnect(env, device, CALEClientGetAutoConnectFlag());
+ jobject newGatt = CALEClientConnect(env, device,
+ CALEClientGetAutoConnectFlag(env, jni_address));
if (NULL == newGatt)
{
OIC_LOG(ERROR, TAG, "CALEClientConnect has failed");
return CA_STATUS_OK;
}
-void CALEClientSetAutoConnectFlag(jboolean flag)
+CAResult_t CALEClientSetAutoConnectFlag(JNIEnv *env, jstring jni_address, jboolean flag)
{
- OIC_LOG_V(INFO, TAG, "auto connect flag is set %d", flag);
- g_autoConnectFlag = flag;
+ OIC_LOG(DEBUG, TAG, "IN - CALEClientSetAutoConnectFlag");
+ VERIFY_NON_NULL(env, TAG, "env");
+ VERIFY_NON_NULL(jni_address, TAG, "jni_address");
+
+ ca_mutex_lock(g_deviceStateListMutex);
+
+ char* address = (char*)(*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ OIC_LOG(ERROR, TAG, "address is not available");
+ return CA_STATUS_FAILED;
+ }
+
+ if (CALEClientIsDeviceInList(address))
+ {
+ CALEState_t* curState = CALEClientGetStateInfo(address);
+ if(!curState)
+ {
+ OIC_LOG(ERROR, TAG, "curState is null");
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ ca_mutex_unlock(g_deviceStateListMutex);
+ return CA_STATUS_FAILED;
+ }
+ OIC_LOG_V(INFO, TAG, "auto connect flag is set %d", flag);
+
+ curState->autoConnectFlag = flag;
+ }
+
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ ca_mutex_unlock(g_deviceStateListMutex);
+ OIC_LOG(DEBUG, TAG, "OUT - CALEClientSetAutoConnectFlag");
+ return CA_STATUS_OK;
}
-jboolean CALEClientGetAutoConnectFlag()
+jboolean CALEClientGetAutoConnectFlag(JNIEnv *env, jstring jni_address)
{
- OIC_LOG_V(INFO, TAG, "auto connect flag is %d", g_autoConnectFlag);
- return g_autoConnectFlag;
+ OIC_LOG(DEBUG, TAG, "IN - CALEClientGetAutoConnectFlag");
+ VERIFY_NON_NULL_RET(env, TAG, "env", false);
+ VERIFY_NON_NULL_RET(jni_address, TAG, "jni_address", false);
+
+ ca_mutex_lock(g_deviceStateListMutex);
+
+ char* address = (char*)(*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ OIC_LOG(ERROR, TAG, "address is not available");
+ return JNI_FALSE;
+ }
+
+ CALEState_t* curState = CALEClientGetStateInfo(address);
+ if(!curState)
+ {
+ OIC_LOG(INFO, TAG, "there is no information. auto connect flag is false");
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ ca_mutex_unlock(g_deviceStateListMutex);
+ return JNI_FALSE;
+ }
+ OIC_LOG_V(INFO, TAG, "auto connect flag is %d", curState->autoConnectFlag);
+
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ ca_mutex_unlock(g_deviceStateListMutex);
+
+ OIC_LOG(DEBUG, TAG, "OUT - CALEClientGetAutoConnectFlag");
+ return curState->autoConnectFlag;
}
jobject CALEClientConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect)
{
state->notificationState = curState->notificationState;
}
+ state->autoConnectFlag = curState->autoConnectFlag;
// delete previous state for update new state
CAResult_t res = CALEClientRemoveDeviceState(state->address);
return CA_STATUS_OK;
}
+CAResult_t CALEClientResetDeviceStateForAll()
+{
+ OIC_LOG(DEBUG, TAG, "CALEClientResetDeviceStateForAll");
+
+ ca_mutex_lock(g_deviceStateListMutex);
+ if (!g_deviceStateList)
+ {
+ OIC_LOG(ERROR, TAG, "g_deviceStateList is null");
+ ca_mutex_unlock(g_deviceStateListMutex);
+ return CA_STATUS_FAILED;
+ }
+
+ size_t length = u_arraylist_length(g_deviceStateList);
+ for (size_t index = 0; index < length; index++)
+ {
+ CALEState_t* state = (CALEState_t*) u_arraylist_get(g_deviceStateList, index);
+ if (!state)
+ {
+ OIC_LOG(ERROR, TAG, "jarrayObj is null");
+ continue;
+ }
+
+ // autoConnectFlag value will be not changed,
+ // since it has reset only termination case.
+ state->connectedState = STATE_DISCONNECTED;
+ state->notificationState = STATE_CHARACTER_UNSET;
+ state->sendState = STATE_SEND_NONE;
+ }
+ ca_mutex_unlock(g_deviceStateListMutex);
+
+ return CA_STATUS_OK;
+}
+
CAResult_t CALEClientRemoveDeviceState(const char* remoteAddress)
{
OIC_LOG(DEBUG, TAG, "CALEClientRemoveDeviceState");
goto error_exit;
}
- jobject newGatt = CALEClientConnect(env, btObject, CALEClientGetAutoConnectFlag());
+ jobject newGatt = CALEClientConnect(env, btObject,
+ CALEClientGetAutoConnectFlag(env, leAddress));
if (!newGatt)
{
OIC_LOG(ERROR, TAG, "CALEClientConnect has failed");
jint connectedState;
uint16_t notificationState;
uint16_t sendState;
+ jboolean autoConnectFlag;
} CALEState_t;
/**
/**
* set auto connect flag for connectGatt API.
- * @param[in] flag auto connect flag.
+ * @param[in] env JNI interface pointer.
+ * @param[in] jni_address remote address.
+ * @param[in] flag auto connect flag.
*/
-void CALEClientSetAutoConnectFlag(jboolean flag);
+CAResult_t CALEClientSetAutoConnectFlag(JNIEnv *env, jstring jni_address, jboolean flag);
/**
* get auto connect flag.
+ * @param[in] env JNI interface pointer.
+ * @param[in] jni_address remote address.
* @return current auto connect flag;
*/
-jboolean CALEClientGetAutoConnectFlag();
+jboolean CALEClientGetAutoConnectFlag(JNIEnv *env, jstring jni_address);
/**
* connect to gatt server hosted.
CAResult_t CALEClientRemoveAllDeviceState();
/**
+ * Reset values of device state for all of devices.
+ * this method has to be invoked when BT adapter is disabled.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientResetDeviceStateForAll();
+
+/**
* remove the device state for a remote device.
* @param[in] remoteAddress remote address.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).