- JNI Logic implement(initRemoteEnrollee, RequestPropertyData, DataProvisioning, SecurityProvisioning)
Change-Id: Ic38924573b4c733bfa257b4ddb763f49e8cca00c
Signed-off-by: Heewon Park <h_w.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9015
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
{
jthrowable ex = env->ExceptionOccurred();
env->ExceptionClear();
- m_ownerResource->removeCloudProvisioningStatusListener(env, m_jwListener);
+ m_ownerResource->removeStatusListener<JniCloudProvisioningStatusListener>(env, m_jwListener);
env->Throw((jthrowable)ex);
}
else
{
- m_ownerResource->removeCloudProvisioningStatusListener(env, m_jwListener);
+ m_ownerResource->removeStatusListener<JniCloudProvisioningStatusListener>(env, m_jwListener);
}
}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "JniDataProvisioningStatusListener.h"
+#include "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniDataProvisioningStatusListener::JniDataProvisioningStatusListener(JNIEnv *env, jobject jListener,
+ JniRemoteEnrollee *owner)
+ : m_ownerResource(owner)
+{
+ m_jwListener = env->NewWeakGlobalRef(jListener);
+}
+
+JniDataProvisioningStatusListener::~JniDataProvisioningStatusListener()
+{
+ LOGI("~JniDataProvisioningStatusListener()");
+ if (m_jwListener)
+ {
+ jint ret;
+ JNIEnv *env = GetESJNIEnv(ret);
+ if (NULL == env) return;
+ env->DeleteWeakGlobalRef(m_jwListener);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ }
+}
+
+void JniDataProvisioningStatusListener::dataProvisionStatusCallback (std::shared_ptr<DataProvisioningStatus>
+ dataProvStatusCb)
+{
+
+ LOGI("JniDataProvisioningStatusListener::provisioiningStatusCallback enter");
+
+ jint ret;
+ JNIEnv *env = GetESJNIEnv(ret);
+ if (NULL == env) return;
+ jobject jListener = env->NewLocalRef(m_jwListener);
+ if (!jListener)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ jclass clsL = env->GetObjectClass(jListener);
+ if (!clsL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+ //TODO:
+ jmethodID midL = env->GetMethodID(clsL, "onProgress",
+ "(Lorg/iotivity/service/easysetup/mediator/"
+ "DataProvisioningCallback;"
+ ")V");
+
+ if (!midL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ int nativeESResult = convertNativeDataProvResultToInt(dataProvStatusCb->getESResult());
+ int nativeESDataProvState = convertNativeDataProvStateToInt(dataProvStatusCb->getESDataProvState());
+
+ jobject jDataProvisioningStatus = NULL;
+ jDataProvisioningStatus = env->NewObject(g_cls_DataProvisioningStatus,
+ g_mid_DataProvisioningStatus_ctor,
+ (jint)nativeESResult,
+ (jint)nativeESDataProvState);
+
+ LOGI("JniDataProvisioningStatus::onDataProvisioningStatus - %d, %d", nativeESResult, nativeESDataProvState);
+ if (!jDataProvisioningStatus)
+ {
+ LOGE("JniDataProvisioningStatus::onDataProvisioningStatus Unable to create the java object");
+ return ;
+ }
+
+ env->CallVoidMethod(jListener, midL, jDataProvisioningStatus);
+
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniDataProvisioningStatusListener::checkExAndRemoveListener(JNIEnv *env)
+{
+ if (env->ExceptionCheck())
+ {
+ jthrowable ex = env->ExceptionOccurred();
+ env->ExceptionClear();
+ m_ownerResource->removeStatusListener<JniDataProvisioningStatusListener>(env, m_jwListener);
+ env->Throw((jthrowable)ex);
+ }
+ else
+ {
+ m_ownerResource->removeStatusListener<JniDataProvisioningStatusListener>(env, m_jwListener);
+ }
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef __JNI_ES_DATA_PROVISIONING_STATUS_LISTENER_H_
+#define __JNI_ES_DATA_PROVISIONING_STATUS_LISTENER_H_
+
+#include <jni.h>
+
+#include "RemoteEnrollee.h"
+#include "ESRichCommon.h"
+
+#include "JniJvm.h"
+
+class JniRemoteEnrollee;
+
+using namespace OIC::Service;
+
+class JniDataProvisioningStatusListener
+{
+ public:
+ /**
+ * @brief constructor
+ */
+ JniDataProvisioningStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+
+ /**
+ * @brief destructor
+ */
+ ~JniDataProvisioningStatusListener();
+
+ /**
+ * @brief callback function that will be passed to Native layer
+ */
+ void dataProvisionStatusCallback (std::shared_ptr<DataProvisioningStatus> dataProvisioningStatus);
+
+ private:
+ jweak m_jwListener;
+ JniRemoteEnrollee *m_ownerResource;
+ void checkExAndRemoveListener(JNIEnv *env);
+};
+
+#endif //__JNI_ES_DATA_PROVISIONING_STATUS_LISTENER_H_
}
return CT_DEFAULT;
}
+
+WIFI_AUTHTYPE getWifiAuthTypeFromInt(int authType)
+{
+ switch (authType)
+ {
+ case 0:
+ return WIFI_AUTHTYPE::NONE_AUTH;
+ case 1:
+ return WIFI_AUTHTYPE::WEP;
+ case 2:
+ return WIFI_AUTHTYPE::WPA_PSK;
+ case 3:
+ return WIFI_AUTHTYPE::WPA2_PSK;
+ }
+ return NONE_AUTH;
+}
+
+WIFI_ENCTYPE getWifiEncTypeFromInt(int encType)
+{
+ switch (encType)
+ {
+ case 0:
+ return WIFI_ENCTYPE::NONE_ENC;
+ case 1:
+ return WIFI_ENCTYPE::WEP_64;
+ case 2:
+ return WIFI_ENCTYPE::WEP_128;
+ case 3:
+ return WIFI_ENCTYPE::TKIP;
+ case 4:
+ return WIFI_ENCTYPE::AES;
+ case 5:
+ return WIFI_ENCTYPE::TKIP_AES;
+ }
+ return NONE_ENC;
+}
+
+int convertNativeWifiFreqToInt(WIFI_FREQ wifiFreq)
+{
+ switch (wifiFreq)
+ {
+ case WIFI_FREQ::WIFI_24G:
+ return 0;
+ case WIFI_FREQ::WIFI_5G:
+ return 1;
+ case WIFI_FREQ::WIFI_BOTH:
+ return 2;
+ }
+}
+
+int convertNativeWifiModeToInt(WIFI_MODE wifiMode)
+{
+ switch (wifiMode)
+ {
+ case WIFI_MODE::WIFI_11A:
+ return 0;
+ case WIFI_MODE::WIFI_11B:
+ return 1;
+ case WIFI_MODE::WIFI_11G:
+ return 2;
+ case WIFI_MODE::WIFI_11N:
+ return 3;
+ case WIFI_MODE::WIFI_11AC:
+ return 4;
+ }
+}
+
+int convertNativeDataProvStateToInt(ESDataProvState nativeState)
+{
+ switch (nativeState)
+ {
+ case ESDataProvState::ES_PROVISIONING_ERROR:
+ return -1;
+ case ESDataProvState::ES_NEED_PROVISIONING:
+ return 0;
+ case ESDataProvState::ES_PROVISIONED_ALREADY:
+ return 1;
+ case ESDataProvState::ES_PROVISIONING_SUCCESS:
+ return 2;
+ }
+}
+
+int convertNativeDataProvResultToInt(ESResult nativeResult)
+{
+ switch (nativeResult)
+ {
+ case ESResult::ES_ERROR:
+ return -1;
+ case ESResult::ES_OK:
+ return 0;
+ case ESResult::ES_NETWORKFOUND:
+ return 1;
+ case ESResult::ES_NETWORKCONNECTED:
+ return 2;
+ case ESResult::ES_NETWORKNOTCONNECTED:
+ return 3;
+ case ESResult::ES_RESOURCECREATED:
+ return 11;
+ case ESResult::ES_RECVREQOFPROVRES:
+ return 21;
+ case ESResult::ES_RECVREQOFNETRES:
+ return 22;
+ case ESResult::ES_RECVUPDATEOFPROVRES:
+ return 23;
+ case ESResult::ES_RECVTRIGGEROFPROVRES:
+ return 24;
+ case ESResult::ES_UNAUTHORIZED:
+ return 31;
+ }
+}
\ No newline at end of file
*/
OCConnectivityType getOCConnectivityTypeFromInt(int connectivityType);
+WIFI_AUTHTYPE getWifiAuthTypeFromInt(int authType);
+WIFI_ENCTYPE getWifiEncTypeFromInt(int encType);
+int convertNativeWifiFreqToInt(WIFI_FREQ wifiFreq);
+int convertNativeWifiModeToInt(WIFI_MODE wifiMode);
+int convertNativeDataProvStateToInt(ESDataProvState nativeState);
+int convertNativeDataProvResultToInt(ESResult nativeResult);
#endif //__JNI_ES_UTILS_H_
JavaVM *g_jvm = NULL;
jclass g_cls_RemoteEnrollee = NULL;
+jclass g_cls_PropertyData = NULL;
+jclass g_cls_DeviceConfig = NULL;
+jclass g_cls_NetworkInfo = NULL;
+jclass g_cls_RequestPropertyDataStatus = NULL;
+jclass g_cls_SecurityProvisioningStatus = NULL;
+jclass g_cls_DataProvisioningStatus = NULL;
jclass g_cls_ESException = NULL;
jclass g_cls_CloudProvisioningStatus = NULL;
jmethodID g_mid_RemoteEnrollee_ctor = NULL;
jmethodID g_mid_ESException_ctor = NULL;
+jmethodID g_mid_PropertyData_ctor = NULL;
+jmethodID g_mid_DeviceConfig_ctor = NULL;
+jmethodID g_mid_NetworkInfo_ctor = NULL;
+jmethodID g_mid_RequestPropertyDataStatus_ctor = NULL;
+jmethodID g_mid_SecurityProvisioningStatus_ctor = NULL;
+jmethodID g_mid_DataProvisioningStatus_ctor = NULL;
jmethodID g_mid_CloudProvisioningStatus_ctor = NULL;
// JNI OnLoad
g_mid_ESException_ctor = env->GetMethodID(g_cls_ESException, "<init>", "(Ljava/lang/String;)V");
if (!g_mid_ESException_ctor) return JNI_ERR;
+ // DeviceConfig
+ clazz = env->FindClass("org/iotivity/service/easysetup/mediator/DeviceConfig");
+ if (!clazz) return JNI_ERR;
+
+ g_cls_DeviceConfig = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_DeviceConfig_ctor = env->GetMethodID(g_cls_DeviceConfig, "<init>",
+ "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
+ if (!g_mid_DeviceConfig_ctor) return JNI_ERR;
+
+ // NetworkInfo
+ clazz = env->FindClass("org/iotivity/service/easysetup/mediator/NetworkInfo");
+ if (!clazz) return JNI_ERR;
+
+ g_cls_NetworkInfo = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_NetworkInfo_ctor = env->GetMethodID(g_cls_NetworkInfo, "<init>",
+ "(Ljava.util.ArrayList;I)V");
+ if (!g_mid_NetworkInfo_ctor) return JNI_ERR;
+
+ // PropertyData
+ clazz = env->FindClass("org/iotivity/service/easysetup/mediator/PropertyData");
+ if (!clazz) return JNI_ERR;
+
+ g_cls_PropertyData = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_PropertyData_ctor = env->GetMethodID(g_cls_PropertyData, "<init>",
+ "(LDeviceConfig;LNetworkInfo;Z)V");
+ if (!g_mid_PropertyData_ctor) return JNI_ERR;
+
+ // RequestPropertyDataStatus
+
+ clazz = env->FindClass("org/iotivity/service/easysetup/mediator/RequestPropertyDataStatus");
+ if (!clazz) return JNI_ERR;
+
+ g_cls_RequestPropertyDataStatus = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_RequestPropertyDataStatus_ctor = env->GetMethodID(g_cls_RequestPropertyDataStatus, "<init>",
+ "(ILPropertyData;)V");
+ if (!g_mid_RequestPropertyDataStatus_ctor) return JNI_ERR;
+
+ // SecurityProvisioningStatus
+ clazz = env->FindClass("org/iotivity/service/easysetup/mediator/SecurityProvisioningStatus");
+ if (!clazz) return JNI_ERR;
+
+ g_cls_SecurityProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_SecurityProvisioningStatus_ctor = env->GetMethodID(g_cls_SecurityProvisioningStatus, "<init>",
+ "(ILjava/lang/String;)V");
+ if (!g_mid_SecurityProvisioningStatus_ctor) return JNI_ERR;
+
+ // DataProvisioningStatus
+ clazz = env->FindClass("org/iotivity/service/easysetup/mediator/DataProvisioningStatus");
+ if (!clazz) return JNI_ERR;
+
+ g_cls_DataProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_DataProvisioningStatus_ctor = env->GetMethodID(g_cls_DataProvisioningStatus, "<init>",
+ "(II)V");
+ if (!g_mid_DataProvisioningStatus_ctor) return JNI_ERR;
+
// CloudProvisioningStatus
clazz = env->FindClass("org/iotivity/service/easysetup/mediator/CloudProvisioningStatus");
if (!clazz) return JNI_ERR;
extern jclass g_cls_RemoteEnrollee;
extern jclass g_cls_ESException;
+extern jclass g_cls_PropertyData;
+extern jclass g_cls_DeviceConfig;
+extern jclass g_cls_NetworkInfo;
+extern jclass g_cls_RequestPropertyDataStatus;
+extern jclass g_cls_SecurityProvisioningStatus;
+extern jclass g_cls_DataProvisioningStatus;
extern jclass g_cls_CloudProvisioningStatus;
extern jmethodID g_mid_RemoteEnrollee_ctor;
extern jmethodID g_mid_ESException_ctor;
+extern jmethodID g_mid_PropertyData_ctor;
+extern jmethodID g_mid_DeviceConfig_ctor;
+extern jmethodID g_mid_NetworkInfo_ctor;
+extern jmethodID g_mid_RequestPropertyDataStatus_ctor;
+extern jmethodID g_mid_SecurityProvisioningStatus_ctor;
+extern jmethodID g_mid_DataProvisioningStatus_ctor;
extern jmethodID g_mid_CloudProvisioningStatus_ctor;
typedef void(*RemoveListenerCallback)(JNIEnv *env, jobject jListener);
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "JniProvisioningStatusListener.h"
-#include "JniRemoteEnrollee.h"
-
-using namespace OIC::Service;
-
-JniProvisioningStatusListener::JniProvisioningStatusListener(JNIEnv *env, jobject jListener,
- JniRemoteEnrollee *owner)
- : m_ownerResource(owner)
-{
- m_jwListener = env->NewWeakGlobalRef(jListener);
-}
-
-JniProvisioningStatusListener::~JniProvisioningStatusListener()
-{
- LOGI("~JniProvisioningStatusListener()");
- if (m_jwListener)
- {
- jint ret;
- JNIEnv *env = GetESJNIEnv(ret);
- if (NULL == env) return;
- env->DeleteWeakGlobalRef(m_jwListener);
- if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
- }
-}
-/*
-void JniProvisioningStatusListener::provisionStatusCallback (std::shared_ptr<EasySetupStatus>
- easySetupStatus)
-{
-
- LOGI("JniProvisioningStatusListener::provisioiningStatusCallback enter");
-
- jint ret;
- JNIEnv *env = GetESJNIEnv(ret);
- if (NULL == env) return;
- jobject jListener = env->NewLocalRef(m_jwListener);
- if (!jListener)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
- return;
- }
-
- jclass clsL = env->GetObjectClass(jListener);
- if (!clsL)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
- return;
- }
-
- jmethodID midL = env->GetMethodID(clsL, "onStatusRecieved",
- "(I)V");
- if (!midL)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
- return;
- }
-
- EasySetupState nativeProvisioningState = easySetupStatus->getEasySetupState();
- int provisionState = convertNativeProvisionStateToInt(nativeProvisioningState);
- env->CallVoidMethod(jListener, midL, provisionState);
- if (env->ExceptionCheck())
- {
- LOGE("Java exception is thrown");
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
- return;
- }
-
- if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-}
-
-void JniProvisioningStatusListener::checkExAndRemoveListener(JNIEnv *env)
-{
- if (env->ExceptionCheck())
- {
- jthrowable ex = env->ExceptionOccurred();
- env->ExceptionClear();
- m_ownerResource->removeProvisioningStatusListener(env, m_jwListener);
- env->Throw((jthrowable)ex);
- }
- else
- {
- m_ownerResource->removeProvisioningStatusListener(env, m_jwListener);
- }
-}
-*/
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-/** @file JniProvisioningStatusListener.h
- *
- * @brief This file contains JNI Provisioing status Listener class
- */
-
-#ifndef __JNI_ES_PROVISIONING_STATUS_LISTENER_H_
-#define __JNI_ES_PROVISIONING_STATUS_LISTENER_H_
-
-#include <jni.h>
-
-#include "RemoteEnrollee.h"
-#include "ESRichCommon.h"
-
-#include "JniJvm.h"
-
-class JniRemoteEnrollee;
-
-using namespace OIC::Service;
-
-/**
- * @class JniProvisioningStatusListener
- * @brief This class provides functions for handling the provisioning status callback between the Java and native layer
- *
- */
-class JniProvisioningStatusListener
-{
- public:
- /**
- * @brief constructor
- */
- JniProvisioningStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
-
- /**
- * @brief destructor
- */
- ~JniProvisioningStatusListener();
-
- /**
- * @brief callback function that will be passed to Native layer
- */
- //void provisionStatusCallback (std::shared_ptr<EasySetupStatus> easySetupStatus);
-
- private:
- jweak m_jwListener;
- JniRemoteEnrollee *m_ownerResource;
- void checkExAndRemoveListener(JNIEnv *env);
-};
-
-#endif //__JNI_ES_PROVISIONING_STATUS_LISTENER_H_
return remoteEnrollee;
}
-JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetCloudProvInfo
-(JNIEnv *env, jobject jClass, jstring jauthCode, jstring jauthProvider, jstring jciServer)
+void JniRemoteEnrollee::initRemoteEnrollee(JNIEnv *env)
{
- LOGD("nativeSetCloudProvInfo Enter");
+ try
+ {
+ m_sharedResource->initRemoteEnrollee();
+ }
+ catch (ESBadRequestException exception)
+ {
+ LOGE("JNI initRemoteEnrollee :: Exception occured");
+ //throw the exception to java
+ throwESException( env, exception.what());
+ }
+}
- // TODO
- JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
- remoteEnrollee->setCloudProvInfo(env, jauthCode, jauthProvider, jciServer);
+void JniRemoteEnrollee::requestPropertyData(JNIEnv *env, jobject jListener)
+{
+ JniRequestPropertyDataStatusListener *onRequestPropertyDataStatusReceived =
+ addStatusListener<JniRequestPropertyDataStatusListener>(env, jListener);
- LOGD("nativeSetCloudProvInfo Exit");
+ RequestPropertyDataStatusCb requestPropertyDataStatusCallback = [onRequestPropertyDataStatusReceived]
+ (std::shared_ptr<OIC::Service::RequestPropertyDataStatus > requestPropertyDataStatus)
+ {
+ onRequestPropertyDataStatusReceived->requestPropertyDataStatusCallback(requestPropertyDataStatus);
+ };
+
+ try
+ {
+ m_sharedResource->requestPropertyData(requestPropertyDataStatusCallback);
+ }
+ catch (ESBadRequestException exception)
+ {
+ LOGE("JNI requestPropertyData :: Exception occured");
+ //throw the exception to java
+ throwESException( env, exception.what());
+ }
}
-JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartCloudProvisioning
-(JNIEnv *env, jobject jClass, jobject jListener)
+void JniRemoteEnrollee::startSecurityProvisioning(JNIEnv *env, jobject jListener)
{
- LOGD("nativeStartCloudProvisioning Enter");
+ JniSecurityStatusListener *onSecurityProvStatusReceived =
+ addStatusListener<JniSecurityStatusListener>(env, jListener);
- JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
- remoteEnrollee->startCloudProvisioning(env, jListener);
+ SecurityProvStatusCb secProvStatusCallback = [onSecurityProvStatusReceived]
+ (std::shared_ptr<OIC::Service::SecProvisioningStatus > SecProvisioningStatus)
+ {
+ onSecurityProvStatusReceived->secProvisionStatusCallback(SecProvisioningStatus);
+ };
- LOGD("nativeStartCloudProvisioning Exit");
+ try
+ {
+ m_sharedResource->startSecurityProvisioning(secProvStatusCallback);
+ }
+ catch (ESBadRequestException exception)
+ {
+ LOGE("JNI startSecurityProvisioning :: Exception occured");
+ //throw the exception to java
+ throwESException( env, exception.what());
+ }
+}
+
+void JniRemoteEnrollee::startDataProvisioning(JNIEnv *env, jobject jListener)
+{
+ JniDataProvisioningStatusListener *onDataProvStatusReceived =
+ addStatusListener<JniDataProvisioningStatusListener>(env, jListener);
+
+ DataProvStatusCb dataProvStatusCallback = [onDataProvStatusReceived]
+ (std::shared_ptr<OIC::Service::DataProvisioningStatus > dataProvisioningStatus)
+ {
+ onDataProvStatusReceived->dataProvisionStatusCallback(dataProvisioningStatus);
+ };
+
+ try
+ {
+ m_sharedResource->startDataProvisioning(dataProvStatusCallback);
+ }
+ catch (ESBadRequestException exception)
+ {
+ LOGE("JNI startDataProvisioning :: Exception occured");
+ //throw the exception to java
+ throwESException( env, exception.what());
+ }
+}
+
+void JniRemoteEnrollee::setDataProvInfo(JNIEnv *env, jstring jssid, jstring jpwd, jint jauthType,
+ jint jencType, jstring jlanguage, jstring jcountry)
+{
+ DataProvInfo info;
+
+ info.WIFI.ssid = env->GetStringUTFChars(jssid, NULL);
+ info.WIFI.pwd = env->GetStringUTFChars(jpwd, NULL);
+ info.WIFI.authtype = getWifiAuthTypeFromInt(jauthType);
+ info.WIFI.enctype = getWifiEncTypeFromInt(jencType);
+ info.Device.language = env->GetStringUTFChars(jlanguage, NULL);
+ info.Device.country = env->GetStringUTFChars(jcountry, NULL);
+
+ m_sharedResource->setDataProvInfo(info);
}
void JniRemoteEnrollee::setCloudProvInfo(JNIEnv *env, jstring jauthCode, jstring jauthProvider, jstring jciServer)
void JniRemoteEnrollee::startCloudProvisioning(JNIEnv *env, jobject jListener)
{
- JniCloudProvisioningStatusListener *onCloudProvisioningStatusReceived = addCloudProvisioningStatusListener(env,
- jListener);
+ JniCloudProvisioningStatusListener *onCloudProvisioningStatusReceived =
+ addStatusListener<JniCloudProvisioningStatusListener>(env, jListener);
CloudProvStatusCb provisionStatusCallback = [onCloudProvisioningStatusReceived]
(std::shared_ptr< OIC::Service::CloudProvisioningStatus > cloudProvisioningStatus)
}
}
-JniCloudProvisioningStatusListener *JniRemoteEnrollee::addCloudProvisioningStatusListener(JNIEnv *env,
- jobject jListener)
+//JNI
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeInitRemoteEnrollee
+(JNIEnv *env, jobject jClass)
+{
+ LOGD("nativeInitRemoteEnrollee Enter");
+
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->initRemoteEnrollee(env);
+
+ LOGD("nativeInitRemoteEnrollee Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRequestPropertyData
+(JNIEnv *env, jobject jClass, jobject jListener)
+{
+ LOGD("nativeRequestPropertyData Enter");
+
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->requestPropertyData(env, jListener);
+
+ LOGD("nativeRequestPropertyData Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartSecurityProvision
+(JNIEnv *env, jobject jClass, jobject jListener)
+{
+ LOGD("nativeStartSecurityProvision Enter");
+
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->startSecurityProvisioning(env, jListener);
+
+ LOGD("nativeStartSecurityProvision Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartDataProvision
+(JNIEnv *env, jobject jClass, jobject jListener)
+{
+ LOGD("nativeStartDataProvision Enter");
+
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->startDataProvisioning(env, jListener);
+
+ LOGD("nativeStartDataProvision Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetDataProvInfo
+(JNIEnv *env, jobject jClass, jstring jssid, jstring jpwd, jint jauthType, jint jencType,
+ jstring jlanguage, jstring jcountry)
{
- return this->m_cloudProvisioningStatus.addListener(env, jListener, this);
+ LOGD("nativeSetDataProvInfo Enter");
+
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->setDataProvInfo(env, jssid, jpwd, jauthType, jencType, jlanguage, jcountry);
+
+ LOGD("nativeSetDataProvInfo Exit");
}
-void JniRemoteEnrollee::removeCloudProvisioningStatusListener(JNIEnv *env, jobject jListener)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetCloudProvInfo
+(JNIEnv *env, jobject jClass, jstring jauthCode, jstring jauthProvider, jstring jciServer)
{
- this->m_cloudProvisioningStatus.removeListener(env, jListener);
+ LOGD("nativeSetCloudProvInfo Enter");
+
+ // TODO
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->setCloudProvInfo(env, jauthCode, jauthProvider, jciServer);
+
+ LOGD("nativeSetCloudProvInfo Exit");
}
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartCloudProvisioning
+(JNIEnv *env, jobject jClass, jobject jListener)
+{
+ LOGD("nativeStartCloudProvisioning Enter");
+
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->startCloudProvisioning(env, jListener);
+
+ LOGD("nativeStartCloudProvisioning Exit");
+}
\ No newline at end of file
#include "JniJvm.h"
#include "JniEsUtils.h"
-#include "JniProvisioningStatusListener.h"
+#include "JniRequestPropertyDataStatusListener.h"
+#include "JniSecurityStatusListener.h"
+#include "JniDataProvisioningStatusListener.h"
#include "JniCloudProvisioningStatusListener.h"
#include "JniEsListenerManager.h"
~JniRemoteEnrollee();
// ***** JNI APIs internally call the APIs of this class ***** //
-
- void setCloudProvInfo(JNIEnv *env, jstring authCode, jstring authProvider, jstring ciServer);
-
+ void initRemoteEnrollee(JNIEnv *env);
+ void requestPropertyData(JNIEnv *env, jobject jListener);
+ void startSecurityProvisioning(JNIEnv *env, jobject jListener);
+ void startDataProvisioning(JNIEnv *env, jobject jListener);
void startCloudProvisioning(JNIEnv *env, jobject jListener);
+ void setDataProvInfo(JNIEnv *env, jstring jssid, jstring jpwd, jint jauthType,
+ jint jencType, jstring jlanguage, jstring jcountry);
+ void setCloudProvInfo(JNIEnv *env, jstring authCode, jstring authProvider, jstring ciServer);
static JniRemoteEnrollee *getJniRemoteEnrollee(JNIEnv *env, jobject thiz);
- JniCloudProvisioningStatusListener *addCloudProvisioningStatusListener(JNIEnv *env, jobject jListener);
- void removeCloudProvisioningStatusListener(JNIEnv *env, jobject jListener);
+ template <class T>
+ T *addStatusListener(JNIEnv *env, jobject jListener)
+ {
+ return JniEsListenerManager<T>().addListener(env, jListener, this);
+ };
+
+ template <class T>
+ void removeStatusListener(JNIEnv *env, jobject jListener)
+ {
+ JniEsListenerManager<T>().removeListener(env, jListener);
+ };
private:
- void registerCloudProvisioningHandler(JNIEnv *env, jobject jListener);
- JniEsListenerManager<JniCloudProvisioningStatusListener> m_cloudProvisioningStatus;
std::shared_ptr<RemoteEnrollee> m_sharedResource;
};
#endif
/**
- * API for setting cloud provisioning information.
+ * API for starting the initRemoteEnrollee process.
*/
JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetCloudProvInfo
-(JNIEnv *env, jobject jClass, jstring jauthCode, jstring jauthProvider, jstring jciServer);
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeInitRemoteEnrollee
+(JNIEnv *env, jobject jClass);
/**
- * API for starting the cloud provisioning process.
+ * API for starting the Request PropertyData process.
*/
JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartCloudProvisioning
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRequestPropertyData
(JNIEnv *env, jobject jClass, jobject jListener);
/**
- * API for starting the provisioning process.
+ * API for starting the Sequrity provisioning process.
*/
-//JNIEXPORT void JNICALL
-//Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartProvision
-//(JNIEnv *env, jobject jClass);
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartSecurityProvision
+(JNIEnv *env, jobject jClass, jobject jListener);
/**
- * API for stopping the provisioning process.
+ * API for starting the Data provisioning process.
*/
-//JNIEXPORT void JNICALL
-//Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStopProvision
-//(JNIEnv *env, jobject jClass);
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartDataProvision
+(JNIEnv *env, jobject jClass);
/**
- * API for setting the lisener for recieiving provisioning status.
- *
- * @param provisiongListener - Provisioning listener [callback from native layer will be passing to this listener]
+ * API for setting data provisioning information.
*/
-//JNIEXPORT void JNICALL
-//Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRegisterProvisioningHandler
-//(JNIEnv *env, jobject jClass, jobject provisiongListener);
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetDataProvInfo
+(JNIEnv *env, jobject jClass, jstring jssid, jstring jpwd, jint jauthType, jint jencType,
+ jstring jlanguage, jstring jcountry);
+
+/**
+ * API for setting cloud provisioning information.
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetCloudProvInfo
+(JNIEnv *env, jobject jClass, jstring jauthCode, jstring jauthProvider, jstring jciServer);
+
+/**
+ * API for starting the cloud provisioning process.
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartCloudProvisioning
+(JNIEnv *env, jobject jClass, jobject jListener);
#ifdef __cplusplus
}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "JniRequestPropertyDataStatusListener.h"
+#include "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniRequestPropertyDataStatusListener::JniRequestPropertyDataStatusListener(JNIEnv *env, jobject jListener,
+ JniRemoteEnrollee *owner)
+ : m_ownerResource(owner)
+{
+ m_jwListener = env->NewWeakGlobalRef(jListener);
+}
+
+JniRequestPropertyDataStatusListener::~JniRequestPropertyDataStatusListener()
+{
+ LOGI("~JniRequestPropertyDataStatusListener()");
+ if (m_jwListener)
+ {
+ jint ret;
+ JNIEnv *env = GetESJNIEnv(ret);
+ if (NULL == env) return;
+ env->DeleteWeakGlobalRef(m_jwListener);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ }
+}
+
+void JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback (
+ std::shared_ptr<RequestPropertyDataStatus> requestPropertyDataStatusCb)
+{
+ LOGI("JniRequestPropertyDataStatusListener::provisioiningStatusCallback enter");
+
+ jint ret;
+ JNIEnv *env = GetESJNIEnv(ret);
+ if (NULL == env) return;
+ jobject jListener = env->NewLocalRef(m_jwListener);
+ if (!jListener)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ jclass clsL = env->GetObjectClass(jListener);
+ if (!clsL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ jmethodID midL = env->GetMethodID(clsL, "onProgress",
+ "(Lorg/iotivity/service/easysetup/mediator/"
+ "RequestPropertyDataStatus;"
+ ")V");
+
+ if (!midL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ const PropertyData propertyData = requestPropertyDataStatusCb->getPropertyData();
+ DeviceConfig devConf = propertyData.getDevConf();
+ NetworkInfo netInfo = propertyData.getNetInfo();
+
+ jobject jDevConf = NULL;
+ jDevConf = env->NewObject(g_cls_DeviceConfig,
+ g_mid_DeviceConfig_ctor,
+ (jstring)env->NewStringUTF(devConf.id.c_str()),
+ (jstring)env->NewStringUTF(devConf.name.c_str()),
+ (jstring)env->NewStringUTF(devConf.language.c_str()),
+ (jstring)env->NewStringUTF(devConf.country.c_str()));
+
+ jclass clazz = (*env).FindClass("java/util/ArrayList");
+ jobject wifiModeTypes = (*env).NewObject(clazz, (*env).GetMethodID(clazz, "<init>", "()V"));
+
+ for (int n=0; n<netInfo.types.size(); n++)
+ {
+ (*env).CallBooleanMethod(wifiModeTypes, (*env).GetMethodID(clazz, "add", "(java/lang/Object;)Z"),
+ convertNativeWifiModeToInt(static_cast<WIFI_MODE>(netInfo.types[n])));
+ }
+
+ jobject jNetInfo = NULL;
+ jNetInfo = env->NewObject(g_cls_NetworkInfo,
+ g_mid_NetworkInfo_ctor,
+ (jobject)wifiModeTypes,
+ (jint)convertNativeWifiFreqToInt(netInfo.freq));
+
+ jobject jPropertyData = NULL;
+ jPropertyData = env->NewObject(g_cls_PropertyData,
+ g_mid_PropertyData_ctor,
+ (jobject)jDevConf,
+ (jobject)jNetInfo,
+ (jboolean)propertyData.isCloudable());
+
+ jobject jRequestPropertyDataStatus = NULL;
+ jRequestPropertyDataStatus = env->NewObject(g_cls_RequestPropertyDataStatus,
+ g_mid_RequestPropertyDataStatus_ctor,
+ convertNativeDataProvResultToInt(requestPropertyDataStatusCb->getESResult()),
+ (jobject)jPropertyData);
+
+ if (!jRequestPropertyDataStatus)
+ {
+ LOGE("JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback Unable to create the java object");
+ return ;
+ }
+
+ env->CallVoidMethod(jListener, midL, jRequestPropertyDataStatus);
+
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniRequestPropertyDataStatusListener::checkExAndRemoveListener(JNIEnv *env)
+{
+ if (env->ExceptionCheck())
+ {
+ jthrowable ex = env->ExceptionOccurred();
+ env->ExceptionClear();
+ m_ownerResource->removeStatusListener<JniRequestPropertyDataStatusListener>(env, m_jwListener);
+
+ env->Throw((jthrowable)ex);
+ }
+ else
+ {
+ m_ownerResource->removeStatusListener<JniRequestPropertyDataStatusListener>(env, m_jwListener);
+ }
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef __JNI_ES_REQUEST_PROPERTY_DATA_STATUS_LISTENER_H_
+#define __JNI_ES_REQUEST_PROPERTY_DATA_STATUS_LISTENER_H_
+
+#include <jni.h>
+
+#include "RemoteEnrollee.h"
+#include "ESRichCommon.h"
+
+#include "JniJvm.h"
+
+class JniRemoteEnrollee;
+
+using namespace OIC::Service;
+
+class JniRequestPropertyDataStatusListener
+{
+ public:
+ /**
+ * @brief constructor
+ */
+ JniRequestPropertyDataStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+
+ /**
+ * @brief destructor
+ */
+ ~JniRequestPropertyDataStatusListener();
+
+ /**
+ * @brief callback function that will be passed to Native layer
+ */
+ void requestPropertyDataStatusCallback (std::shared_ptr<RequestPropertyDataStatus> requestPropertyDataStatus);
+
+ private:
+ jweak m_jwListener;
+ JniRemoteEnrollee *m_ownerResource;
+ void checkExAndRemoveListener(JNIEnv *env);
+};
+
+#endif //__JNI_ES_REQUEST_PROPERTY_DATA_STATUS_LISTENER_H_
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "JniSecurityStatusListener.h"
+#include "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniSecurityStatusListener::JniSecurityStatusListener(JNIEnv *env, jobject jListener,
+ JniRemoteEnrollee *owner)
+ : m_ownerResource(owner)
+{
+ m_jwListener = env->NewWeakGlobalRef(jListener);
+}
+
+JniSecurityStatusListener::~JniSecurityStatusListener()
+{
+ LOGI("~JniSecurityStatusListener()");
+ if (m_jwListener)
+ {
+ jint ret;
+ JNIEnv *env = GetESJNIEnv(ret);
+ if (NULL == env) return;
+ env->DeleteWeakGlobalRef(m_jwListener);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ }
+}
+void JniSecurityStatusListener::secProvisionStatusCallback(
+ std::shared_ptr<SecProvisioningStatus> secProvisioningStatus)
+{
+
+ LOGI("JniSecurityStatusListener::secProvisionStatusCallback enter");
+
+ jint ret;
+ JNIEnv *env = GetESJNIEnv(ret);
+ if (NULL == env) return;
+ jobject jListener = env->NewLocalRef(m_jwListener);
+ if (!jListener)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ jclass clsL = env->GetObjectClass(jListener);
+ if (!clsL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ jmethodID midL = env->GetMethodID(clsL, "onProgress",
+ "(Lorg/iotivity/service/easysetup/mediator/"
+ "SecurityProvisioningStatus;"
+ ")V");
+
+ if (!midL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ ESResult esResult = secProvisioningStatus->getESResult();
+
+ //create the java object
+ jobject jSecurityProvisioningStatus = NULL;
+ jSecurityProvisioningStatus = env->NewObject(g_cls_SecurityProvisioningStatus,
+ g_mid_SecurityProvisioningStatus_ctor,
+ (jint)esResult,
+ (jstring)env->NewStringUTF(secProvisioningStatus->getDeviceUUID().c_str()));
+
+ if (!jSecurityProvisioningStatus)
+ {
+ LOGE("JniSecurityStatusListener::onSecurityProvisioningStatus Unable to create the java object");
+ return ;
+ }
+
+ env->CallVoidMethod(jListener, midL, jSecurityProvisioningStatus);
+
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniSecurityStatusListener::checkExAndRemoveListener(JNIEnv *env)
+{
+ if (env->ExceptionCheck())
+ {
+ jthrowable ex = env->ExceptionOccurred();
+ env->ExceptionClear();
+ m_ownerResource->removeStatusListener<JniSecurityStatusListener>(env, m_jwListener);
+ env->Throw((jthrowable)ex);
+ }
+ else
+ {
+ m_ownerResource->removeStatusListener<JniSecurityStatusListener>(env, m_jwListener);
+ }
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef __JNI_ES_SECURITY_PROVISIONING_STATUS_LISTENER_H_
+#define __JNI_ES_SECURITY_PROVISIONING_STATUS_LISTENER_H_
+
+#include <jni.h>
+
+#include "RemoteEnrollee.h"
+#include "ESRichCommon.h"
+
+#include "JniJvm.h"
+
+class JniRemoteEnrollee;
+
+using namespace OIC::Service;
+
+class JniSecurityStatusListener
+{
+ public:
+ /**
+ * @brief constructor
+ */
+ JniSecurityStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+
+ /**
+ * @brief destructor
+ */
+ ~JniSecurityStatusListener();
+
+ /**
+ * @brief callback function that will be passed to Native layer
+ */
+ void secProvisionStatusCallback (std::shared_ptr<SecProvisioningStatus> secProvisioningStatus);
+
+ private:
+ jweak m_jwListener;
+ JniRemoteEnrollee *m_ownerResource;
+ void checkExAndRemoveListener(JNIEnv *env);
+};
+
+#endif //__JNI_ES_SECURITY_PROVISIONING_STATUS_LISTENER_H_
typedef enum
{
- WiFi_11A = 0,
- WiFi_11B,
- WiFi_11G,
- WiFi_11N,
- WiFi_11AC
+ WIFI_11A = 0,
+ WIFI_11B,
+ WIFI_11G,
+ WIFI_11N,
+ WIFI_11AC
} WIFI_MODE;
typedef struct
ES_NEED_PROVISIONING,
ES_PROVISIONED_ALREADY,
ES_PROVISIONING_SUCCESS
- } ESState;
+ } ESDataProvState;
typedef enum
{
return m_devUUID;
}
- ESResult getResult()
+ ESResult getESResult()
{
return m_result;
}
{
}
- const DeviceConfig getDevInfo()
+ const DeviceConfig& getDevConf() const
{
return m_devConfig;
}
- const NetworkInfo getNetInfo()
+ const NetworkInfo& getNetInfo() const
{
return m_netInfo;
}
- bool isCloudable()
+ const bool isCloudable() const
{
return m_cloudable;
}
{
public:
RequestPropertyDataStatus(ESResult result, const PropertyData& data) :
- m_result(result), m_PropertyData(data)
+ m_result(result), m_propertyData(data)
{
}
return m_result;
}
- const PropertyData getPropertyData()
+ const PropertyData& getPropertyData()
{
- return m_PropertyData;
+ return m_propertyData;
}
private:
ESResult m_result;
- PropertyData m_PropertyData;
+ PropertyData m_propertyData;
};
class DataProvisioningStatus
{
public:
- DataProvisioningStatus(ESResult result, ESState esState) :
- m_result(result), m_esState(esState)
+ DataProvisioningStatus(ESResult result, ESDataProvState dataProvState) :
+ m_result(result), m_state(dataProvState)
{
}
return m_result;
}
- ESState getESState()
+ ESDataProvState getESDataProvState()
{
- return m_esState;
+ return m_state;
}
private:
ESResult m_result;
- ESState m_esState;
+ ESDataProvState m_state;
};
class CloudProvisioningStatus
/**
* Callback function definition for providing Enrollee security status .
*/
- typedef function< void(shared_ptr<SecProvisioningStatus>) > EnrolleeSecStatusCb;
+ typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
/**
* Callback definition to be invoked when the security stack expects a pin from application.
public:
EnrolleeSecurity(std::shared_ptr< EnrolleeResource > EnrolleeResource,
std::string secDbPath);
- ESResult registerCallbackHandler(EnrolleeSecStatusCb enrolleeSecStatusCb,
+ ESResult registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb);
bool performOwnershipTransfer();
private:
std::shared_ptr< EnrolleeResource > m_EnrolleeResource;
- EnrolleeSecStatusCb m_enrolleeSecStatusCb;
+ SecurityProvStatusCb m_securityProvStatusCb;
SecurityPinCb m_securityPinCb;
SecProvisioningDbPathCb m_secProvisioningDbPathCb;
std::shared_ptr< OC::OCSecureResource > m_unownedDevice;
*
* @see RemoteEnrollee
*/
- void startSecurityProvisioning(EnrolleeSecStatusCb callback);
+ void startSecurityProvisioning(SecurityProvStatusCb callback);
/**
* Start provisioning of target Enrollers information to the Enrollee.
void RequestPropertyDataStatusHandler (std::shared_ptr< RequestPropertyDataStatus > status);
void dataProvisioningStatusHandler (std::shared_ptr< DataProvisioningStatus > status);
void cloudProvisioningStatusHandler (std::shared_ptr< CloudProvisioningStatus > status);
- void easySetupSecurityStatusCallback(std::shared_ptr< SecProvisioningStatus > status);
+ void securityStatusHandler(std::shared_ptr< SecProvisioningStatus > status);
private:
std::shared_ptr< OC::OCResource > m_ocResource;
std::string m_deviceId;
bool m_discoveryResponse;
- EnrolleeSecStatusCb m_enrolleeSecStatusCb;
- RequestPropertyDataStatusCb m_RequestPropertyDataStatusCb;
+ SecurityProvStatusCb m_securityProvStatusCb;
+ RequestPropertyDataStatusCb m_requestPropertyDataStatusCb;
SecurityPinCb m_securityPinCb;
SecProvisioningDbPathCb m_secProvisioningDbPathCb;
DataProvStatusCb m_dataProvStatusCb;
OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
"checkProvInformationCb : Provisioning is failed ");
std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
- DataProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
+ DataProvisioningStatus >(ESResult::ES_ERROR, ESDataProvState::ES_PROVISIONING_ERROR);
m_dataProvStatusCb(provStatus);
return;
}
"Now trigger network connection ");
std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
- DataProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
+ DataProvisioningStatus >(ESResult::ES_OK, ESDataProvState::ES_PROVISIONING_SUCCESS);
m_dataProvStatusCb(provStatus);
}
result = ESResult::ES_UNAUTHORIZED;
}
std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
- DataProvisioningStatus >(result, ESState::ES_PROVISIONING_ERROR);
+ DataProvisioningStatus >(result, ESDataProvState::ES_PROVISIONING_ERROR);
m_dataProvStatusCb(provStatus);
return;
OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
"getProvStatusResponse : Provisioning is successful");
std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
- DataProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONED_ALREADY);
+ DataProvisioningStatus >(ESResult::ES_OK, ESDataProvState::ES_PROVISIONED_ALREADY);
m_dataProvStatusCb(provStatus);
}
}
if (result != OCStackResult::OC_STACK_OK)
{
std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
- DataProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
+ DataProvisioningStatus >(ESResult::ES_ERROR, ESDataProvState::ES_PROVISIONING_ERROR);
m_dataProvStatusCb(provStatus);
return;
}
m_EnrolleeResource = EnrolleeResource;
}
- ESResult EnrolleeSecurity::registerCallbackHandler(EnrolleeSecStatusCb enrolleeSecStatusCb,
+ ESResult EnrolleeSecurity::registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb)
{
- m_enrolleeSecStatusCb = enrolleeSecStatusCb;
+ m_securityProvStatusCb = securityProvStatusCb;
m_securityPinCb = securityPinCb;
m_secProvisioningDbPathCb = secProvisioningDbPathCb;
securityProvisioningStatus = std::make_shared< SecProvisioningStatus >(uuid,
ES_ERROR);
- m_enrolleeSecStatusCb(securityProvisioningStatus);
+ m_securityProvStatusCb(securityProvisioningStatus);
return;
}
else
securityProvisioningStatus = std::make_shared< SecProvisioningStatus >(uuid,
ES_OK);
- m_enrolleeSecStatusCb(securityProvisioningStatus);
+ m_securityProvStatusCb(securityProvisioningStatus);
return;
}
RemoteEnrollee::RemoteEnrollee()
{
- m_enrolleeSecStatusCb = nullptr;
- m_RequestPropertyDataStatusCb = nullptr;
+ m_securityProvStatusCb = nullptr;
+ m_requestPropertyDataStatusCb = nullptr;
m_securityPinCb = nullptr;
m_secProvisioningDbPathCb = nullptr;
m_dataProvStatusCb = nullptr;
}
#endif //__WITH_DTLS__
- void RemoteEnrollee::easySetupSecurityStatusCallback(
+ void RemoteEnrollee::securityStatusHandler(
std::shared_ptr< SecProvisioningStatus > status)
{
OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "easySetupStatusCallback status is, UUID = %s, "
"Status = %d", status->getDeviceUUID().c_str(),
- status->getResult());
+ status->getESResult());
- if(status->getResult() == ES_OK)
+ if(status->getESResult() == ES_OK)
{
OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are successful. "
"Continue with Network information provisioning");
OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
- m_enrolleeSecStatusCb(status);
+ m_securityProvStatusCb(status);
}
else
{
OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are fail");
- m_enrolleeSecStatusCb(status);
+ m_securityProvStatusCb(status);
}
}
m_propertyData = status->getPropertyData();
}
- m_RequestPropertyDataStatusCb(status);
+ m_requestPropertyDataStatusCb(status);
}
void RemoteEnrollee::dataProvisioningStatusHandler(
if (status->getESResult() == ES_OK)
{
- if (status->getESState() >= ESState::ES_PROVISIONED_ALREADY)
+ if (status->getESDataProvState() >= ESDataProvState::ES_PROVISIONED_ALREADY)
{
OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", status->getESResult());
}
}
}
- void RemoteEnrollee::startSecurityProvisioning(EnrolleeSecStatusCb callback)
+ void RemoteEnrollee::startSecurityProvisioning(SecurityProvStatusCb callback)
{
#ifdef __WITH_DTLS__
- m_enrolleeSecStatusCb = callback;
+ m_securityProvStatusCb = callback;
- EnrolleeSecStatusCb securityProvStatusCb = std::bind(
- &RemoteEnrollee::easySetupSecurityStatusCallback,
+ SecurityProvStatusCb securityProvStatusCb = std::bind(
+ &RemoteEnrollee::securityStatusHandler,
this,
std::placeholders::_1);
//TODO : DBPath is passed empty as of now. Need to take dbpath from application.
OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Fail performOwnershipTransfer");
std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
std::make_shared< SecProvisioningStatus >(nullptr, ES_ERROR);
- m_enrolleeSecStatusCb(securityProvisioningStatus);
+ m_securityProvStatusCb(securityProvisioningStatus);
return;
}
}
std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
std::make_shared< SecProvisioningStatus >(nullptr, ES_ERROR);
- m_enrolleeSecStatusCb(securityProvisioningStatus);
+ m_securityProvStatusCb(securityProvisioningStatus);
#endif
}
throw ESInvalidParameterException("Callback is empty");
}
- m_RequestPropertyDataStatusCb = callback;
+ m_requestPropertyDataStatusCb = callback;
if (m_enrolleeResource == nullptr)
{
void printPropertyData(PropertyData propData)
{
cout << "===========================================" << endl;
- DeviceConfig devConfig = propData.getDevInfo();
+ DeviceConfig devConfig = propData.getDevConf();
NetworkInfo netInfo = propData.getNetInfo();
bool cloudable = propData.isCloudable();
else
{
cout << "dataProvisioningStatusCallback is success." << endl;
- cout << "ESState : " << provStatus->getESState() << endl;
+ cout << "ESDataProvState : " << provStatus->getESDataProvState() << endl;
}
}