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 using namespace OIC::Service;
25 JniRemoteEnrollee::JniRemoteEnrollee(std::shared_ptr<RemoteEnrollee> remoteEnrollee)
26 : m_sharedResource(remoteEnrollee) {}
28 JniRemoteEnrollee::~JniRemoteEnrollee()
30 LOGD("JniRemoteEnrollee::~JniRemoteEnrollee()");
31 m_sharedResource = NULL;
34 JNIEnv *env = GetESJNIEnv(envRet);
35 if (NULL == env) return;
37 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
40 JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject thiz)
42 JniRemoteEnrollee *remoteEnrollee = ESGetHandle<JniRemoteEnrollee>(env, thiz);
43 if (env->ExceptionCheck())
45 LOGE("getJniRemoteEnrollee :: Failed to get native handle from RemoteEnrollee object");
49 LOGE("getJniRemoteEnrollee :: no resource");
51 return remoteEnrollee;
54 JNIEXPORT void JNICALL
55 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetCloudProvInfo
56 (JNIEnv *env, jobject jClass, jstring jauthCode, jstring jauthProvider, jstring jciServer)
58 LOGD("nativeSetCloudProvInfo Enter");
61 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
62 remoteEnrollee->setCloudProvInfo(env, jauthCode, jauthProvider, jciServer);
64 LOGD("nativeSetCloudProvInfo Exit");
67 JNIEXPORT void JNICALL
68 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartCloudProvisioning
69 (JNIEnv *env, jobject jClass, jobject jListener)
71 LOGD("nativeStartCloudProvisioning Enter");
73 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
74 remoteEnrollee->startCloudProvisioning(env, jListener);
76 LOGD("nativeStartCloudProvisioning Exit");
79 void JniRemoteEnrollee::setCloudProvInfo(JNIEnv *env, jstring jauthCode, jstring jauthProvider, jstring jciServer)
82 info.authCode = env->GetStringUTFChars(jauthCode, NULL);
83 info.authProvider = env->GetStringUTFChars(jauthProvider, NULL);
84 info.ciServer = env->GetStringUTFChars(jciServer, NULL);
86 m_sharedResource->setCloudProvInfo(info);
89 void JniRemoteEnrollee::startCloudProvisioning(JNIEnv *env, jobject jListener)
91 JniCloudProvisioningStatusListener *onCloudProvisioningStatusReceived = addCloudProvisioningStatusListener(env,
94 CloudProvStatusCb provisionStatusCallback = [onCloudProvisioningStatusReceived]
95 (std::shared_ptr< OIC::Service::CloudProvisioningStatus > cloudProvisioningStatus)
98 onCloudProvisioningStatusReceived->onCloudProvisioningStatus(cloudProvisioningStatus);
103 m_sharedResource->startCloudProvisioning(provisionStatusCallback);
105 catch (ESBadRequestException exception)
107 LOGE("JNI startProvisioning :: Exception occured");
108 //throw the exception to java
109 throwESException(env, exception.what());
113 JniCloudProvisioningStatusListener *JniRemoteEnrollee::addCloudProvisioningStatusListener(JNIEnv *env,
116 return this->m_cloudProvisioningStatus.addListener(env, jListener, this);
119 void JniRemoteEnrollee::removeCloudProvisioningStatusListener(JNIEnv *env, jobject jListener)
121 this->m_cloudProvisioningStatus.removeListener(env, jListener);