1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
23 #include <android/log.h>
24 #include "caedrutils.h"
26 #include "oic_malloc.h"
27 #include "cathreadpool.h"
28 #include "uarraylist.h"
30 #define ERROR_CODE (-1)
31 #define TAG PCF("CA_EDR_UTILS")
33 static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
34 static const char METHODID_STRINGNONPARAM[] = "()Ljava/lang/String;";
35 static const char CLASSPATH_BT_ADPATER[] = "android/bluetooth/BluetoothAdapter";
36 static const char CLASSPATH_BT_DEVICE[] = "android/bluetooth/BluetoothDevice";
37 static const char CLASSPATH_BT_SOCKET[] = "android/bluetooth/BluetoothSocket";
39 static u_arraylist_t *g_deviceStateList = NULL;
40 static u_arraylist_t *g_deviceObjectList = NULL;
42 // get address from bluetooth socket
43 jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSocketObj)
45 if (!bluetoothSocketObj)
47 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: bluetoothSocketObj is null");
51 jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
52 if (!jni_cid_BTSocket)
54 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_cid_BTSocket is null");
58 jmethodID jni_mid_getRemoteDevice = (*env)->GetMethodID(
59 env, jni_cid_BTSocket, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;");
60 if (!jni_mid_getRemoteDevice)
62 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_mid_getRemoteDevice is null");
66 jobject jni_obj_remoteBTDevice = (*env)->CallObjectMethod(env, bluetoothSocketObj,
67 jni_mid_getRemoteDevice);
68 if (!jni_obj_remoteBTDevice)
70 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_obj_remoteBTDevice is null");
74 jclass jni_cid_BTDevice = (*env)->FindClass(env, CLASSPATH_BT_DEVICE);
75 if (!jni_cid_BTDevice)
77 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_cid_BTDevice is null");
80 jmethodID j_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTDevice, "getAddress",
81 METHODID_STRINGNONPARAM);
82 if (!j_mid_getAddress)
84 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: j_mid_getAddress is null");
88 jstring j_str_address = (*env)->CallObjectMethod(env, jni_obj_remoteBTDevice, j_mid_getAddress);
91 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: j_str_address is null");
98 jstring CAEDRNativeGetLocalDeviceAddress(JNIEnv* env)
100 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
101 if (!jni_cid_BTAdapter)
103 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_cid_BTAdapter is null");
107 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
109 METHODID_OBJECTNONPARAM);
110 if (!jni_mid_getDefaultAdapter)
112 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_mid_getDefaultAdapter is null");
116 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTAdapter, "getAddress",
117 METHODID_STRINGNONPARAM);
118 if (!jni_mid_getAddress)
120 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_mid_getAddress is null");
124 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
125 jni_mid_getDefaultAdapter);
126 if (!jni_obj_BTAdapter)
128 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_obj_BTAdapter is null");
132 jstring jni_str_address = (jstring)(*env)->CallObjectMethod(env, jni_obj_BTAdapter,
134 if (!jni_str_address)
136 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_str_address is null");
140 return jni_str_address;
143 jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env)
145 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
146 if (!jni_cid_BTAdapter)
148 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_BTAdapter is null");
152 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
154 METHODID_OBJECTNONPARAM);
155 if (!jni_mid_getDefaultAdapter)
157 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: default adapter is null");
161 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
162 jni_mid_getDefaultAdapter);
163 if (!jni_obj_BTAdapter)
165 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: bluetooth adapter is null");
169 // Get a list of currently paired devices
170 jmethodID jni_mid_getBondedDevices = (*env)->GetMethodID(env, jni_cid_BTAdapter,
172 "()Ljava/util/Set;");
173 if (!jni_mid_getBondedDevices)
175 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_getBondedDevicesr is null");
179 jobject jni_obj_setPairedDevices = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
180 jni_mid_getBondedDevices);
181 if (!jni_obj_setPairedDevices)
183 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_obj_setPairedDevices is null");
187 // Convert the set to an object array
188 // object[] array = Set<BluetoothDevice>.toArray();
189 jclass jni_cid_Set = (*env)->FindClass(env, "java/util/Set");
192 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_Set is null");
195 jmethodID jni_mid_toArray = (*env)->GetMethodID(env, jni_cid_Set, "toArray",
196 "()[Ljava/lang/Object;");
198 if (!jni_mid_toArray)
200 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_toArray is null");
204 jobjectArray jni_arrayPairedDevices = (jobjectArray)(
205 (*env)->CallObjectMethod(env, jni_obj_setPairedDevices, jni_mid_toArray));
206 if (!jni_arrayPairedDevices)
208 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_arrayPairedDevices is null");
212 return jni_arrayPairedDevices;
215 jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env)
217 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
218 if (!jni_cid_BTAdapter)
220 OIC_LOG(ERROR, TAG, "[EDR][Native] getBTStateOnInfo: jni_cid_BTAdapter is null");
224 jfieldID jni_fid_stateon = (*env)->GetStaticFieldID(env, jni_cid_BTAdapter, "STATE_ON", "I");
225 if (jni_fid_stateon == 0)
227 OIC_LOG(ERROR, TAG, "[EDR][Native] get_field_state is 0");
230 jint jni_int_val = (*env)->GetStaticIntField(env, jni_cid_BTAdapter, jni_fid_stateon);
232 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] bluetooth state integer value : %d", jni_int_val);
237 jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env)
239 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
240 if (!jni_cid_BTAdapter)
242 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_BTAdapter: jni_cid_BTAdapter is null");
246 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
248 METHODID_OBJECTNONPARAM);
249 if (!jni_mid_getDefaultAdapter)
251 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getDefaultAdapter is null");
255 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
256 jni_mid_getDefaultAdapter);
257 if (!jni_obj_BTAdapter)
259 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_obj_BTAdapter is null");
264 jmethodID jni_mid_isEnable = (*env)->GetMethodID(env, jni_cid_BTAdapter, "isEnabled", "()Z");
265 if (!jni_mid_isEnable)
267 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_isEnable is null");
271 jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
272 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] adapter state is %d", jni_isEnable);
277 jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice)
279 if (!bluetoothDevice)
281 OIC_LOG(ERROR, TAG, "[EDR][Native] bluetoothDevice is null");
284 jclass jni_cid_device_list = (*env)->FindClass(env, "android/bluetooth/BluetoothDevice");
285 if (!jni_cid_device_list)
287 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_device_list is null");
291 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_device_list, "getAddress",
292 METHODID_STRINGNONPARAM);
293 if (!jni_mid_getAddress)
295 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getAddress is null");
299 jstring jni_address = (jstring)(*env)->CallObjectMethod(env, bluetoothDevice,
303 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_address is null");
312 void CAEDRNativeCreateDeviceStateList()
314 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceStateList");
316 // create new object array
317 if (NULL == g_deviceStateList)
319 OIC_LOG(DEBUG, TAG, "Create device list");
321 g_deviceStateList = u_arraylist_create();
325 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address)
329 OIC_LOG(ERROR, TAG, "[EDR][Native] address is null");
332 state_t *newstate = (state_t*) OICCalloc(1, sizeof(state_t));
335 OIC_LOG(ERROR, TAG, "[EDR][Native] newstate is null");
338 strcpy(newstate->address, address);
339 newstate->state = state;
341 CAEDRNativeAddDeviceStateToList(newstate);
344 void CAEDRNativeAddDeviceStateToList(state_t *state)
348 OIC_LOG(ERROR, TAG, "[EDR][Native] device is null");
352 if (!g_deviceStateList)
354 OIC_LOG(ERROR, TAG, "[EDR][Native] gdevice_list is null");
358 if (CAEDRNativeIsDeviceInList(state->address))
360 CAEDRNativeRemoveDevice(state->address); // delete previous state for update new state
362 u_arraylist_add(g_deviceStateList, state); // update new state
363 OIC_LOG_V(DEBUG, TAG, "Set State Info to List : %d", state->state);
366 bool CAEDRNativeIsDeviceInList(const char* remoteAddress)
371 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
375 jint length = u_arraylist_length(g_deviceStateList);
376 for (index = 0; index < length; index++)
378 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
381 OIC_LOG(ERROR, TAG, "[EDR][Native] state_t object is null");
385 if (!strcmp(remoteAddress, state->address))
387 OIC_LOG(DEBUG, TAG, "the device is already set");
396 OIC_LOG(DEBUG, TAG, "there are no the device in list.");
400 void CAEDRNativeRemoveAllDeviceState()
402 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveAllDevices");
404 if (!g_deviceStateList)
406 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
411 jint length = u_arraylist_length(g_deviceStateList);
412 for (index = 0; index < length; index++)
414 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
417 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
423 OICFree(g_deviceStateList);
424 g_deviceStateList = NULL;
428 void CAEDRNativeRemoveDevice(const char *remoteAddress)
430 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList");
432 if (!g_deviceStateList)
434 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
439 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
444 jint length = u_arraylist_length(g_deviceStateList);
445 for (index = 0; index < length; index++)
447 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
450 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
454 if (!strcmp(state->address, remoteAddress))
456 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove state : %s", remoteAddress);
459 CAEDRReorderingDeviceList(index);
466 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
468 OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice");
472 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
473 return STATE_DISCONNECTED;
476 if (!g_deviceStateList)
478 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
479 return STATE_DISCONNECTED;
483 jint length = u_arraylist_length(g_deviceStateList);
484 for (index = 0; index < length; index++)
486 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
489 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
493 if (!strcmp(state->address, remoteAddress))
495 OIC_LOG(DEBUG, TAG, "[EDR][Native] check whether it is connected or not");
500 return STATE_DISCONNECTED;
503 void CAEDRReorderingDeviceList(uint32_t index)
505 if (index >= g_deviceStateList->length)
510 if (index < g_deviceStateList->length - 1)
512 memmove(&g_deviceStateList->data[index], &g_deviceStateList->data[index + 1],
513 (g_deviceStateList->length - index - 1) * sizeof(void *));
516 g_deviceStateList->size--;
517 g_deviceStateList->length--;
521 * Device Socket Object List
523 void CAEDRNativeCreateDeviceSocketList()
525 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceSocketList");
527 // create new object array
528 if (NULL == g_deviceObjectList)
530 OIC_LOG(DEBUG, TAG, "Create Device object list");
532 g_deviceObjectList = u_arraylist_create();
536 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket)
538 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeAddDeviceobjToList");
542 OIC_LOG(ERROR, TAG, "[EDR][Native] Device is null");
546 if (!g_deviceObjectList)
548 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
552 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
553 if (!jni_remoteAddress)
555 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_remoteAddress is null");
559 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
561 if (!CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
563 jobject gDeviceSocker = (*env)->NewGlobalRef(env, deviceSocket);
564 u_arraylist_add(g_deviceObjectList, gDeviceSocker);
565 OIC_LOG(DEBUG, TAG, "Set Socket Object to Array");
567 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
570 bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
572 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeIsDeviceObjInList");
576 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
580 jint length = u_arraylist_length(g_deviceStateList);
581 for (index = 0; index < length; index++)
584 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
587 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
591 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
594 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
598 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
601 OIC_LOG(DEBUG, TAG, "[EDR][Native] setAddress is null");
605 if (!strcmp(remoteAddress, setAddress))
607 OIC_LOG(DEBUG, TAG, "the device is already set");
608 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
613 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
618 OIC_LOG(DEBUG, TAG, "there are no the Device obejct in list. we can add");
622 void CAEDRNativeSocketCloseToAll(JNIEnv *env)
624 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeSocketCloseToAll");
626 if (!g_deviceObjectList)
628 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
632 jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
633 if (!jni_cid_BTSocket)
635 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_cid_BTSocket is null");
639 jmethodID jni_mid_close = (*env)->GetMethodID(env, jni_cid_BTSocket, "close", "()V");
642 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_mid_close is null");
647 jint length = u_arraylist_length(g_deviceStateList);
648 for (index = 0; index < length; index++)
650 jobject jni_obj_socket = (jobject) u_arraylist_get(g_deviceObjectList, index);
653 OIC_LOG(ERROR, TAG, "[EDR][Native] socket obj is null");
657 (*env)->CallVoidMethod(env, jni_obj_socket, jni_mid_close);
659 if ((*env)->ExceptionCheck(env))
661 OIC_LOG(ERROR, TAG, "[EDR][Native] close: close is Failed!!!");
662 (*env)->ExceptionDescribe(env);
663 (*env)->ExceptionClear(env);
669 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env)
671 OIC_LOG(DEBUG, TAG, "CANativeRemoveAllDeviceObjsList");
673 if (!g_deviceObjectList)
675 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
680 jint length = u_arraylist_length(g_deviceStateList);
681 for (index = 0; index < length; index++)
683 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
686 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
689 (*env)->DeleteGlobalRef(env, jarrayObj);
692 OICFree(g_deviceObjectList);
693 g_deviceObjectList = NULL;
697 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket)
699 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
701 if (!g_deviceObjectList)
703 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
708 jint length = u_arraylist_length(g_deviceStateList);
709 for (index = 0; index < length; index++)
711 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
714 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
718 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
721 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
725 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
726 if (!jni_remoteAddress)
728 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_remoteAddress is null");
732 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
733 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
735 if (!strcmp(setAddress, remoteAddress))
737 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove object : %s", remoteAddress);
738 (*env)->DeleteGlobalRef(env, jarrayObj);
739 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
740 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
742 CAEDRReorderingDeviceSocketList(index);
745 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
746 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
749 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
753 void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address)
755 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
757 if (!g_deviceObjectList)
759 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
764 jint length = u_arraylist_length(g_deviceStateList);
765 for (index = 0; index < length; index++)
767 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
770 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
774 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
777 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
780 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
781 const char* remoteAddress = (*env)->GetStringUTFChars(env, address, NULL);
783 if (!strcmp(setAddress, remoteAddress))
785 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
786 (*env)->DeleteGlobalRef(env, jarrayObj);
787 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
788 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
790 CAEDRReorderingDeviceSocketList(index);
793 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
794 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
797 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
801 jobject CAEDRNativeGetDeviceSocket(uint32_t idx)
803 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
805 if (!g_deviceObjectList)
807 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
811 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, idx);
814 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is not available");
820 jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddress)
822 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
824 if (!g_deviceObjectList)
826 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
831 jint length = u_arraylist_length(g_deviceStateList);
832 for (index = 0; index < length; index++)
834 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
837 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
841 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
844 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
847 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
849 if (!strcmp(setAddress, remoteAddress))
851 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
852 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
855 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
861 uint32_t CAEDRGetSocketListLength()
863 if (!g_deviceObjectList)
865 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
869 uint32_t length = u_arraylist_length(g_deviceObjectList);
874 void CAEDRReorderingDeviceSocketList(uint32_t index)
876 if (index >= g_deviceObjectList->length)
881 if (index < g_deviceObjectList->length - 1)
883 memmove(&g_deviceObjectList->data[index], &g_deviceObjectList->data[index + 1],
884 (g_deviceObjectList->length - index - 1) * sizeof(void *));
887 g_deviceObjectList->size--;
888 g_deviceObjectList->length--;