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,
163 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
173 CloudProp cloudProp(*representation);
174 cloudProp.setCloudID(env->GetStringUTFChars(jCloudID, NULL));
175 cloudProp.setCredID(jCredID);
177 JniCloudPropProvisioningStatusListener *onCloudPropProvisioningStatusReceived =
178 addStatusListener<JniCloudPropProvisioningStatusListener>(env, jListener);
180 CloudPropProvStatusCb cloudPropProvStatusCallback = [onCloudPropProvisioningStatusReceived]
181 (std::shared_ptr< OIC::Service::CloudPropProvisioningStatus > cloudPropProvisioningStatus)
184 onCloudPropProvisioningStatusReceived->onCloudPropProvisioningStatus(cloudPropProvisioningStatus);
189 m_sharedResource->provisionCloudProperties(cloudProp, cloudPropProvStatusCallback);
191 catch (ESBadRequestException exception)
193 ES_LOGE("JNI startProvisioning :: Exception occured");
194 //throw the exception to java
195 throwESException(env, exception.what());
200 JNIEXPORT void JNICALL
201 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeGetStatus
202 (JNIEnv *env, jobject jClass, jobject jListener)
204 ES_LOGD("nativeGetStatus Enter");
206 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
207 remoteEnrollee->getStatus(env, jListener);
209 ES_LOGD("nativeGetStatus Exit");
213 JNIEXPORT void JNICALL
214 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeGetConfiguration
215 (JNIEnv *env, jobject jClass, jobject jListener)
217 ES_LOGD("nativegetConfiguration Enter");
219 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
220 remoteEnrollee->getConfiguration(env, jListener);
222 ES_LOGD("nativegetConfiguration Exit");
225 JNIEXPORT void JNICALL
226 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionSecurity
227 (JNIEnv *env, jobject jClass, jobject jListener)
229 ES_LOGD("nativeStartSecurityProvision Enter");
231 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
232 remoteEnrollee->provisionSecurity(env, jListener);
234 ES_LOGD("nativeStartSecurityProvision Exit");
237 JNIEXPORT void JNICALL
238 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionDeviceProperties
239 (JNIEnv *env, jobject jClass, jobject jRepresentation, jobject jListener)
241 ES_LOGD("nativeProvisionDeviceProperties Enter");
243 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
244 remoteEnrollee->provisionDeviceProperties(env, jRepresentation, jListener);
246 ES_LOGD("nativeProvisionDeviceProperties Exit");
249 JNIEXPORT void JNICALL
250 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionCloudProperties
251 (JNIEnv *env, jobject jClass, jobject jRepresentation, jstring jCloudID, jint jCredID, jobject jListener)
253 ES_LOGD("nativeprovisionCloudProperties Enter");
255 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
256 remoteEnrollee->provisionCloudProperties(env, jRepresentation, jCloudID, jCredID, jListener);
258 ES_LOGD("nativeprovisionCloudProperties Exit");