const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
- if (!CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
+ if (CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
{
- CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) OICCalloc(1, sizeof(*socketInfo));
- if (!socketInfo)
- {
- OIC_LOG(ERROR, TAG, "Out of memory");
- return;
- }
+ OIC_LOG(DEBUG, TAG, "the address exists in deviceObjectList. remove it to add new");
+ CAEDRNativeRemoveDeviceSocketBaseAddr(env, jni_remoteAddress);
+ }
- jmethodID jni_mid_getInputStream = CAGetJNIMethodID(env,
- "android/bluetooth/BluetoothSocket",
- "getInputStream",
- "()Ljava/io/InputStream;");
- if (!jni_mid_getInputStream)
- {
- OIC_LOG(ERROR, TAG, "jni_mid_getInputStream is null");
- return;
- }
+ (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
+ (*env)->DeleteLocalRef(env, jni_remoteAddress);
- jobject jni_obj_inputStream = (*env)->CallObjectMethod(env, deviceSocket,
- jni_mid_getInputStream);
- if (!jni_obj_inputStream)
- {
- OIC_LOG(ERROR, TAG, "jni_obj_inputStream is null");
- return;
- }
+ CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) OICCalloc(1, sizeof(*socketInfo));
+ if (!socketInfo)
+ {
+ OIC_LOG(ERROR, TAG, "Out of memory");
+ return;
+ }
+
+ jmethodID jni_mid_getInputStream = CAGetJNIMethodID(env, "android/bluetooth/BluetoothSocket",
+ "getInputStream",
+ "()Ljava/io/InputStream;");
+ if (!jni_mid_getInputStream)
+ {
+ OIC_LOG(ERROR, TAG, "jni_mid_getInputStream is null");
+ return;
+ }
- socketInfo->deviceSocket = (*env)->NewGlobalRef(env, deviceSocket);
- socketInfo->inputStream = (*env)->NewGlobalRef(env, jni_obj_inputStream);
- (*env)->DeleteLocalRef(env, jni_obj_inputStream);
+ jobject jni_obj_inputStream = (*env)->CallObjectMethod(env, deviceSocket,
+ jni_mid_getInputStream);
+ if (!jni_obj_inputStream)
+ {
+ OIC_LOG(ERROR, TAG, "jni_obj_inputStream is null");
+ return;
+ }
- bool result = u_arraylist_add(g_deviceObjectList, (void *) socketInfo);
- if (!result)
- {
- OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
- OICFree(socketInfo);
- return;
- }
+ socketInfo->deviceSocket = (*env)->NewGlobalRef(env, deviceSocket);
+ socketInfo->inputStream = (*env)->NewGlobalRef(env, jni_obj_inputStream);
+ (*env)->DeleteLocalRef(env, jni_obj_inputStream);
- OIC_LOG(DEBUG, TAG, "add new device socket object to list");
+ bool result = u_arraylist_add(g_deviceObjectList, (void *) socketInfo);
+ if (!result)
+ {
+ OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
+ OICFree(socketInfo);
+ return;
}
- (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
- (*env)->DeleteLocalRef(env, jni_remoteAddress);
+
+ OIC_LOG(DEBUG, TAG, "add new device socket object to list");
}
bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
return false;
}
- jint length = u_arraylist_length(g_deviceStateList);
+ jint length = u_arraylist_length(g_deviceObjectList);
for (jint index = 0; index < length; index++)
{
CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList,
return;
}
- jint length = u_arraylist_length(g_deviceStateList);
+ jint length = u_arraylist_length(g_deviceObjectList);
for (jint index = 0; index < length; index++)
{
jobject jni_obj_socket = (jobject) u_arraylist_get(g_deviceObjectList, index);
return;
}
- jint length = u_arraylist_length(g_deviceStateList);
+ jint length = u_arraylist_length(g_deviceObjectList);
for (jint index = 0; index < length; index++)
{
return;
}
- jint length = u_arraylist_length(g_deviceStateList);
+ jint length = u_arraylist_length(g_deviceObjectList);
for (jint index = 0; index < length; index++)
{
CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList,
return;
}
- jint length = u_arraylist_length(g_deviceStateList);
+ jint length = u_arraylist_length(g_deviceObjectList);
for (jint index = 0; index < length; index++)
{
CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList,
return NULL;
}
- jint length = u_arraylist_length(g_deviceStateList);
+ jint length = u_arraylist_length(g_deviceObjectList);
for (jint index = 0; index < length; index++)
{
CAEDRSocketInfo_t *socketInfo = (CAEDRSocketInfo_t *) u_arraylist_get(g_deviceObjectList,