1 /******************************************************************
3 * Copyright 2016 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 ******************************************************************/
24 jclass g_cls_RemoteEnrollee = NULL;
25 jclass g_cls_ESException = NULL;
26 jclass g_cls_EnrolleeStatus = NULL;
27 jclass g_cls_EnrolleeConf = NULL;
28 jclass g_cls_getEnrolleeStatus = NULL;
29 jclass g_cls_getConfigurationStatus = NULL;
30 jclass g_cls_SecurityProvisioningStatus = NULL;
31 jclass g_cls_DevicePropProvisioningStatus = NULL;
32 jclass g_cls_CloudPropProvisioningStatus = NULL;
33 jclass g_cls_Integer = NULL;
34 jclass g_cls_OcRepresentation = NULL;
36 jmethodID g_mid_RemoteEnrollee_ctor = NULL;
37 jmethodID g_mid_ESException_ctor = NULL;
38 jmethodID g_mid_EnrolleeStatus_ctor = NULL;
39 jmethodID g_mid_EnrolleeConf_ctor = NULL;
40 jmethodID g_mid_getEnrolleeStatus_ctor = NULL;
41 jmethodID g_mid_getConfigurationStatus_ctor = NULL;
42 jmethodID g_mid_SecurityProvisioningStatus_ctor = NULL;
43 jmethodID g_mid_DevicePropProvisioningStatus_ctor = NULL;
44 jmethodID g_mid_CloudPropProvisioningStatus_ctor = NULL;
45 jmethodID g_mid_Integer_ctor = NULL;
46 jmethodID g_mid_OcRepresentation_N_ctor_bool = NULL;
49 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
51 ES_LOGI("JNI_OnLoad");
55 if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
57 ES_LOGE("Failed to get the environment using GetEnv()");
61 jclass clazz = nullptr;
64 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/RemoteEnrollee");
65 if (!clazz) return JNI_ERR;
66 g_cls_RemoteEnrollee = (jclass)env->NewGlobalRef(clazz);
67 env->DeleteLocalRef(clazz);
69 g_mid_RemoteEnrollee_ctor = env->GetMethodID(g_cls_RemoteEnrollee, "<init>",
71 if (!g_mid_RemoteEnrollee_ctor) return JNI_ERR;
74 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/ESException");
75 if (!clazz) return JNI_ERR;
76 g_cls_ESException = (jclass)env->NewGlobalRef(clazz);
77 env->DeleteLocalRef(clazz);
79 g_mid_ESException_ctor = env->GetMethodID(g_cls_ESException, "<init>", "(Ljava/lang/String;)V");
80 if (!g_mid_ESException_ctor) return JNI_ERR;
83 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/EnrolleeStatus");
84 if (!clazz) return JNI_ERR;
86 g_cls_EnrolleeStatus = (jclass)env->NewGlobalRef(clazz);
87 env->DeleteLocalRef(clazz);
89 g_mid_EnrolleeStatus_ctor = env->GetMethodID(g_cls_EnrolleeStatus, "<init>",
90 "(Lorg/iotivity/base/OcRepresentation;)V");
91 if (!g_mid_EnrolleeStatus_ctor) return JNI_ERR;
94 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/EnrolleeConf");
95 if (!clazz) return JNI_ERR;
97 g_cls_EnrolleeConf = (jclass)env->NewGlobalRef(clazz);
98 env->DeleteLocalRef(clazz);
100 g_mid_EnrolleeConf_ctor = env->GetMethodID(g_cls_EnrolleeConf, "<init>",
101 "(Lorg/iotivity/base/OcRepresentation;)V");
102 if (!g_mid_EnrolleeConf_ctor) return JNI_ERR;
105 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/GetEnrolleeStatus");
106 if (!clazz) return JNI_ERR;
108 g_cls_getEnrolleeStatus = (jclass)env->NewGlobalRef(clazz);
109 env->DeleteLocalRef(clazz);
111 g_mid_getEnrolleeStatus_ctor = env->GetMethodID(g_cls_getEnrolleeStatus, "<init>",
112 "(ILorg/iotivity/service/easysetup/mediator/EnrolleeStatus;)V");
113 if (!g_mid_getEnrolleeStatus_ctor) return JNI_ERR;
115 // getConfigurationStatus
116 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/GetConfigurationStatus");
117 if (!clazz) return JNI_ERR;
119 g_cls_getConfigurationStatus = (jclass)env->NewGlobalRef(clazz);
120 env->DeleteLocalRef(clazz);
122 g_mid_getConfigurationStatus_ctor = env->GetMethodID(g_cls_getConfigurationStatus, "<init>",
123 "(ILorg/iotivity/service/easysetup/mediator/EnrolleeConf;)V");
124 if (!g_mid_getConfigurationStatus_ctor) return JNI_ERR;
126 // SecurityProvisioningStatus
127 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/SecurityProvisioningStatus");
128 if (!clazz) return JNI_ERR;
130 g_cls_SecurityProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
131 env->DeleteLocalRef(clazz);
133 g_mid_SecurityProvisioningStatus_ctor = env->GetMethodID(g_cls_SecurityProvisioningStatus, "<init>",
134 "(ILjava/lang/String;)V");
135 if (!g_mid_SecurityProvisioningStatus_ctor) return JNI_ERR;
137 // DevicePropProvisioningStatus
138 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/DevicePropProvisioningStatus");
139 if (!clazz) return JNI_ERR;
141 g_cls_DevicePropProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
142 env->DeleteLocalRef(clazz);
144 g_mid_DevicePropProvisioningStatus_ctor = env->GetMethodID(g_cls_DevicePropProvisioningStatus, "<init>",
146 if (!g_mid_DevicePropProvisioningStatus_ctor) return JNI_ERR;
148 // CloudPropProvisioningStatus
149 clazz = env->FindClass("org/iotivity/service/easysetup/mediator/CloudPropProvisioningStatus");
150 if (!clazz) return JNI_ERR;
151 g_cls_CloudPropProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
152 env->DeleteLocalRef(clazz);
154 g_mid_CloudPropProvisioningStatus_ctor = env->GetMethodID(g_cls_CloudPropProvisioningStatus, "<init>",
156 if (!g_mid_CloudPropProvisioningStatus_ctor) return JNI_ERR;
159 clazz = env->FindClass("java/lang/Integer");
160 if (!clazz) return JNI_ERR;
161 g_cls_Integer = (jclass)env->NewGlobalRef(clazz);
162 env->DeleteLocalRef(clazz);
164 g_mid_Integer_ctor = env->GetMethodID(g_cls_Integer, "<init>",
166 if (!g_mid_Integer_ctor) return JNI_ERR;
169 clazz = env->FindClass("org/iotivity/base/OcRepresentation");
170 if (!clazz) return JNI_ERR;
171 g_cls_OcRepresentation = (jclass)env->NewGlobalRef(clazz);
172 env->DeleteLocalRef(clazz);
174 g_mid_OcRepresentation_N_ctor_bool = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(JZ)V");
175 if (!g_mid_OcRepresentation_N_ctor_bool) return JNI_ERR;
177 return JNI_CURRENT_VERSION;
181 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
183 ES_LOGI("JNI_OnUnload");
186 if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
188 ES_LOGE("Failed to get the environment using GetEnv()");
191 env->DeleteGlobalRef(g_cls_RemoteEnrollee);
192 env->DeleteGlobalRef(g_cls_ESException);