1 /******************************************************************
3 * Copyright 2015 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();
41 JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject thiz)
43 JniRemoteEnrollee *remoteEnrollee = ESGetHandle<JniRemoteEnrollee>(env, thiz);
44 if (env->ExceptionCheck())
46 LOGE("getJniRemoteEnrollee :: Failed to get native handle from RemoteEnrollee object");
50 LOGE("getJniRemoteEnrollee :: no resource");
52 return remoteEnrollee;
55 void JniRemoteEnrollee::startProvisioning(JNIEnv *env)
59 m_sharedResource->startProvisioning();
61 catch (ESBadRequestException exception)
63 LOGE("JNI startProvisioning :: Exception occured");
64 //throw the exception to java
65 throwESException( env, exception.what());
68 void JniRemoteEnrollee::stopProvisioning(JNIEnv *env)
72 m_sharedResource->stopProvisioning();
74 catch (ESBadRequestException exception)
76 LOGE("JNI stopProvisioning :: Exception occured");
77 //throw the exception to java
78 throwESException( env, exception.what());
82 void JniRemoteEnrollee::registerProvisioningHandler(JNIEnv *env, jobject jListener)
84 JniProvisioningStatusListener *onProvisioningStatusReceived = addProvisioningStatusListener(env,
87 RemoteEnrollee::EasySetupStatusCB provisionStatusCallback = [onProvisioningStatusReceived]
88 (std::shared_ptr< OIC::Service::EasySetupStatus > easySetupStatus)
91 onProvisioningStatusReceived->provisionStatusCallback(easySetupStatus);
96 m_sharedResource->registerEasySetupStatusHandler(provisionStatusCallback);
98 catch (ESException exception)
100 LOGE("JNI stopProvisioning :: Exception occured");
101 //throw the exception to java
102 throwESException( env, exception.what());
107 JniProvisioningStatusListener *JniRemoteEnrollee::addProvisioningStatusListener(JNIEnv *env,
110 return this->m_provisioingStatus.addListener(env, jListener, this);
113 void JniRemoteEnrollee::removeProvisioningStatusListener(JNIEnv *env, jobject jListener)
115 this->m_provisioingStatus.removeListener(env, jListener);
118 JNIEXPORT void JNICALL
119 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartProvision
120 (JNIEnv *env, jobject jClass)
122 LOGD("nativeStartProvision Enter");
124 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
125 remoteEnrollee->startProvisioning(env);
127 LOGD("nativeStartProvision Exit");
130 JNIEXPORT void JNICALL
131 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStopProvision
132 (JNIEnv *env, jobject jClass)
135 LOGD("nativeStopProvision Enter");
137 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
138 remoteEnrollee->stopProvisioning(env);
140 LOGD("nativeStopProvision Exit");
143 JNIEXPORT void JNICALL
144 Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRegisterProvisioningHandler
145 (JNIEnv *env, jobject jClass, jobject provisiongListener)
147 LOGD("nativeRegisterProvisioningHandler Enter");
149 if (!provisiongListener)
151 LOGE("nativeRegisterProvisioningHandler : listener is NULL");
154 JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
155 remoteEnrollee->registerProvisioningHandler(env, provisiongListener);
157 LOGD("nativeRegisterProvisioningHandler Exit");