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"
30 #include "caadapterutils.h"
32 #define ERROR_CODE (-1)
33 #define TAG PCF("OIC_CA_EDR_UTILS")
35 static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
36 static const char METHODID_STRINGNONPARAM[] = "()Ljava/lang/String;";
37 static const char CLASSPATH_BT_ADPATER[] = "android/bluetooth/BluetoothAdapter";
38 static const char CLASSPATH_BT_DEVICE[] = "android/bluetooth/BluetoothDevice";
39 static const char CLASSPATH_BT_SOCKET[] = "android/bluetooth/BluetoothSocket";
41 static u_arraylist_t *g_deviceStateList = NULL;
42 static u_arraylist_t *g_deviceObjectList = NULL;
44 // get address from bluetooth socket
45 jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSocketObj)
47 if (!bluetoothSocketObj)
49 OIC_LOG(ERROR, TAG, "bluetoothSocketObj is null");
53 jmethodID jni_mid_getRemoteDevice = CAGetJNIMethodID(
54 env, CLASSPATH_BT_SOCKET, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;");
55 if (!jni_mid_getRemoteDevice)
57 OIC_LOG(ERROR, TAG, "jni_mid_getRemoteDevice is null");
61 jobject jni_obj_remoteBTDevice = (*env)->CallObjectMethod(env, bluetoothSocketObj,
62 jni_mid_getRemoteDevice);
63 if (!jni_obj_remoteBTDevice)
65 OIC_LOG(ERROR, TAG, "jni_obj_remoteBTDevice is null");
69 jmethodID j_mid_getAddress = CAGetJNIMethodID(env, CLASSPATH_BT_DEVICE,
71 METHODID_STRINGNONPARAM);
72 if (!j_mid_getAddress)
74 OIC_LOG(ERROR, TAG, "j_mid_getAddress is null");
75 (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
79 jstring j_str_address = (*env)->CallObjectMethod(env, jni_obj_remoteBTDevice,
83 OIC_LOG(ERROR, TAG, "j_str_address is null");
84 (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
88 (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
93 jstring CAEDRNativeGetLocalDeviceAddress(JNIEnv* env)
95 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
96 if (!jni_cid_BTAdapter)
98 OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
102 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
104 METHODID_OBJECTNONPARAM);
105 if (!jni_mid_getDefaultAdapter)
107 OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
108 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
112 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTAdapter, "getAddress",
113 METHODID_STRINGNONPARAM);
114 if (!jni_mid_getAddress)
116 OIC_LOG(ERROR, TAG, "jni_mid_getAddress is null");
117 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
121 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
122 jni_mid_getDefaultAdapter);
123 if (!jni_obj_BTAdapter)
125 OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
126 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
130 jstring jni_str_address = (jstring)(*env)->CallObjectMethod(env, jni_obj_BTAdapter,
132 if (!jni_str_address)
134 OIC_LOG(ERROR, TAG, "jni_str_address is null");
135 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
136 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
140 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
141 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
143 return jni_str_address;
146 jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env)
148 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
149 if (!jni_cid_BTAdapter)
151 OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
155 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
157 METHODID_OBJECTNONPARAM);
158 if (!jni_mid_getDefaultAdapter)
160 OIC_LOG(ERROR, TAG, "default adapter is null");
161 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
165 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
166 jni_mid_getDefaultAdapter);
167 if (!jni_obj_BTAdapter)
169 OIC_LOG(ERROR, TAG, "bluetooth adapter is null");
170 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
174 // Get a list of currently paired devices
175 jmethodID jni_mid_getBondedDevices = (*env)->GetMethodID(env, jni_cid_BTAdapter,
177 "()Ljava/util/Set;");
178 if (!jni_mid_getBondedDevices)
180 OIC_LOG(ERROR, TAG, "jni_mid_getBondedDevicesr is null");
181 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
182 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
186 jobject jni_obj_setPairedDevices = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
187 jni_mid_getBondedDevices);
188 if (!jni_obj_setPairedDevices)
190 OIC_LOG(ERROR, TAG, "ni_obj_setPairedDevices is null");
191 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
192 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
196 // Convert the set to an object array
197 // object[] array = Set<BluetoothDevice>.toArray();
198 jmethodID jni_mid_toArray = CAGetJNIMethodID(env, "java/util/Set",
199 "toArray", "()[Ljava/lang/Object;");
200 if (!jni_mid_toArray)
202 OIC_LOG(ERROR, TAG, "jni_mid_toArray is null");
206 jobjectArray jni_arrayPairedDevices = (jobjectArray)(
207 (*env)->CallObjectMethod(env, jni_obj_setPairedDevices, jni_mid_toArray));
208 if (!jni_arrayPairedDevices)
210 OIC_LOG(ERROR, TAG, "jni_arrayPairedDevices is null");
214 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
215 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
216 (*env)->DeleteLocalRef(env, jni_obj_setPairedDevices);
218 return jni_arrayPairedDevices;
221 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
222 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
223 (*env)->DeleteLocalRef(env, jni_obj_setPairedDevices);
227 jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env)
229 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
230 if (!jni_cid_BTAdapter)
232 OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
236 jfieldID jni_fid_stateon = (*env)->GetStaticFieldID(env, jni_cid_BTAdapter, "STATE_ON", "I");
237 if (jni_fid_stateon == 0)
239 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
241 OIC_LOG(ERROR, TAG, "get_field_state is 0");
244 jint jni_int_val = (*env)->GetStaticIntField(env, jni_cid_BTAdapter, jni_fid_stateon);
246 OIC_LOG_V(DEBUG, TAG, "bluetooth state integer value : %d", jni_int_val);
248 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
253 jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env)
255 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
256 if (!jni_cid_BTAdapter)
258 OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter: jni_cid_BTAdapter is null");
262 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
264 METHODID_OBJECTNONPARAM);
265 if (!jni_mid_getDefaultAdapter)
267 OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
268 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
272 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
273 jni_mid_getDefaultAdapter);
274 if (!jni_obj_BTAdapter)
276 OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
277 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
282 jmethodID jni_mid_isEnable = (*env)->GetMethodID(env, jni_cid_BTAdapter, "isEnabled", "()Z");
283 if (!jni_mid_isEnable)
285 OIC_LOG(ERROR, TAG, "jni_mid_isEnable is null");
286 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
287 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
291 jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
293 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
294 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
299 jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice)
301 if (!bluetoothDevice)
303 OIC_LOG(ERROR, TAG, "bluetoothDevice is null");
307 jmethodID jni_mid_getAddress = CAGetJNIMethodID(env,
310 METHODID_STRINGNONPARAM);
311 if (!jni_mid_getAddress)
313 OIC_LOG(ERROR, TAG, "jni_mid_getAddress is null");
317 jstring jni_address = (jstring)(*env)->CallObjectMethod(env, bluetoothDevice,
321 OIC_LOG(ERROR, TAG, "jni_address is null");
330 void CAEDRNativeCreateDeviceStateList()
332 OIC_LOG(DEBUG, TAG, "CAEDRNativeCreateDeviceStateList");
334 // create new object array
335 if (NULL == g_deviceStateList)
337 OIC_LOG(DEBUG, TAG, "Create device list");
339 g_deviceStateList = u_arraylist_create();
343 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address)
347 OIC_LOG(ERROR, TAG, "address is null");
350 CAConnectedDeviceInfo_t *deviceInfo =
351 (CAConnectedDeviceInfo_t *) OICCalloc(1, sizeof(CAConnectedDeviceInfo_t));
354 OIC_LOG(ERROR, TAG, "deviceInfo is null");
357 OICStrcpy((char*) deviceInfo->address, sizeof(deviceInfo->address), address);
358 deviceInfo->state = state;
360 CAEDRNativeAddDeviceStateToList(deviceInfo);
363 void CAEDRNativeAddDeviceStateToList(CAConnectedDeviceInfo_t *deviceInfo)
367 OIC_LOG(ERROR, TAG, "device is null");
371 if (!g_deviceStateList)
373 OIC_LOG(ERROR, TAG, "gdevice_list is null");
377 if (CAEDRNativeIsDeviceInList((const char*) deviceInfo->address))
379 // delete previous state for update new state
380 CAEDRNativeRemoveDevice((const char*) deviceInfo->address);
382 u_arraylist_add(g_deviceStateList, deviceInfo); // update new state
383 OIC_LOG_V(DEBUG, TAG, "add new device state[%d] to list", deviceInfo->state);
386 bool CAEDRNativeIsDeviceInList(const char* remoteAddress)
390 OIC_LOG(ERROR, TAG, "remoteAddress is null");
394 jint length = u_arraylist_length(g_deviceStateList);
395 for (jint index = 0; index < length; index++)
397 CAConnectedDeviceInfo_t* deviceInfo =
398 (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index);
401 OIC_LOG(ERROR, TAG, "deviceInfo object is null");
405 if (!strcmp(remoteAddress, (const char*) deviceInfo->address))
407 OIC_LOG(DEBUG, TAG, "the device is already set");
412 OIC_LOG(DEBUG, TAG, "there are no the device in list.");
416 void CAEDRNativeRemoveAllDeviceState()
418 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveAllDevices");
420 if (!g_deviceStateList)
422 OIC_LOG(ERROR, TAG, "gdeviceStateList is null");
427 jint length = u_arraylist_length(g_deviceStateList);
428 for (index = 0; index < length; index++)
430 CAConnectedDeviceInfo_t* deviceInfo =
431 (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index);
434 OIC_LOG(DEBUG, TAG, "jarrayObj is null");
440 OICFree(g_deviceStateList);
441 g_deviceStateList = NULL;
445 void CAEDRNativeRemoveDevice(const char *remoteAddress)
447 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList");
449 if (!g_deviceStateList)
451 OIC_LOG(ERROR, TAG, "gdeviceStateList is null");
456 OIC_LOG(ERROR, TAG, "remoteAddress is null");
460 jint length = u_arraylist_length(g_deviceStateList);
461 for (jint index = 0; index < length; index++)
463 CAConnectedDeviceInfo_t* deviceInfo =
464 (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index);
467 OIC_LOG(DEBUG, TAG, "deviceInfo object is null");
471 if (!strcmp((const char*) deviceInfo->address, remoteAddress))
473 OIC_LOG_V(DEBUG, TAG, "remove [%s] info from list", remoteAddress);
476 u_arraylist_remove(g_deviceStateList, index);
483 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
485 OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice");
489 OIC_LOG(ERROR, TAG, "remoteAddress is null");
490 return STATE_DISCONNECTED;
493 if (!g_deviceStateList)
495 OIC_LOG(ERROR, TAG, "gdeviceStateList is null");
496 return STATE_DISCONNECTED;
499 jint length = u_arraylist_length(g_deviceStateList);
500 for (jint index = 0; index < length; index++)
502 CAConnectedDeviceInfo_t* deviceInfo =
503 (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index);
506 OIC_LOG(DEBUG, TAG, "deviceInfo object is null");
510 if (!strcmp((const char*) deviceInfo->address, remoteAddress))
512 return deviceInfo->state;
515 return STATE_DISCONNECTED;
519 * Device Socket Object List
521 void CAEDRNativeCreateDeviceSocketList()
523 OIC_LOG(DEBUG, TAG, "CAEDRNativeCreateDeviceSocketList");
525 // create new object array
526 if (NULL == g_deviceObjectList)
528 OIC_LOG(DEBUG, TAG, "Create Device object list");
530 g_deviceObjectList = u_arraylist_create();
534 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket)
536 OIC_LOG(DEBUG, TAG, "CANativeAddDeviceobjToList");
540 OIC_LOG(ERROR, TAG, "Device is null");
544 if (!g_deviceObjectList)
546 OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
550 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
551 if (!jni_remoteAddress)
553 OIC_LOG(ERROR, TAG, "jni_remoteAddress is null");
557 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
559 if (!CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
561 jobject gDeviceSocker = (*env)->NewGlobalRef(env, deviceSocket);
562 u_arraylist_add(g_deviceObjectList, gDeviceSocker);
563 OIC_LOG(DEBUG, TAG, "add new device socket object to list");
565 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
566 (*env)->DeleteLocalRef(env, jni_remoteAddress);
569 bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
571 OIC_LOG(DEBUG, TAG, "CANativeIsDeviceObjInList");
575 OIC_LOG(ERROR, TAG, "remoteAddress is null");
579 jint length = u_arraylist_length(g_deviceStateList);
580 for (jint index = 0; index < length; index++)
583 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
586 OIC_LOG(DEBUG, TAG, "jarrayObj is null");
590 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
593 OIC_LOG(DEBUG, TAG, "jni_setAddress is null");
597 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
600 OIC_LOG(DEBUG, TAG, "setAddress is null");
604 if (!strcmp(remoteAddress, setAddress))
606 OIC_LOG(DEBUG, TAG, "the device is already set");
607 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
612 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
617 OIC_LOG(DEBUG, TAG, "there are no the Device obejct in list");
621 void CAEDRNativeSocketCloseToAll(JNIEnv *env)
623 OIC_LOG(DEBUG, TAG, "CAEDRNativeSocketCloseToAll");
625 if (!g_deviceObjectList)
627 OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
631 jmethodID jni_mid_close = CAGetJNIMethodID(env, CLASSPATH_BT_SOCKET,
635 OIC_LOG(ERROR, TAG, "jni_mid_close is null");
639 jint length = u_arraylist_length(g_deviceStateList);
640 for (jint index = 0; index < length; index++)
642 jobject jni_obj_socket = (jobject) u_arraylist_get(g_deviceObjectList, index);
645 OIC_LOG(ERROR, TAG, "socket obj is null");
649 (*env)->CallVoidMethod(env, jni_obj_socket, jni_mid_close);
651 if ((*env)->ExceptionCheck(env))
653 OIC_LOG(ERROR, TAG, "close is Failed!!!");
654 (*env)->ExceptionDescribe(env);
655 (*env)->ExceptionClear(env);
661 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env)
663 OIC_LOG(DEBUG, TAG, "CANativeRemoveAllDeviceObjsList");
665 if (!g_deviceObjectList)
667 OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
671 jint length = u_arraylist_length(g_deviceStateList);
672 for (jint index = 0; index < length; index++)
674 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
677 OIC_LOG(ERROR, TAG, "jarrayObj is null");
680 (*env)->DeleteGlobalRef(env, jarrayObj);
683 OICFree(g_deviceObjectList);
684 g_deviceObjectList = NULL;
688 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket)
690 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
692 if (!g_deviceObjectList)
694 OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
698 jint length = u_arraylist_length(g_deviceStateList);
699 for (jint index = 0; index < length; index++)
701 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
704 OIC_LOG(DEBUG, TAG, "jarrayObj is null");
708 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
711 OIC_LOG(DEBUG, TAG, "jni_setAddress is null");
715 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
716 if (!jni_remoteAddress)
718 OIC_LOG(DEBUG, TAG, "jni_remoteAddress is null");
722 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
723 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
725 if (!strcmp(setAddress, remoteAddress))
727 OIC_LOG_V(DEBUG, TAG, "remove object : %s", remoteAddress);
728 (*env)->DeleteGlobalRef(env, jarrayObj);
729 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
730 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
732 u_arraylist_remove(g_deviceObjectList, index);
735 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
736 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
739 OIC_LOG(DEBUG, TAG, "there are no target object");
743 void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address)
745 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
747 if (!g_deviceObjectList)
749 OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
753 jint length = u_arraylist_length(g_deviceStateList);
754 for (jint index = 0; index < length; index++)
756 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
759 OIC_LOG(DEBUG, TAG, "jarrayObj is null");
763 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
766 OIC_LOG(ERROR, TAG, "jni_setAddress is null");
769 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
770 const char* remoteAddress = (*env)->GetStringUTFChars(env, address, NULL);
772 if (!strcmp(setAddress, remoteAddress))
774 OIC_LOG_V(ERROR, TAG, "remove object : %s", remoteAddress);
775 (*env)->DeleteGlobalRef(env, jarrayObj);
776 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
777 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
779 u_arraylist_remove(g_deviceObjectList, index);
782 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
783 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
786 OIC_LOG(DEBUG, TAG, "there are no target object");
790 jobject CAEDRNativeGetDeviceSocket(uint32_t idx)
792 if (!g_deviceObjectList)
794 OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
798 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, idx);
801 OIC_LOG(ERROR, TAG, "jarrayObj is not available");
807 jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddress)
809 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
811 if (!g_deviceObjectList)
813 OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
817 jint length = u_arraylist_length(g_deviceStateList);
818 for (jint index = 0; index < length; index++)
820 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
823 OIC_LOG(ERROR, TAG, "jarrayObj is null");
827 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
830 OIC_LOG(ERROR, TAG, "jni_setAddress is null");
833 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
835 if (!strcmp(setAddress, remoteAddress))
837 OIC_LOG_V(ERROR, TAG, "remove object : %s", remoteAddress);
838 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
839 (*env)->DeleteLocalRef(env, jni_setAddress);
842 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
843 (*env)->DeleteLocalRef(env, jni_setAddress);
849 uint32_t CAEDRGetSocketListLength()
851 if (!g_deviceObjectList)
853 OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
857 return u_arraylist_length(g_deviceObjectList);
860 CAConnectedDeviceInfo_t *CAEDRGetDeviceInfoFromAddress(const char *remoteAddress)
862 OIC_LOG(DEBUG, TAG, "CAEDRGetDeviceInfoFromAddress");
864 if (!g_deviceStateList)
866 OIC_LOG(ERROR, TAG, "gdeviceStateList is null");
871 OIC_LOG(ERROR, TAG, "remoteAddress is null");
875 jint length = u_arraylist_length(g_deviceStateList);
876 for (jint index = 0; index < length; index++)
878 CAConnectedDeviceInfo_t* deviceInfo =
879 (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index);
882 OIC_LOG(DEBUG, TAG, "deviceInfo object is null");
886 if (!strcmp((const char*) deviceInfo->address, remoteAddress))