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 "oic_string.h"
28 #include "cathreadpool.h"
29 #include "uarraylist.h"
31 #define ERROR_CODE (-1)
32 #define TAG PCF("CA_EDR_UTILS")
34 static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
35 static const char METHODID_STRINGNONPARAM[] = "()Ljava/lang/String;";
36 static const char CLASSPATH_BT_ADPATER[] = "android/bluetooth/BluetoothAdapter";
37 static const char CLASSPATH_BT_DEVICE[] = "android/bluetooth/BluetoothDevice";
38 static const char CLASSPATH_BT_SOCKET[] = "android/bluetooth/BluetoothSocket";
40 static u_arraylist_t *g_deviceStateList = NULL;
41 static u_arraylist_t *g_deviceObjectList = NULL;
43 // get address from bluetooth socket
44 jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSocketObj)
46 if (!bluetoothSocketObj)
48 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: bluetoothSocketObj is null");
52 jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
53 if (!jni_cid_BTSocket)
55 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_cid_BTSocket is null");
59 jmethodID jni_mid_getRemoteDevice = (*env)->GetMethodID(
60 env, jni_cid_BTSocket, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;");
61 if (!jni_mid_getRemoteDevice)
63 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_mid_getRemoteDevice is null");
67 jobject jni_obj_remoteBTDevice = (*env)->CallObjectMethod(env, bluetoothSocketObj,
68 jni_mid_getRemoteDevice);
69 if (!jni_obj_remoteBTDevice)
71 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_obj_remoteBTDevice is null");
75 jclass jni_cid_BTDevice = (*env)->FindClass(env, CLASSPATH_BT_DEVICE);
76 if (!jni_cid_BTDevice)
78 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_cid_BTDevice is null");
81 jmethodID j_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTDevice, "getAddress",
82 METHODID_STRINGNONPARAM);
83 if (!j_mid_getAddress)
85 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: j_mid_getAddress is null");
89 jstring j_str_address = (*env)->CallObjectMethod(env, jni_obj_remoteBTDevice, j_mid_getAddress);
92 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: j_str_address is null");
99 jstring CAEDRNativeGetLocalDeviceAddress(JNIEnv* env)
101 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
102 if (!jni_cid_BTAdapter)
104 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_cid_BTAdapter is null");
108 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
110 METHODID_OBJECTNONPARAM);
111 if (!jni_mid_getDefaultAdapter)
113 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_mid_getDefaultAdapter is null");
117 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTAdapter, "getAddress",
118 METHODID_STRINGNONPARAM);
119 if (!jni_mid_getAddress)
121 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_mid_getAddress is null");
125 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
126 jni_mid_getDefaultAdapter);
127 if (!jni_obj_BTAdapter)
129 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_obj_BTAdapter is null");
133 jstring jni_str_address = (jstring)(*env)->CallObjectMethod(env, jni_obj_BTAdapter,
135 if (!jni_str_address)
137 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_str_address is null");
141 return jni_str_address;
144 jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env)
146 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
147 if (!jni_cid_BTAdapter)
149 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_BTAdapter is null");
153 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
155 METHODID_OBJECTNONPARAM);
156 if (!jni_mid_getDefaultAdapter)
158 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: default adapter is null");
162 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
163 jni_mid_getDefaultAdapter);
164 if (!jni_obj_BTAdapter)
166 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: bluetooth adapter is null");
170 // Get a list of currently paired devices
171 jmethodID jni_mid_getBondedDevices = (*env)->GetMethodID(env, jni_cid_BTAdapter,
173 "()Ljava/util/Set;");
174 if (!jni_mid_getBondedDevices)
176 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_getBondedDevicesr is null");
180 jobject jni_obj_setPairedDevices = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
181 jni_mid_getBondedDevices);
182 if (!jni_obj_setPairedDevices)
184 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_obj_setPairedDevices is null");
188 // Convert the set to an object array
189 // object[] array = Set<BluetoothDevice>.toArray();
190 jclass jni_cid_Set = (*env)->FindClass(env, "java/util/Set");
193 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_Set is null");
196 jmethodID jni_mid_toArray = (*env)->GetMethodID(env, jni_cid_Set, "toArray",
197 "()[Ljava/lang/Object;");
199 if (!jni_mid_toArray)
201 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_toArray is null");
205 jobjectArray jni_arrayPairedDevices = (jobjectArray)(
206 (*env)->CallObjectMethod(env, jni_obj_setPairedDevices, jni_mid_toArray));
207 if (!jni_arrayPairedDevices)
209 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_arrayPairedDevices is null");
213 return jni_arrayPairedDevices;
216 jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env)
218 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
219 if (!jni_cid_BTAdapter)
221 OIC_LOG(ERROR, TAG, "[EDR][Native] getBTStateOnInfo: jni_cid_BTAdapter is null");
225 jfieldID jni_fid_stateon = (*env)->GetStaticFieldID(env, jni_cid_BTAdapter, "STATE_ON", "I");
226 if (jni_fid_stateon == 0)
228 OIC_LOG(ERROR, TAG, "[EDR][Native] get_field_state is 0");
231 jint jni_int_val = (*env)->GetStaticIntField(env, jni_cid_BTAdapter, jni_fid_stateon);
233 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] bluetooth state integer value : %d", jni_int_val);
238 jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env)
240 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
241 if (!jni_cid_BTAdapter)
243 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_BTAdapter: jni_cid_BTAdapter is null");
247 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
249 METHODID_OBJECTNONPARAM);
250 if (!jni_mid_getDefaultAdapter)
252 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getDefaultAdapter is null");
256 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
257 jni_mid_getDefaultAdapter);
258 if (!jni_obj_BTAdapter)
260 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_obj_BTAdapter is null");
265 jmethodID jni_mid_isEnable = (*env)->GetMethodID(env, jni_cid_BTAdapter, "isEnabled", "()Z");
266 if (!jni_mid_isEnable)
268 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_isEnable is null");
272 jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
273 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] adapter state is %d", jni_isEnable);
278 jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice)
280 if (!bluetoothDevice)
282 OIC_LOG(ERROR, TAG, "[EDR][Native] bluetoothDevice is null");
285 jclass jni_cid_device_list = (*env)->FindClass(env, "android/bluetooth/BluetoothDevice");
286 if (!jni_cid_device_list)
288 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_device_list is null");
292 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_device_list, "getAddress",
293 METHODID_STRINGNONPARAM);
294 if (!jni_mid_getAddress)
296 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getAddress is null");
300 jstring jni_address = (jstring)(*env)->CallObjectMethod(env, bluetoothDevice,
304 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_address is null");
313 void CAEDRNativeCreateDeviceStateList()
315 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceStateList");
317 // create new object array
318 if (NULL == g_deviceStateList)
320 OIC_LOG(DEBUG, TAG, "Create device list");
322 g_deviceStateList = u_arraylist_create();
326 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address)
330 OIC_LOG(ERROR, TAG, "[EDR][Native] address is null");
333 state_t *newstate = (state_t*) OICCalloc(1, sizeof(state_t));
336 OIC_LOG(ERROR, TAG, "[EDR][Native] newstate is null");
339 OICStrcpy((char*) newstate->address, sizeof(newstate->address), address);
340 newstate->state = state;
342 CAEDRNativeAddDeviceStateToList(newstate);
345 void CAEDRNativeAddDeviceStateToList(state_t *state)
349 OIC_LOG(ERROR, TAG, "[EDR][Native] device is null");
353 if (!g_deviceStateList)
355 OIC_LOG(ERROR, TAG, "[EDR][Native] gdevice_list is null");
359 if (CAEDRNativeIsDeviceInList((const char*) state->address))
361 // delete previous state for update new state
362 CAEDRNativeRemoveDevice((const char*) state->address);
364 u_arraylist_add(g_deviceStateList, state); // update new state
365 OIC_LOG_V(DEBUG, TAG, "Set State Info to List : %d", state->state);
368 bool CAEDRNativeIsDeviceInList(const char* remoteAddress)
373 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
377 jint length = u_arraylist_length(g_deviceStateList);
378 for (index = 0; index < length; index++)
380 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
383 OIC_LOG(ERROR, TAG, "[EDR][Native] state_t object is null");
387 if (!strcmp(remoteAddress, (const char*) state->address))
389 OIC_LOG(DEBUG, TAG, "the device is already set");
398 OIC_LOG(DEBUG, TAG, "there are no the device in list.");
402 void CAEDRNativeRemoveAllDeviceState()
404 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveAllDevices");
406 if (!g_deviceStateList)
408 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
413 jint length = u_arraylist_length(g_deviceStateList);
414 for (index = 0; index < length; index++)
416 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
419 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
425 OICFree(g_deviceStateList);
426 g_deviceStateList = NULL;
430 void CAEDRNativeRemoveDevice(const char *remoteAddress)
432 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList");
434 if (!g_deviceStateList)
436 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
441 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
446 jint length = u_arraylist_length(g_deviceStateList);
447 for (index = 0; index < length; index++)
449 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
452 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
456 if (!strcmp((const char*) state->address, remoteAddress))
458 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove state : %s", remoteAddress);
461 CAEDRReorderingDeviceList(index);
468 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
470 OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice");
474 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
475 return STATE_DISCONNECTED;
478 if (!g_deviceStateList)
480 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
481 return STATE_DISCONNECTED;
485 jint length = u_arraylist_length(g_deviceStateList);
486 for (index = 0; index < length; index++)
488 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
491 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
495 if (!strcmp((const char*) state->address, remoteAddress))
497 OIC_LOG(DEBUG, TAG, "[EDR][Native] check whether it is connected or not");
502 return STATE_DISCONNECTED;
505 void CAEDRReorderingDeviceList(uint32_t index)
507 if (index >= g_deviceStateList->length)
512 if (index < g_deviceStateList->length - 1)
514 memmove(&g_deviceStateList->data[index], &g_deviceStateList->data[index + 1],
515 (g_deviceStateList->length - index - 1) * sizeof(void *));
518 g_deviceStateList->size--;
519 g_deviceStateList->length--;
523 * Device Socket Object List
525 void CAEDRNativeCreateDeviceSocketList()
527 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceSocketList");
529 // create new object array
530 if (NULL == g_deviceObjectList)
532 OIC_LOG(DEBUG, TAG, "Create Device object list");
534 g_deviceObjectList = u_arraylist_create();
538 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket)
540 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeAddDeviceobjToList");
544 OIC_LOG(ERROR, TAG, "[EDR][Native] Device is null");
548 if (!g_deviceObjectList)
550 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
554 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
555 if (!jni_remoteAddress)
557 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_remoteAddress is null");
561 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
563 if (!CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
565 jobject gDeviceSocker = (*env)->NewGlobalRef(env, deviceSocket);
566 u_arraylist_add(g_deviceObjectList, gDeviceSocker);
567 OIC_LOG(DEBUG, TAG, "Set Socket Object to Array");
569 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
572 bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
574 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeIsDeviceObjInList");
578 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
582 jint length = u_arraylist_length(g_deviceStateList);
583 for (index = 0; index < length; index++)
586 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
589 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
593 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
596 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
600 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
603 OIC_LOG(DEBUG, TAG, "[EDR][Native] setAddress is null");
607 if (!strcmp(remoteAddress, setAddress))
609 OIC_LOG(DEBUG, TAG, "the device is already set");
610 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
615 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
620 OIC_LOG(DEBUG, TAG, "there are no the Device obejct in list. we can add");
624 void CAEDRNativeSocketCloseToAll(JNIEnv *env)
626 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeSocketCloseToAll");
628 if (!g_deviceObjectList)
630 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
634 jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
635 if (!jni_cid_BTSocket)
637 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_cid_BTSocket is null");
641 jmethodID jni_mid_close = (*env)->GetMethodID(env, jni_cid_BTSocket, "close", "()V");
644 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_mid_close is null");
649 jint length = u_arraylist_length(g_deviceStateList);
650 for (index = 0; index < length; index++)
652 jobject jni_obj_socket = (jobject) u_arraylist_get(g_deviceObjectList, index);
655 OIC_LOG(ERROR, TAG, "[EDR][Native] socket obj is null");
659 (*env)->CallVoidMethod(env, jni_obj_socket, jni_mid_close);
661 if ((*env)->ExceptionCheck(env))
663 OIC_LOG(ERROR, TAG, "[EDR][Native] close: close is Failed!!!");
664 (*env)->ExceptionDescribe(env);
665 (*env)->ExceptionClear(env);
671 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env)
673 OIC_LOG(DEBUG, TAG, "CANativeRemoveAllDeviceObjsList");
675 if (!g_deviceObjectList)
677 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
682 jint length = u_arraylist_length(g_deviceStateList);
683 for (index = 0; index < length; index++)
685 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
688 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
691 (*env)->DeleteGlobalRef(env, jarrayObj);
694 OICFree(g_deviceObjectList);
695 g_deviceObjectList = NULL;
699 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket)
701 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
703 if (!g_deviceObjectList)
705 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
710 jint length = u_arraylist_length(g_deviceStateList);
711 for (index = 0; index < length; index++)
713 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
716 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
720 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
723 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
727 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
728 if (!jni_remoteAddress)
730 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_remoteAddress is null");
734 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
735 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
737 if (!strcmp(setAddress, remoteAddress))
739 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove object : %s", remoteAddress);
740 (*env)->DeleteGlobalRef(env, jarrayObj);
741 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
742 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
744 CAEDRReorderingDeviceSocketList(index);
747 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
748 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
751 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
755 void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address)
757 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
759 if (!g_deviceObjectList)
761 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
766 jint length = u_arraylist_length(g_deviceStateList);
767 for (index = 0; index < length; index++)
769 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
772 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
776 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
779 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
782 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
783 const char* remoteAddress = (*env)->GetStringUTFChars(env, address, NULL);
785 if (!strcmp(setAddress, remoteAddress))
787 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
788 (*env)->DeleteGlobalRef(env, jarrayObj);
789 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
790 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
792 CAEDRReorderingDeviceSocketList(index);
795 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
796 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
799 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
803 jobject CAEDRNativeGetDeviceSocket(uint32_t idx)
805 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
807 if (!g_deviceObjectList)
809 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
813 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, idx);
816 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is not available");
822 jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddress)
824 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
826 if (!g_deviceObjectList)
828 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
833 jint length = u_arraylist_length(g_deviceStateList);
834 for (index = 0; index < length; index++)
836 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
839 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
843 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
846 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
849 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
851 if (!strcmp(setAddress, remoteAddress))
853 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
854 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
857 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
863 uint32_t CAEDRGetSocketListLength()
865 if (!g_deviceObjectList)
867 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
871 uint32_t length = u_arraylist_length(g_deviceObjectList);
876 void CAEDRReorderingDeviceSocketList(uint32_t index)
878 if (index >= g_deviceObjectList->length)
883 if (index < g_deviceObjectList->length - 1)
885 memmove(&g_deviceObjectList->data[index], &g_deviceObjectList->data[index + 1],
886 (g_deviceObjectList->length - index - 1) * sizeof(void *));
889 g_deviceObjectList->size--;
890 g_deviceObjectList->length--;