2 * //******************************************************************
4 * // Copyright 2015 Intel Corporation.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "JniOcStack.h"
24 #include "OCPlatform.h"
25 #include "OCRepresentation.h"
29 * Macro to verify the validity of input argument.
31 * @param arg log level
33 #define VERIFY_VARIABLE_NULL(arg) \
34 if (nullptr == (arg)) \
36 LOGE("invalid input"); \
40 JavaVM* g_jvm = nullptr;
42 jclass g_cls_Integer = nullptr;
43 jclass g_cls_int1DArray = nullptr;
44 jclass g_cls_int2DArray = nullptr;
45 jclass g_cls_Double = nullptr;
46 jclass g_cls_double1DArray = nullptr;
47 jclass g_cls_double2DArray = nullptr;
48 jclass g_cls_Boolean = nullptr;
49 jclass g_cls_boolean1DArray = nullptr;
50 jclass g_cls_boolean2DArray = nullptr;
51 jclass g_cls_String = nullptr;
52 jclass g_cls_String1DArray = nullptr;
53 jclass g_cls_String2DArray = nullptr;
54 jclass g_cls_LinkedList = nullptr;
55 jclass g_cls_Map = nullptr;
56 jclass g_cls_MapEntry = nullptr;
57 jclass g_cls_Set = nullptr;
58 jclass g_cls_Iterator = nullptr;
59 jclass g_cls_HashMap = nullptr;
60 jclass g_cls_OcException = nullptr;
61 jclass g_cls_OcResource = nullptr;
62 jclass g_cls_OcRepresentation = nullptr;
63 jclass g_cls_OcRepresentation1DArray = nullptr;
64 jclass g_cls_OcRepresentation2DArray = nullptr;
65 jclass g_cls_OcResourceRequest = nullptr;
66 jclass g_cls_OcResourceResponse = nullptr;
67 jclass g_cls_OcResourceHandle = nullptr;
68 jclass g_cls_OcPresenceHandle = nullptr;
69 jclass g_cls_OcRequestHandle = nullptr;
70 jclass g_cls_OcPresenceStatus = nullptr;
71 jclass g_cls_OcHeaderOption = nullptr;
72 jclass g_cls_ObservationInfo = nullptr;
73 jclass g_cls_OcResourceIdentifier = nullptr;
74 jclass g_cls_OcProvisionResult = nullptr;
75 jclass g_cls_OcSecureResource = nullptr;
76 jclass g_cls_OcOicSecAcl = nullptr;
77 jclass g_cls_OcOicSecAcl_ace = nullptr;
78 jclass g_cls_OcOicSecAcl_resr = nullptr;
79 jclass g_cls_OcOicSecAcl_validity = nullptr;
80 jclass g_cls_OcOicSecPdAcl = nullptr;
81 jclass g_cls_OcDirectPairDevice = nullptr;
83 jclass g_cls_OcAccountManager = nullptr;
86 jmethodID g_mid_Integer_ctor = nullptr;
87 jmethodID g_mid_Double_ctor = nullptr;
88 jmethodID g_mid_Boolean_ctor = nullptr;
89 jmethodID g_mid_LinkedList_ctor = nullptr;
90 jmethodID g_mid_LinkedList_add_object = nullptr;
91 jmethodID g_mid_Map_entrySet = nullptr;
92 jmethodID g_mid_MapEntry_getKey = nullptr;
93 jmethodID g_mid_MapEntry_getValue = nullptr;
94 jmethodID g_mid_Set_iterator = nullptr;
95 jmethodID g_mid_Iterator_hasNext = nullptr;
96 jmethodID g_mid_Iterator_next = nullptr;
97 jmethodID g_mid_HashMap_ctor = nullptr;
98 jmethodID g_mid_HashMap_put = nullptr;
99 jmethodID g_mid_OcException_ctor = nullptr;
100 jmethodID g_mid_OcException_setNativeExceptionLocation = nullptr;
101 jmethodID g_mid_OcResource_ctor = nullptr;
102 jmethodID g_mid_OcRepresentation_N_ctor = nullptr;
103 jmethodID g_mid_OcRepresentation_N_ctor_bool = nullptr;
104 jmethodID g_mid_OcResourceRequest_N_ctor = nullptr;
105 jmethodID g_mid_OcResourceResponse_N_ctor = nullptr;
106 jmethodID g_mid_OcResourceHandle_N_ctor = nullptr;
107 jmethodID g_mid_OcPresenceHandle_N_ctor = nullptr;
109 jmethodID g_mid_OcRequestHandle_N_ctor = nullptr;
110 jmethodID g_mid_OcHeaderOption_ctor = nullptr;
111 jmethodID g_mid_OcHeaderOption_get_id = nullptr;
112 jmethodID g_mid_OcHeaderOption_get_data = nullptr;
113 jmethodID g_mid_ObservationInfo_N_ctor = nullptr;
114 jmethodID g_mid_OcPresenceStatus_get = nullptr;
115 jmethodID g_mid_OcResourceIdentifier_N_ctor = nullptr;
116 jmethodID g_mid_OcProvisionResult_ctor = nullptr;
117 jmethodID g_mid_OcSecureResource_ctor = nullptr;
118 jmethodID g_mid_OcDirectPairDevice_ctor = nullptr;
119 jmethodID g_mid_OcDirectPairDevice_dev_ctor = nullptr;
121 jmethodID g_mid_OcAccountManager_ctor = nullptr;
124 jmethodID g_mid_OcOicSecPdAcl_get_resources_cnt = nullptr;
125 jmethodID g_mid_OcOicSecPdAcl_get_resources = nullptr;
126 jmethodID g_mid_OcOicSecPdAcl_get_permission = nullptr;
127 jmethodID g_mid_OcOicSecPdAcl_get_periods_cnt = nullptr;
128 jmethodID g_mid_OcOicSecPdAcl_get_periods = nullptr;
129 jmethodID g_mid_OcOicSecPdAcl_get_recurrences = nullptr;
131 jmethodID g_mid_OcOicSecAcl_get_aces = nullptr;
132 jmethodID g_mid_OcOicSecAcl_ace_get_subjectID = nullptr;
133 jmethodID g_mid_OcOicSecAcl_ace_get_permissions = nullptr;
134 jmethodID g_mid_OcOicSecAcl_ace_get_resources = nullptr;
135 jmethodID g_mid_OcOicSecAcl_ace_get_validities = nullptr;
136 jmethodID g_mid_OcOicSecAcl_resr_get_href = nullptr;
137 jmethodID g_mid_OcOicSecAcl_resr_get_rel = nullptr;
138 jmethodID g_mid_OcOicSecAcl_resr_get_types = nullptr;
139 jmethodID g_mid_OcOicSecAcl_resr_get_typeLen = nullptr;
140 jmethodID g_mid_OcOicSecAcl_resr_get_interfaces = nullptr;
141 jmethodID g_mid_OcOicSecAcl_validity_get_getPeriod = nullptr;
142 jmethodID g_mid_OcOicSecAcl_validity_get_recurrences = nullptr;
143 jmethodID g_mid_OcOicSecAcl_validity_get_recurrenceLen = nullptr;
144 jmethodID g_mid_OcOicSecAcl_resr_get_interfaceLen = nullptr;
145 jmethodID g_mid_OcOicSecAcl_get_rownerID = nullptr;
147 jobject getOcException(JNIEnv* env, const char* file, const char* functionName,
148 const int line, const int code, const char* message)
150 std::string codeStr = JniUtils::stackResultToStr(code);
153 codeStr = JniUtils::stackResultToStr(JNI_INVALID_VALUE);
155 jobject ex = env->NewObject(g_cls_OcException,
156 g_mid_OcException_ctor,
157 env->NewStringUTF(codeStr.c_str()),
158 env->NewStringUTF(message));
163 env->CallVoidMethod(ex,
164 g_mid_OcException_setNativeExceptionLocation,
165 env->NewStringUTF(file),
166 env->NewStringUTF(functionName),
168 if (env->ExceptionCheck())
175 void throwOcException(JNIEnv* env, jobject ex)
177 env->Throw((jthrowable)ex);
181 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
184 JNIEnv* env = nullptr;
187 if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
189 LOGE("Failed to get the environment using GetEnv()");
192 VERIFY_VARIABLE_NULL(env);
194 jclass clazz = nullptr;
197 clazz = env->FindClass("java/lang/Integer");
198 VERIFY_VARIABLE_NULL(clazz);
200 g_cls_Integer = (jclass)env->NewGlobalRef(clazz);
201 env->DeleteLocalRef(clazz);
203 g_mid_Integer_ctor = env->GetMethodID(g_cls_Integer, "<init>", "(I)V");
204 VERIFY_VARIABLE_NULL(g_mid_Integer_ctor);
206 clazz = env->FindClass("[I");
207 VERIFY_VARIABLE_NULL(clazz);
208 g_cls_int1DArray = (jclass)env->NewGlobalRef(clazz);
209 env->DeleteLocalRef(clazz);
211 clazz = env->FindClass("[[I");
212 VERIFY_VARIABLE_NULL(clazz);
213 g_cls_int2DArray = (jclass)env->NewGlobalRef(clazz);
214 env->DeleteLocalRef(clazz);
217 clazz = env->FindClass("java/lang/Double");
218 VERIFY_VARIABLE_NULL(clazz);
219 g_cls_Double = (jclass)env->NewGlobalRef(clazz);
220 env->DeleteLocalRef(clazz);
222 g_mid_Double_ctor = env->GetMethodID(g_cls_Double, "<init>", "(D)V");
223 VERIFY_VARIABLE_NULL(g_mid_Double_ctor);
225 clazz = env->FindClass("[D");
226 VERIFY_VARIABLE_NULL(clazz);
227 g_cls_double1DArray = (jclass)env->NewGlobalRef(clazz);
228 env->DeleteLocalRef(clazz);
230 clazz = env->FindClass("[[D");
231 VERIFY_VARIABLE_NULL(clazz);
232 g_cls_double2DArray = (jclass)env->NewGlobalRef(clazz);
233 env->DeleteLocalRef(clazz);
236 clazz = env->FindClass("java/lang/Boolean");
237 VERIFY_VARIABLE_NULL(clazz);
238 g_cls_Boolean = (jclass)env->NewGlobalRef(clazz);
239 env->DeleteLocalRef(clazz);
241 g_mid_Boolean_ctor = env->GetMethodID(g_cls_Boolean, "<init>", "(Z)V");
242 VERIFY_VARIABLE_NULL(g_mid_Boolean_ctor);
244 clazz = env->FindClass("[Z");
245 VERIFY_VARIABLE_NULL(clazz);
246 g_cls_boolean1DArray = (jclass)env->NewGlobalRef(clazz);
247 env->DeleteLocalRef(clazz);
249 clazz = env->FindClass("[[Z");
250 VERIFY_VARIABLE_NULL(clazz);
251 g_cls_boolean2DArray = (jclass)env->NewGlobalRef(clazz);
252 env->DeleteLocalRef(clazz);
255 clazz = env->FindClass("java/lang/String");
256 VERIFY_VARIABLE_NULL(clazz);
257 g_cls_String = (jclass)env->NewGlobalRef(clazz);
258 env->DeleteLocalRef(clazz);
260 clazz = env->FindClass("[Ljava/lang/String;");
261 VERIFY_VARIABLE_NULL(clazz);
262 g_cls_String1DArray = (jclass)env->NewGlobalRef(clazz);
263 env->DeleteLocalRef(clazz);
265 clazz = env->FindClass("[[Ljava/lang/String;");
266 VERIFY_VARIABLE_NULL(clazz);
267 g_cls_String2DArray = (jclass)env->NewGlobalRef(clazz);
268 env->DeleteLocalRef(clazz);
271 clazz = env->FindClass("java/util/LinkedList");
272 VERIFY_VARIABLE_NULL(clazz);
273 g_cls_LinkedList = (jclass)env->NewGlobalRef(clazz);
274 env->DeleteLocalRef(clazz);
276 g_mid_LinkedList_ctor = env->GetMethodID(g_cls_LinkedList, "<init>", "()V");
277 VERIFY_VARIABLE_NULL(g_mid_LinkedList_ctor);
279 g_mid_LinkedList_add_object = env->GetMethodID(g_cls_LinkedList, "add", "(Ljava/lang/Object;)Z");
280 VERIFY_VARIABLE_NULL(g_mid_LinkedList_add_object);
283 clazz = env->FindClass("java/util/Map");
284 VERIFY_VARIABLE_NULL(clazz);
285 g_cls_Map = (jclass)env->NewGlobalRef(clazz);
286 env->DeleteLocalRef(clazz);
288 g_mid_Map_entrySet = env->GetMethodID(g_cls_Map, "entrySet", "()Ljava/util/Set;");
289 VERIFY_VARIABLE_NULL(g_mid_Map_entrySet);
292 clazz = env->FindClass("java/util/Map$Entry");
293 VERIFY_VARIABLE_NULL(clazz);
294 g_cls_MapEntry = (jclass)env->NewGlobalRef(clazz);
295 env->DeleteLocalRef(clazz);
297 g_mid_MapEntry_getKey = env->GetMethodID(g_cls_MapEntry, "getKey", "()Ljava/lang/Object;");
298 VERIFY_VARIABLE_NULL(g_mid_MapEntry_getKey);
299 g_mid_MapEntry_getValue = env->GetMethodID(g_cls_MapEntry, "getValue", "()Ljava/lang/Object;");
300 VERIFY_VARIABLE_NULL(g_mid_MapEntry_getValue);
303 clazz = env->FindClass("java/util/Set");
304 VERIFY_VARIABLE_NULL(clazz);
305 g_cls_Set = (jclass)env->NewGlobalRef(clazz);
306 env->DeleteLocalRef(clazz);
308 g_mid_Set_iterator = env->GetMethodID(g_cls_Set, "iterator", "()Ljava/util/Iterator;");
309 VERIFY_VARIABLE_NULL(g_mid_Set_iterator);
312 clazz = env->FindClass("java/util/Iterator");
313 VERIFY_VARIABLE_NULL(clazz);
314 g_cls_Iterator = (jclass)env->NewGlobalRef(clazz);
315 env->DeleteLocalRef(clazz);
317 g_mid_Iterator_hasNext = env->GetMethodID(g_cls_Iterator, "hasNext", "()Z");
318 VERIFY_VARIABLE_NULL(g_mid_Iterator_hasNext);
320 g_mid_Iterator_next = env->GetMethodID(g_cls_Iterator, "next", "()Ljava/lang/Object;");
321 VERIFY_VARIABLE_NULL(g_mid_Iterator_next);
324 clazz = env->FindClass("java/util/HashMap");
325 VERIFY_VARIABLE_NULL(clazz);
326 g_cls_HashMap = (jclass)env->NewGlobalRef(clazz);
327 env->DeleteLocalRef(clazz);
329 g_mid_HashMap_ctor = env->GetMethodID(g_cls_HashMap, "<init>", "()V");
330 VERIFY_VARIABLE_NULL(g_mid_HashMap_ctor);
332 g_mid_HashMap_put = env->GetMethodID(g_cls_HashMap, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
333 VERIFY_VARIABLE_NULL(g_mid_HashMap_put);
336 clazz = env->FindClass("org/iotivity/base/OcException");
337 VERIFY_VARIABLE_NULL(clazz);
338 g_cls_OcException = (jclass)env->NewGlobalRef(clazz);
339 env->DeleteLocalRef(clazz);
341 g_mid_OcException_ctor = env->GetMethodID(g_cls_OcException, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
342 VERIFY_VARIABLE_NULL(g_mid_OcException_ctor);
344 g_mid_OcException_setNativeExceptionLocation = env->GetMethodID(g_cls_OcException, "setNativeExceptionLocation",
345 "(Ljava/lang/String;""Ljava/lang/String;""I)V");
346 VERIFY_VARIABLE_NULL(g_mid_OcException_setNativeExceptionLocation);
349 clazz = env->FindClass("org/iotivity/base/OcResource");
350 VERIFY_VARIABLE_NULL(clazz);
351 g_cls_OcResource = (jclass)env->NewGlobalRef(clazz);
352 env->DeleteLocalRef(clazz);
354 g_mid_OcResource_ctor = env->GetMethodID(g_cls_OcResource, "<init>", "(J)V");
355 VERIFY_VARIABLE_NULL(g_mid_OcResource_ctor);
358 clazz = env->FindClass("org/iotivity/base/OcRepresentation");
359 VERIFY_VARIABLE_NULL(clazz);
360 g_cls_OcRepresentation = (jclass)env->NewGlobalRef(clazz);
361 env->DeleteLocalRef(clazz);
363 g_mid_OcRepresentation_N_ctor = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(J)V");
364 VERIFY_VARIABLE_NULL(g_mid_OcRepresentation_N_ctor);
366 g_mid_OcRepresentation_N_ctor_bool = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(JZ)V");
367 VERIFY_VARIABLE_NULL(g_mid_OcRepresentation_N_ctor_bool);
369 clazz = env->FindClass("[Lorg/iotivity/base/OcRepresentation;");
370 VERIFY_VARIABLE_NULL(clazz);
371 g_cls_OcRepresentation1DArray = (jclass)env->NewGlobalRef(clazz);
372 env->DeleteLocalRef(clazz);
374 clazz = env->FindClass("[[Lorg/iotivity/base/OcRepresentation;");
375 VERIFY_VARIABLE_NULL(clazz);
376 g_cls_OcRepresentation2DArray = (jclass)env->NewGlobalRef(clazz);
377 env->DeleteLocalRef(clazz);
380 clazz = env->FindClass("org/iotivity/base/OcHeaderOption");
381 VERIFY_VARIABLE_NULL(clazz);
382 g_cls_OcHeaderOption = (jclass)env->NewGlobalRef(clazz);
383 env->DeleteLocalRef(clazz);
384 g_mid_OcHeaderOption_ctor = env->GetMethodID(g_cls_OcHeaderOption, "<init>", "(ILjava/lang/String;)V");
385 VERIFY_VARIABLE_NULL(g_mid_OcHeaderOption_ctor);
387 g_mid_OcHeaderOption_get_id = env->GetMethodID(g_cls_OcHeaderOption, "getOptionId", "()I");
388 VERIFY_VARIABLE_NULL(g_mid_OcHeaderOption_get_id);
390 g_mid_OcHeaderOption_get_data = env->GetMethodID(g_cls_OcHeaderOption, "getOptionData", "()Ljava/lang/String;");
391 VERIFY_VARIABLE_NULL(g_mid_OcHeaderOption_get_data);
394 clazz = env->FindClass("org/iotivity/base/OcResourceRequest");
395 VERIFY_VARIABLE_NULL(clazz);
396 g_cls_OcResourceRequest = (jclass)env->NewGlobalRef(clazz);
397 env->DeleteLocalRef(clazz);
399 g_mid_OcResourceRequest_N_ctor = env->GetMethodID(g_cls_OcResourceRequest, "<init>", "(J)V");
400 VERIFY_VARIABLE_NULL(g_mid_OcResourceRequest_N_ctor);
403 clazz = env->FindClass("org/iotivity/base/OcResourceResponse");
404 VERIFY_VARIABLE_NULL(clazz);
405 g_cls_OcResourceResponse = (jclass)env->NewGlobalRef(clazz);
406 env->DeleteLocalRef(clazz);
408 g_mid_OcResourceResponse_N_ctor = env->GetMethodID(g_cls_OcResourceResponse, "<init>", "(J)V");
409 VERIFY_VARIABLE_NULL(g_mid_OcResourceResponse_N_ctor);
412 clazz = env->FindClass("org/iotivity/base/OcResourceHandle");
413 VERIFY_VARIABLE_NULL(clazz);
414 g_cls_OcResourceHandle = (jclass)env->NewGlobalRef(clazz);
415 env->DeleteLocalRef(clazz);
416 g_mid_OcResourceHandle_N_ctor = env->GetMethodID(g_cls_OcResourceHandle, "<init>", "(J)V");
417 VERIFY_VARIABLE_NULL(g_mid_OcResourceHandle_N_ctor);
420 clazz = env->FindClass("org/iotivity/base/OcPresenceHandle");
421 VERIFY_VARIABLE_NULL(clazz);
422 g_cls_OcPresenceHandle = (jclass)env->NewGlobalRef(clazz);
423 env->DeleteLocalRef(clazz);
424 g_mid_OcPresenceHandle_N_ctor = env->GetMethodID(g_cls_OcPresenceHandle, "<init>", "(J)V");
425 VERIFY_VARIABLE_NULL(g_mid_OcPresenceHandle_N_ctor);
428 clazz = env->FindClass("org/iotivity/base/OcRequestHandle");
429 VERIFY_VARIABLE_NULL(clazz);
430 g_cls_OcRequestHandle = (jclass)env->NewGlobalRef(clazz);
431 env->DeleteLocalRef(clazz);
432 g_mid_OcRequestHandle_N_ctor = env->GetMethodID(g_cls_OcRequestHandle, "<init>", "(J)V");
433 VERIFY_VARIABLE_NULL(g_mid_OcRequestHandle_N_ctor);
436 clazz = env->FindClass("org/iotivity/base/OcPresenceStatus");
437 VERIFY_VARIABLE_NULL(clazz);
438 g_cls_OcPresenceStatus = (jclass)env->NewGlobalRef(clazz);
439 env->DeleteLocalRef(clazz);
440 g_mid_OcPresenceStatus_get = env->GetStaticMethodID(g_cls_OcPresenceStatus, "get",
441 "(Ljava/lang/String;)Lorg/iotivity/base/OcPresenceStatus;");
442 VERIFY_VARIABLE_NULL(g_mid_OcPresenceStatus_get);
445 clazz = env->FindClass("org/iotivity/base/ObservationInfo");
446 VERIFY_VARIABLE_NULL(clazz);
447 g_cls_ObservationInfo = (jclass)env->NewGlobalRef(clazz);
448 env->DeleteLocalRef(clazz);
449 g_mid_ObservationInfo_N_ctor = env->GetMethodID(g_cls_ObservationInfo, "<init>", "(IB)V");
450 VERIFY_VARIABLE_NULL(g_mid_ObservationInfo_N_ctor);
452 clazz = env->FindClass("org/iotivity/base/OcResourceIdentifier");
453 VERIFY_VARIABLE_NULL(clazz);
454 g_cls_OcResourceIdentifier = (jclass)env->NewGlobalRef(clazz);
455 env->DeleteLocalRef(clazz);
456 g_mid_OcResourceIdentifier_N_ctor = env->GetMethodID(g_cls_OcResourceIdentifier, "<init>", "(J)V");
457 VERIFY_VARIABLE_NULL(g_mid_OcResourceIdentifier_N_ctor);
460 clazz = env->FindClass("org/iotivity/base/OcSecureResource");
461 VERIFY_VARIABLE_NULL(clazz);
462 g_cls_OcSecureResource = (jclass)env->NewGlobalRef(clazz);
463 env->DeleteLocalRef(clazz);
464 g_mid_OcSecureResource_ctor = env->GetMethodID(g_cls_OcSecureResource, "<init>", "(J)V");
465 VERIFY_VARIABLE_NULL(g_mid_OcSecureResource_ctor);
468 clazz = env->FindClass("org/iotivity/base/ProvisionResult");
469 VERIFY_VARIABLE_NULL(clazz);
470 g_cls_OcProvisionResult = (jclass)env->NewGlobalRef(clazz);
471 env->DeleteLocalRef(clazz);
472 g_mid_OcProvisionResult_ctor = env->GetMethodID(g_cls_OcProvisionResult, "<init>", "(Ljava/lang/String;I)V");
473 VERIFY_VARIABLE_NULL(g_mid_OcProvisionResult_ctor);
476 clazz = env->FindClass("org/iotivity/base/OcDirectPairDevice");
477 VERIFY_VARIABLE_NULL(clazz);
478 g_cls_OcDirectPairDevice = (jclass)env->NewGlobalRef(clazz);
479 g_mid_OcDirectPairDevice_ctor = env->GetMethodID(g_cls_OcDirectPairDevice, "<init>", "(J)V");
480 VERIFY_VARIABLE_NULL(g_mid_OcDirectPairDevice_ctor);
482 g_mid_OcDirectPairDevice_dev_ctor = env->GetMethodID(g_cls_OcDirectPairDevice, "<init>", "(Ljava/lang/String;)V");
483 VERIFY_VARIABLE_NULL(g_mid_OcDirectPairDevice_dev_ctor);
484 env->DeleteLocalRef(clazz);
488 clazz = env->FindClass("org/iotivity/base/OcAccountManager");
489 VERIFY_VARIABLE_NULL(clazz);
490 g_cls_OcAccountManager = (jclass)env->NewGlobalRef(clazz);
491 env->DeleteLocalRef(clazz);
493 g_mid_OcAccountManager_ctor = env->GetMethodID(g_cls_OcAccountManager, "<init>", "(J)V");
494 VERIFY_VARIABLE_NULL(g_mid_OcAccountManager_ctor);
498 clazz = env->FindClass("org/iotivity/base/OicSecAcl");
499 VERIFY_VARIABLE_NULL(clazz);
500 g_cls_OcOicSecAcl = (jclass)env->NewGlobalRef(clazz);
501 env->DeleteLocalRef(clazz);
503 g_mid_OcOicSecAcl_get_rownerID = env->GetMethodID(g_cls_OcOicSecAcl, "getRownerID", "()Ljava/lang/String;");
504 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_rownerID);
506 g_mid_OcOicSecAcl_get_aces = env->GetMethodID(g_cls_OcOicSecAcl, "getOicSecAces", "()[Lorg/iotivity/base/OicSecAce;");
507 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_aces);
510 clazz = env->FindClass("org/iotivity/base/OicSecAce");
511 VERIFY_VARIABLE_NULL(clazz);
512 g_cls_OcOicSecAcl_ace = (jclass)env->NewGlobalRef(clazz);
513 env->DeleteLocalRef(clazz);
515 g_mid_OcOicSecAcl_ace_get_subjectID = env->GetMethodID(g_cls_OcOicSecAcl_ace, "getSubjectID","()Ljava/lang/String;");
516 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_ace_get_subjectID);
518 g_mid_OcOicSecAcl_ace_get_permissions = env->GetMethodID(g_cls_OcOicSecAcl_ace, "getPermission","()I");
519 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_ace_get_permissions);
521 g_mid_OcOicSecAcl_ace_get_resources = env->GetMethodID(g_cls_OcOicSecAcl_ace, "getResources","()[Lorg/iotivity/base/OicSecResr;");
522 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_ace_get_resources);
524 g_mid_OcOicSecAcl_ace_get_validities = env->GetMethodID(g_cls_OcOicSecAcl_ace, "getValidities","()[Lorg/iotivity/base/OicSecValidity;");
525 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_ace_get_validities);
528 clazz = env->FindClass("org/iotivity/base/OicSecResr");
529 VERIFY_VARIABLE_NULL(clazz);
530 g_cls_OcOicSecAcl_resr = (jclass)env->NewGlobalRef(clazz);
531 env->DeleteLocalRef(clazz);
533 g_mid_OcOicSecAcl_resr_get_href = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getHref","()Ljava/lang/String;");
534 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_href);
536 g_mid_OcOicSecAcl_resr_get_rel = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getRel","()Ljava/lang/String;");
537 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_rel);
539 g_mid_OcOicSecAcl_resr_get_types = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getTypes","(I)Ljava/lang/String;");
540 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_types);
542 g_mid_OcOicSecAcl_resr_get_typeLen = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getTypeLen","()I");
543 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_typeLen);
545 g_mid_OcOicSecAcl_resr_get_interfaces = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getInterfaces","(I)Ljava/lang/String;");
546 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_interfaces);
548 g_mid_OcOicSecAcl_resr_get_interfaceLen = env->GetMethodID(g_cls_OcOicSecAcl_resr, "getInterfaceLen","()I");
549 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_resr_get_interfaceLen);
551 //OicSecAcl$OicSecValidity
552 clazz = env->FindClass("org/iotivity/base/OicSecValidity");
553 VERIFY_VARIABLE_NULL(clazz);
554 g_cls_OcOicSecAcl_validity = (jclass)env->NewGlobalRef(clazz);
555 env->DeleteLocalRef(clazz);
557 g_mid_OcOicSecAcl_validity_get_getPeriod = env->GetMethodID(g_cls_OcOicSecAcl_validity, "getPeriod","()Ljava/lang/String;");
558 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_validity_get_getPeriod);
560 g_mid_OcOicSecAcl_validity_get_recurrences = env->GetMethodID(g_cls_OcOicSecAcl_validity, "getRecurrences","(I)Ljava/lang/String;");
561 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_validity_get_recurrences);
563 g_mid_OcOicSecAcl_validity_get_recurrenceLen = env->GetMethodID(g_cls_OcOicSecAcl_validity, "getRecurrenceLen","()I");
564 VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_validity_get_recurrenceLen);
567 clazz = env->FindClass("org/iotivity/base/OicSecPdAcl");
568 VERIFY_VARIABLE_NULL(clazz);
569 g_cls_OcOicSecPdAcl = (jclass)env->NewGlobalRef(clazz);
570 env->DeleteLocalRef(clazz);
572 g_mid_OcOicSecPdAcl_get_resources_cnt = env->GetMethodID(g_cls_OcOicSecPdAcl, "getResourcesCount", "()I");
573 VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_resources_cnt);
575 g_mid_OcOicSecPdAcl_get_resources = env->GetMethodID(g_cls_OcOicSecPdAcl, "getResources", "(I)Ljava/lang/String;");
576 VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_resources);
578 g_mid_OcOicSecPdAcl_get_permission = env->GetMethodID(g_cls_OcOicSecPdAcl, "getPermission", "()I");
579 VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_permission);
581 g_mid_OcOicSecPdAcl_get_periods_cnt = env->GetMethodID(g_cls_OcOicSecPdAcl, "getPeriodsCount", "()I");
582 VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_periods_cnt);
584 g_mid_OcOicSecPdAcl_get_periods = env->GetMethodID(g_cls_OcOicSecPdAcl, "getPeriods", "(I)Ljava/lang/String;");
585 VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_periods);
587 g_mid_OcOicSecPdAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecPdAcl, "getRecurrences", "(I)Ljava/lang/String;");
588 VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_recurrences);
590 return JNI_CURRENT_VERSION;
593 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
595 LOGI("JNI_OnUnload");
596 JNIEnv* env = nullptr;
598 if (vm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
600 LOGE("Failed to get the environment using GetEnv()");
606 env->DeleteGlobalRef(g_cls_Integer);
607 env->DeleteGlobalRef(g_cls_int1DArray);
608 env->DeleteGlobalRef(g_cls_int2DArray);
609 env->DeleteGlobalRef(g_cls_Double);
610 env->DeleteGlobalRef(g_cls_double1DArray);
611 env->DeleteGlobalRef(g_cls_double2DArray);
612 env->DeleteGlobalRef(g_cls_Boolean);
613 env->DeleteGlobalRef(g_cls_boolean1DArray);
614 env->DeleteGlobalRef(g_cls_boolean2DArray);
615 env->DeleteGlobalRef(g_cls_String);
616 env->DeleteGlobalRef(g_cls_String1DArray);
617 env->DeleteGlobalRef(g_cls_String2DArray);
618 env->DeleteGlobalRef(g_cls_LinkedList);
619 env->DeleteGlobalRef(g_cls_Map);
620 env->DeleteGlobalRef(g_cls_MapEntry);
621 env->DeleteGlobalRef(g_cls_Set);
622 env->DeleteGlobalRef(g_cls_Iterator);
623 env->DeleteGlobalRef(g_cls_HashMap);
624 env->DeleteGlobalRef(g_cls_OcResource);
625 env->DeleteGlobalRef(g_cls_OcException);
626 env->DeleteGlobalRef(g_cls_OcRepresentation);
627 env->DeleteGlobalRef(g_cls_OcRepresentation1DArray);
628 env->DeleteGlobalRef(g_cls_OcRepresentation2DArray);
629 env->DeleteGlobalRef(g_cls_OcResourceRequest);
630 env->DeleteGlobalRef(g_cls_OcResourceResponse);
631 env->DeleteGlobalRef(g_cls_OcResourceHandle);
632 env->DeleteGlobalRef(g_cls_OcPresenceHandle);
633 env->DeleteGlobalRef(g_cls_OcRequestHandle);
634 env->DeleteGlobalRef(g_cls_OcPresenceStatus);
635 env->DeleteGlobalRef(g_cls_OcHeaderOption);
636 env->DeleteGlobalRef(g_cls_ObservationInfo);
637 env->DeleteGlobalRef(g_cls_OcResourceIdentifier);
638 env->DeleteGlobalRef(g_cls_OcSecureResource);
639 env->DeleteGlobalRef(g_cls_OcProvisionResult);
640 env->DeleteGlobalRef(g_cls_OcDirectPairDevice);
642 env->DeleteGlobalRef(g_cls_OcAccountManager);
644 env->DeleteGlobalRef(g_cls_OcOicSecAcl);
645 env->DeleteGlobalRef(g_cls_OcOicSecAcl_ace);
646 env->DeleteGlobalRef(g_cls_OcOicSecAcl_resr);
647 env->DeleteGlobalRef(g_cls_OcOicSecAcl_validity);