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 ******************************************************************/
21 #include "JniRemoteEnrollee.h"
23 #include "JniOcRepresentation.h"
25 using namespace OIC::Service;
27 JniRemoteEnrollee::JniRemoteEnrollee(std::shared_ptr<RemoteEnrollee> remoteEnrollee)
28 : m_sharedResource(remoteEnrollee) {}
30 JniRemoteEnrollee::~JniRemoteEnrollee()
32 ES_LOGD("JniRemoteEnrollee::~JniRemoteEnrollee()");
33 m_sharedResource = NULL;
36 JNIEnv *env = GetESJNIEnv(envRet);
37 if (NULL == env) return;
39 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
42 JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject thiz)
44 JniRemoteEnrollee *remoteEnrollee = ESGetHandle<JniRemoteEnrollee>(env, thiz);
45 if (env->ExceptionCheck())
47 ES_LOGE("getJniRemoteEnrollee :: Failed to get native handle from RemoteEnrollee object");
51 ES_LOGE("getJniRemoteEnrollee :: no resource");
53 return remoteEnrollee;
56 void JniRemoteEnrollee::getStatus(JNIEnv *env, jobject jListener)
58 JniGetEnrolleeStatusListener *onGetEnrolleeStatusReceived =
59 addStatusListener<JniGetEnrolleeStatusListener>(env, jListener);
61 GetStatusCb getEnrolleeStatusCallback = [onGetEnrolleeStatusReceived]
62 (std::shared_ptr<OIC::Service::GetEnrolleeStatus > getEnrolleeStatus)
64 onGetEnrolleeStatusReceived->getEnrolleeStatusCallback(getEnrolleeStatus);
69 m_sharedResource->getStatus(getEnrolleeStatusCallback);
71 catch (ESBadRequestException exception)
73 ES_LOGE("JNI getStatus :: Exception occured");
74 //throw the exception to java
75 throwESException( env, exception.what());
79 void JniRemoteEnrollee::getConfiguration(JNIEnv *env, jobject jListener)
81 JniGetConfigurationStatusListener *onGetConfigurationStatusReceived =
82 addStatusListener<JniGetConfigurationStatusListener>(env, jListener);
84 GetConfigurationStatusCb getConfigurationStatusCallback = [onGetConfigurationStatusReceived]
85 (std::shared_ptr<OIC::Service::GetConfigurationStatus > getConfigurationStatus)
87 onGetConfigurationStatusReceived->getConfigurationStatusCallback(getConfigurationStatus);
92 m_sharedResource->getConfiguration(getConfigurationStatusCallback);
94 catch (ESBadRequestException exception)
96 ES_LOGE("JNI getConfiguration :: Exception occured");
97 //throw the exception to java
98 throwESException( env, exception.what());
102 void JniRemoteEnrollee::provisionSecurity(JNIEnv *env, jobject jListener)
104 JniSecurityStatusListener *onSecurityProvStatusReceived =
105 addStatusListener<JniSecurityStatusListener>(env, jListener);
107 SecurityProvStatusCb secProvStatusCallback = [onSecurityProvStatusReceived]
108 (std::shared_ptr<OIC::Service::SecProvisioningStatus > SecProvisioningStatus)
110 onSecurityProvStatusReceived->secProvisionStatusCallback(SecProvisioningStatus);
115 m_sharedResource->provisionSecurity(secProvStatusCallback);
117 catch (ESBadRequestException exception)
119 ES_LOGE("JNI provisionSecurity :: Exception occured");
120 //throw the exception to java
121 throwESException( env, exception.what());
125 void JniRemoteEnrollee::provisionDeviceProperties(JNIEnv *env,
126 jobject jRepresentation,
129 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
135 DeviceProp deviceProp(*representation);
136 JniDevicePropProvisioningStatusListener *onDevicePropProvStatusReceived =
137 addStatusListener<JniDevicePropProvisioningStatusListener>(env, jListener);
139 DevicePropProvStatusCb devicePropProvStatusCallback = [onDevicePropProvStatusReceived]
140 (std::shared_ptr<OIC::Service::DevicePropProvisioningStatus > devicePropProvisioningStatus)
142 onDevicePropProvStatusReceived->onDevicePropProvisioningStatusCallback(devicePropProvisioningStatus);
147 m_sharedResource->provisionDeviceProperties(deviceProp, devicePropProvStatusCallback);
149 catch (ESBadRequestException exception)
151 ES_LOGE("JNI provisionDeviceProperties :: Exception occured");
152 //throw the exception to java
153 throwESException( env, exception.what());
157 void JniRemoteEnrollee::provisionCloudProperties(JNIEnv *env,
158 jobject jRepresentation,
162 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
168 CloudProp cloudProp(*representation);
169 cloudProp.setCloudID(env->GetStringUTFChars(jCloudID, NULL));
171 JniCloudPropProvisioningStatusListener *onCloudPropProvisioningStatusReceived =
172 addStatusListener<JniCloudPropProvisioningStatusListener>(env, jListener);
174 CloudPropProvStatusCb cloudPropProvStatusCallback = [onCloudPropProvisioningStatusReceived]
175 (std::shared_ptr< OIC::Service::CloudPropProvisioningStatus > cloudPropProvisioningStatus)
178 onCloudPropProvisioningStatusReceived->onCloudPropProvisioningStatus(cloudPropProvisioningStatus);
183 m_sharedResource->provisionCloudProperties(cloudProp, cloudPropProvStatusCallback);
185 catch (ESBadRequestException exception)
187 ES_LOGE("JNI startProvisioning :: Exception occured");
188 //throw the exception to java
189 throwESException(env, exception.what());
194 JNIEXPORT void JNICALL
195 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeGetStatus
196 (JNIEnv *env, jobject jClass, jobject jListener)
198 ES_LOGD("nativeGetStatus Enter");
200 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
201 remoteEnrollee->getStatus(env, jListener);
203 ES_LOGD("nativeGetStatus Exit");
207 JNIEXPORT void JNICALL
208 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeGetConfiguration
209 (JNIEnv *env, jobject jClass, jobject jListener)
211 ES_LOGD("nativegetConfiguration Enter");
213 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
214 remoteEnrollee->getConfiguration(env, jListener);
216 ES_LOGD("nativegetConfiguration Exit");
219 JNIEXPORT void JNICALL
220 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionSecurity
221 (JNIEnv *env, jobject jClass, jobject jListener)
223 ES_LOGD("nativeStartSecurityProvision Enter");
225 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
226 remoteEnrollee->provisionSecurity(env, jListener);
228 ES_LOGD("nativeStartSecurityProvision Exit");
231 JNIEXPORT void JNICALL
232 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionDeviceProperties
233 (JNIEnv *env, jobject jClass, jobject jRepresentation, jobject jListener)
235 ES_LOGD("nativeProvisionDeviceProperties Enter");
237 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
238 remoteEnrollee->provisionDeviceProperties(env, jRepresentation, jListener);
240 ES_LOGD("nativeProvisionDeviceProperties Exit");
243 JNIEXPORT void JNICALL
244 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionCloudProperties
245 (JNIEnv *env, jobject jClass, jobject jRepresentation, jstring jCloudID, jobject jListener)
247 ES_LOGD("nativeprovisionCloudProperties Enter");
249 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
250 remoteEnrollee->provisionCloudProperties(env, jRepresentation, jCloudID, jListener);
252 ES_LOGD("nativeprovisionCloudProperties Exit");