1. Implement startCloudProvisioning for Android and nativeStartCloudProvisioning
for its JNI layer
2. Implement CloudProvisioningStatusListener class for callback listener for
cloud provisioning
3. Implement CloudProvInfo class to store an cloud information to be delivered
to Enrollee
Change-Id: Iafdfa71dd642f99dc6b5b8f0de1f60f5255fea66
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8797
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
--- /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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This class contains on cloud provisioning information.
+ * It implements ProvisioningInfo interface and provide configuration object specific to cloud registration
+ */
+public class CloudProvInfo {
+
+ private final String mAuthCode;
+ private final String mAuthProvider;
+ private final String mCiServer;
+
+ public CloudProvInfo(String authCode, String authProvider, String ciServer) {
+ mAuthCode = authCode;
+ mAuthProvider = authProvider;
+ mCiServer = ciServer;
+ }
+
+ /**
+ * This method returns the authCode used for the first registration to IoTivity cloud
+ * @return AuthCode for sign-up to IoTivity cloud
+ */
+ public String getAuthCode() {
+ return mAuthCode;
+ }
+
+ /**
+ * This method returns the auth provider which issued the given AuthCode
+ * @return Auth provider which issued the given AuthCode
+ */
+ public String getAuthProvider() {
+ return mAuthProvider;
+ }
+
+ /**
+ * This method returns the Cloud Interface server's URL to be registered
+ * @return CI server's URL to be registered
+ */
+ public String getCiServer() {
+ return mCiServer;
+ }
+}
--- /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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import org.iotivity.service.easysetup.mediator.CloudProvisioningStatus;
+
+public abstract class CloudProvisioningCallback {
+ public abstract void onProgress(CloudProvisioningStatus status);
+}
+
--- /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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This interface facilitates Application to get progress & result of Cloud provisioning
+ * process in easy setup
+ */
+public class CloudProvisioningStatus
+{
+ private ESResult m_result;
+ private ESCloudProvState m_esCloudState;
+
+ public CloudProvisioningStatus(int result, int state)
+ {
+ m_result = ESResult.fromInt(result);
+ m_esCloudState = ESCloudProvState.fromInt(state);
+ }
+
+ public ESResult getESResult()
+ {
+ return m_result;
+ }
+
+ public ESCloudProvState getESCloudState()
+ {
+ return m_esCloudState;
+ }
+};
--- /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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * It defines various states of the cloud provisioning during easy setup process
+ */
+public enum ESCloudProvState {
+
+ /**
+ * Some error occurs during cloud data provisioning
+ */
+ ES_CLOUD_PROVISIONING_ERROR(-1),
+
+ /**
+ * Cloud data provisioning is successfully done
+ */
+ ES_CLOUD_PROVISIONING_SUCCESS(0),
+
+ /**
+ * Target enrollee which needs a cloud provisioning is found in a network
+ */
+ ES_CLOUD_ENROLLEE_FOUND(1),
+
+ /**
+ * Target enrollee which needs a cloud provisioning is NOT found in a network
+ */
+ ES_CLOUD_ENROLLEE_NOT_FOUND(2);
+
+ private int value;
+
+ private ESCloudProvState(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public static ESCloudProvState fromInt(int i) {
+ for (ESCloudProvState b : ESCloudProvState.values()) {
+ if (b.getValue() == i) { return b; }
+ }
+ return null;
+ }
+};
+
--- /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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * It defines an result during easy setup process, which is same as one in Easy Setup C++ SDK
+ */
+public enum ESResult {
+ ES_ERROR(-1),
+ ES_OK(0),
+ ES_NETWORKFOUND(1),
+ ES_NETWORKCONNECTED(2),
+ ES_NETWORKNOTCONNECTED(3),
+ ES_RESOURCECREATED(11),
+ ES_RECVREQOFPROVRES(21),
+ ES_RECVREQOFNETRES(22),
+ ES_RECVUPDATEOFPROVRES(23),
+ ES_RECVTRIGGEROFPROVRES(24),
+ ES_UNAUTHORIZED(25);
+
+ private int value;
+
+ private ESResult(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public static ESResult fromInt(int i) {
+ for (ESResult b : ESResult.values()) {
+ if (b.getValue() == i) { return b; }
+ }
+ return null;
+ }
+};
\ No newline at end of file
import java.util.ArrayList;
/**
+ * <To be modified>
* This is facade class, a single point of contact for Application.
* It contains set of APIs to do easy setup of the enrolling device.
* ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.
private static EasySetup sInstance;
- //private final EasySetupStatus mCallback;
-
- //private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;
-
- //private final ProvisioningCallback mProvisioningCallback;
-
private static Context mContext;
- private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
+ private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
protected RemoteEnrollee mRemoteEnrollee;
- //function to call the native createEnrolleeDevice
+ //function to call the native nativeCreateRemoteEnrollee
private native RemoteEnrollee nativeCreateRemoteEnrollee();
static {
}
private EasySetup() {
- //mCallback = callback;
- //mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);
- //mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();
+ mRemoteEnrolleeList = new ArrayList<RemoteEnrollee>();
mContext = null;
}
/**
- * Gives a singleton instance of Easy setup service and initialize the service
- *
- * @param callback Application needs to provide this callback to receive the status of easy
- * setup process.
+ * Gives a singleton instance of Easy setup and initialize the easy setup
*/
-
public synchronized static EasySetup getInstance(Context context) {
if (sInstance == null) {
sInstance = new EasySetup();
return sInstance;
}
- public synchronized RemoteEnrollee createRemoteEnrollee()
- {
- // native call
- mRemoteEnrollee = nativeCreateRemoteEnrollee();
-
- mRemoteEnrolleeList.add(mRemoteEnrollee);
-
+ /**
+ * API to create a new RemoteEnrollee instance
+ */
+ public synchronized RemoteEnrollee createRemoteEnrollee()
+ {
+ // native call
+ mRemoteEnrollee = nativeCreateRemoteEnrollee();
+ mRemoteEnrolleeList.add(mRemoteEnrollee);
return mRemoteEnrollee;
- }
+ }
/**
- * Reset the Easy setup Service
+ * Reset the Easy setup
*/
-
public void finish() {
- //Call the stop Provisioning
- //for (EnrolleeDevice enrolleeDevice : mEnrolleeDeviceList) {
- // enrolleeDevice.stopProvisioningProcess();
- //}
- }
+ //Call the stop Provisioning
+ //for (RemoteEnrollee remoteEnrollee : mRemoteEnrolleeList)
+ // remoteEnrollee.stopProvisioningProcess();
+ }
}
public static final String TAG = RemoteEnrollee.class.getName();
private long m_nativeHandle;
- //private native void nativeStartProvision();
- //private native void nativeStopProvision();
- //private native void nativeRegisterProvisioningHandler(IProvisionStatusNativeHandler listener);
+ private native void nativeSetCloudProvInfo(String authCode, String autoProvider, String ciServer);
+ private native void nativeStartCloudProvisioning(CloudProvisioningCallback callback);
/* constructor will be invoked from the native layer */
private RemoteEnrollee(long nativeHandle){
this.m_nativeHandle = nativeHandle;
}
- /* Register native Listener for the Provisioning state */
- //public void registerProvisioningHandler( IProvisionStatusNativeHandler provisioningListener) throws ESException{
- // // this.provisioningListener = provisioningListener;
- // nativeRegisterProvisioningHandler(provisioningListener);
- // Log.i(TAG, "JNI Callback is registered for getting provisioning status");
- //}
-
- ///* native StartProvision */
- //public void startProvision() throws ESException{
- //nativeStartProvision();
- //}
-
- /* native stopProvision */
- //public void stopProvision() throws ESException{
- //nativeStopProvision();
- //}
-
+ /* native setCloudProvInfo */
+ public void setCloudProvInfo(CloudProvInfo cloudInfo) throws ESException{
+ nativeSetCloudProvInfo(cloudInfo.getAuthCode(), cloudInfo.getAuthProvider(), cloudInfo.getCiServer());
+ }
+
+ /* native startCloudProvisioning */
+ public void startCloudProvisioning(CloudProvisioningCallback callback) throws ESException{
+ if(callback != null)
+ {
+ nativeStartCloudProvisioning(callback);
+ return;
+ }
+ Log.d(TAG, "CloudProvisioningCallback is null ");
+ }
}
--- /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 "JniCloudProvisioningStatusListener.h"
+#include "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniCloudProvisioningStatusListener::JniCloudProvisioningStatusListener(JNIEnv *env, jobject jListener,
+ JniRemoteEnrollee *owner)
+ : m_ownerResource(owner)
+{
+ m_jwListener = env->NewWeakGlobalRef(jListener);
+}
+
+JniCloudProvisioningStatusListener::~JniCloudProvisioningStatusListener()
+{
+ LOGI("~JniCloudProvisioningStatusListener()");
+ 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 JniCloudProvisioningStatusListener::onCloudProvisioningStatus(std::shared_ptr<CloudProvisioningStatus>
+ cloudProvisioningStatus)
+{
+
+ LOGI("JniCloudProvisioningStatusListener::onCloudProvisioningStatus 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/"
+ "CloudProvisioningStatus;"
+ ")V");
+ if (!midL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ ESResult esResult = cloudProvisioningStatus->getESResult();
+ ESCloudProvState cloudProvisionState = cloudProvisioningStatus->getESCloudState();
+
+ //create the java object
+ jobject jCloudProvisioningStatus = NULL;
+ jCloudProvisioningStatus = env->NewObject(g_cls_CloudProvisioningStatus,
+ g_mid_CloudProvisioningStatus_ctor,
+ (jint)esResult,
+ (jint)cloudProvisionState);
+
+ LOGI("JniCloudProvisioningStatus::onCloudProvisioningStatus - %d, %d", esResult, cloudProvisionState);
+ if (!jCloudProvisioningStatus)
+ {
+ LOGE("JniCloudProvisioningStatus::onCloudProvisioningStatus Unable to create the java object");
+ return ;
+ }
+
+ env->CallVoidMethod(jListener, midL, jCloudProvisioningStatus);
+
+ bool needRemoveListener = false;
+
+ if(cloudProvisionState == ES_CLOUD_PROVISIONING_ERROR ||
+ cloudProvisionState == ES_CLOUD_PROVISIONING_SUCCESS )
+ {
+ needRemoveListener = true;
+ }
+
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ if(needRemoveListener)
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return;
+ }
+
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniCloudProvisioningStatusListener::checkExAndRemoveListener(JNIEnv *env)
+{
+ if (env->ExceptionCheck())
+ {
+ jthrowable ex = env->ExceptionOccurred();
+ env->ExceptionClear();
+ m_ownerResource->removeCloudProvisioningStatusListener(env, m_jwListener);
+ env->Throw((jthrowable)ex);
+ }
+ else
+ {
+ m_ownerResource->removeCloudProvisioningStatusListener(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_CLOUD_PROVISIONING_STATUS_LISTENER_H_
+#define __JNI_ES_CLOUD_PROVISIONING_STATUS_LISTENER_H_
+
+#include <jni.h>
+
+#include "RemoteEnrollee.h"
+#include "ESRichCommon.h"
+
+#include "JniJvm.h"
+
+class JniRemoteEnrollee;
+
+using namespace OIC::Service;
+
+/**
+ * @class JniCloudProvisioningStatusListener
+ * @brief This class provides functions for handling the cloud provisioning status callback between the Java and native layer
+ *
+ */
+class JniCloudProvisioningStatusListener
+{
+ public:
+ /**
+ * @brief constructor
+ */
+ JniCloudProvisioningStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+
+ /**
+ * @brief destructor
+ */
+ ~JniCloudProvisioningStatusListener();
+
+ /**
+ * @brief callback function that will be passed to Native layer
+ */
+ void onCloudProvisioningStatus (std::shared_ptr<CloudProvisioningStatus> cloudProvisioningStatus);
+
+ private:
+ jweak m_jwListener;
+ JniRemoteEnrollee *m_ownerResource;
+ void checkExAndRemoveListener(JNIEnv *env);
+};
+
+#endif //__JNI_ES_PROVISIONING_STATUS_LISTENER_H_
+
extern "C" {
#endif
JNIEXPORT jobject JNICALL
-Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateRemoteEnrollee
+Java_org_iotivity_service_easysetup_mediator_EasySetup_nativeCreateRemoteEnrollee
(JNIEnv *env, jobject interfaceClass)
{
* @return jobject - RemoteEnrolleee
*/
JNIEXPORT jobject JNICALL
-Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateRemoteEnrollee
+Java_org_iotivity_service_easysetup_mediator_EasySetup_nativeCreateRemoteEnrollee
(JNIEnv *env, jobject interfaceClass);
#ifdef __cplusplus
}
return CT_DEFAULT;
}
-/*
-int convertNativeProvisionStateToInt(EasySetupState nativeState)
-{
- switch (nativeState)
- {
- case EasySetupState::DEVICE_PROVISIONED:
- return 0;
- case EasySetupState::DEVICE_NOT_PROVISIONED:
- return 1;
- case EasySetupState::DEVICE_OWNED:
- return 2;
- case EasySetupState::DEVICE_NOT_OWNED:
- return 3;
- }
- return -1;
-}
-*/
\ No newline at end of file
*/
OCConnectivityType getOCConnectivityTypeFromInt(int connectivityType);
-/**
-* @brief Convert EasySetupState Enum Value to int
-*/
-//int convertNativeProvisionStateToInt(EasySetupState nativeState);
-
#endif //__JNI_ES_UTILS_H_
jclass g_cls_RemoteEnrollee = 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_CloudProvisioningStatus_ctor = NULL;
// JNI OnLoad
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
jclass clazz = nullptr;
- //Remote Enrollee
+ // Remote Enrollee
clazz = env->FindClass("org/iotivity/service/easysetup/mediator/RemoteEnrollee");
if (!clazz) return JNI_ERR;
g_cls_RemoteEnrollee = (jclass)env->NewGlobalRef(clazz);
"(J)V");
if (!g_mid_RemoteEnrollee_ctor) return JNI_ERR;
- //ESException
+ // ESException
clazz = env->FindClass("org/iotivity/service/easysetup/mediator/ESException");
if (!clazz) return JNI_ERR;
g_cls_ESException = (jclass)env->NewGlobalRef(clazz);
g_mid_ESException_ctor = env->GetMethodID(g_cls_ESException, "<init>", "(Ljava/lang/String;)V");
if (!g_mid_ESException_ctor) return JNI_ERR;
+ // CloudProvisioningStatus
+ clazz = env->FindClass("org/iotivity/service/easysetup/mediator/CloudProvisioningStatus");
+ if (!clazz) return JNI_ERR;
+ g_cls_CloudProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_CloudProvisioningStatus_ctor = env->GetMethodID(g_cls_CloudProvisioningStatus, "<init>",
+ "(II)V");
+ if (!g_mid_CloudProvisioningStatus_ctor) return JNI_ERR;
+
return JNI_CURRENT_VERSION;
}
#define __JNI_ES_JVM_H
#include <jni.h>
-#include<string>
+#include <string>
#include <android/log.h>
#define ESTAG "ES-JNI"
extern jclass g_cls_RemoteEnrollee;
extern jclass g_cls_ESException;
+extern jclass g_cls_CloudProvisioningStatus;
-extern jmethodID g_mid_RemoteEnrollee_ctor ;
+extern jmethodID g_mid_RemoteEnrollee_ctor;
extern jmethodID g_mid_ESException_ctor;
+extern jmethodID g_mid_CloudProvisioningStatus_ctor;
typedef void(*RemoveListenerCallback)(JNIEnv *env, jobject jListener);
if (NULL == env) return;
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
-
}
JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject thiz)
}
return remoteEnrollee;
}
-/*
-void JniRemoteEnrollee::startProvisioning(JNIEnv *env)
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetCloudProvInfo
+(JNIEnv *env, jobject jClass, jstring jauthCode, jstring jauthProvider, jstring jciServer)
{
- try
- {
- m_sharedResource->startProvisioning();
- }
- catch (ESBadRequestException exception)
- {
- LOGE("JNI startProvisioning :: Exception occured");
- //throw the exception to java
- throwESException( env, exception.what());
- }
+ LOGD("nativeSetCloudProvInfo Enter");
+
+ // TODO
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->setCloudProvInfo(env, jauthCode, jauthProvider, jciServer);
+
+ LOGD("nativeSetCloudProvInfo Exit");
}
-void JniRemoteEnrollee::stopProvisioning(JNIEnv *env)
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartCloudProvisioning
+(JNIEnv *env, jobject jClass, jobject jListener)
{
- try
- {
- m_sharedResource->stopProvisioning();
- }
- catch (ESBadRequestException exception)
- {
- LOGE("JNI stopProvisioning :: Exception occured");
- //throw the exception to java
- throwESException( env, exception.what());
- }
+ LOGD("nativeStartCloudProvisioning Enter");
+
+ JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+ remoteEnrollee->startCloudProvisioning(env, jListener);
+
+ LOGD("nativeStartCloudProvisioning Exit");
+}
+
+void JniRemoteEnrollee::setCloudProvInfo(JNIEnv *env, jstring jauthCode, jstring jauthProvider, jstring jciServer)
+{
+ CloudProvInfo info;
+ info.authCode = env->GetStringUTFChars(jauthCode, NULL);
+ info.authProvider = env->GetStringUTFChars(jauthProvider, NULL);
+ info.ciServer = env->GetStringUTFChars(jciServer, NULL);
+
+ m_sharedResource->setCloudProvInfo(info);
}
-void JniRemoteEnrollee::registerProvisioningHandler(JNIEnv *env, jobject jListener)
+void JniRemoteEnrollee::startCloudProvisioning(JNIEnv *env, jobject jListener)
{
- JniProvisioningStatusListener *onProvisioningStatusReceived = addProvisioningStatusListener(env,
+ JniCloudProvisioningStatusListener *onCloudProvisioningStatusReceived = addCloudProvisioningStatusListener(env,
jListener);
- RemoteEnrollee::EasySetupStatusCB provisionStatusCallback = [onProvisioningStatusReceived]
- (std::shared_ptr< OIC::Service::EasySetupStatus > easySetupStatus)
+ CloudProvStatusCb provisionStatusCallback = [onCloudProvisioningStatusReceived]
+ (std::shared_ptr< OIC::Service::CloudProvisioningStatus > cloudProvisioningStatus)
{
- onProvisioningStatusReceived->provisionStatusCallback(easySetupStatus);
+ onCloudProvisioningStatusReceived->onCloudProvisioningStatus(cloudProvisioningStatus);
};
try
{
- m_sharedResource->registerEasySetupStatusHandler(provisionStatusCallback);
+ m_sharedResource->startCloudProvisioning(provisionStatusCallback);
}
- catch (ESException exception)
+ catch (ESBadRequestException exception)
{
- LOGE("JNI stopProvisioning :: Exception occured");
+ LOGE("JNI startProvisioning :: Exception occured");
//throw the exception to java
- throwESException( env, exception.what());
+ throwESException(env, exception.what());
}
-
}
-JniProvisioningStatusListener *JniRemoteEnrollee::addProvisioningStatusListener(JNIEnv *env,
+JniCloudProvisioningStatusListener *JniRemoteEnrollee::addCloudProvisioningStatusListener(JNIEnv *env,
jobject jListener)
{
- return this->m_provisioingStatus.addListener(env, jListener, this);
-}
-
-void JniRemoteEnrollee::removeProvisioningStatusListener(JNIEnv *env, jobject jListener)
-{
- this->m_provisioingStatus.removeListener(env, jListener);
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartProvision
-(JNIEnv *env, jobject jClass)
-{
- LOGD("nativeStartProvision Enter");
-
- JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
- remoteEnrollee->startProvisioning(env);
-
- LOGD("nativeStartProvision Exit");
+ return this->m_cloudProvisioningStatus.addListener(env, jListener, this);
}
-JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStopProvision
-(JNIEnv *env, jobject jClass)
+void JniRemoteEnrollee::removeCloudProvisioningStatusListener(JNIEnv *env, jobject jListener)
{
-
- LOGD("nativeStopProvision Enter");
-
- JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
- remoteEnrollee->stopProvisioning(env);
-
- LOGD("nativeStopProvision Exit");
+ this->m_cloudProvisioningStatus.removeListener(env, jListener);
}
-JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRegisterProvisioningHandler
-(JNIEnv *env, jobject jClass, jobject provisiongListener)
-{
- LOGD("nativeRegisterProvisioningHandler Enter");
-
- if (!provisiongListener)
- {
- LOGE("nativeRegisterProvisioningHandler : listener is NULL");
- return;
- }
- JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
- remoteEnrollee->registerProvisioningHandler(env, provisiongListener);
-
- LOGD("nativeRegisterProvisioningHandler Exit");
-}
-*/
#include "JniJvm.h"
#include "JniEsUtils.h"
#include "JniProvisioningStatusListener.h"
+#include "JniCloudProvisioningStatusListener.h"
#include "JniEsListenerManager.h"
using namespace OIC::Service;
// ***** JNI APIs internally call the APIs of this class ***** //
- //void startProvisioning(JNIEnv *env);
- //void stopProvisioning(JNIEnv *env);
- //void registerProvisioningHandler(JNIEnv *env, jobject jListener);
+ void setCloudProvInfo(JNIEnv *env, jstring authCode, jstring authProvider, jstring ciServer);
- //JniProvisioningStatusListener *addProvisioningStatusListener(JNIEnv *env, jobject jListener);
- //void removeProvisioningStatusListener(JNIEnv *env, jobject jListener);
+ void startCloudProvisioning(JNIEnv *env, jobject jListener);
static JniRemoteEnrollee *getJniRemoteEnrollee(JNIEnv *env, jobject thiz);
+ JniCloudProvisioningStatusListener *addCloudProvisioningStatusListener(JNIEnv *env, jobject jListener);
+ void removeCloudProvisioningStatusListener(JNIEnv *env, jobject jListener);
+
private:
- //JniEsListenerManager<JniProvisioningStatusListener> m_provisioingStatus;
+ void registerCloudProvisioningHandler(JNIEnv *env, jobject jListener);
+ JniEsListenerManager<JniCloudProvisioningStatusListener> m_cloudProvisioningStatus;
std::shared_ptr<RemoteEnrollee> m_sharedResource;
};
#endif
/**
+ * 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);
+
+/**
* API for starting the provisioning process.
*/
//JNIEXPORT void JNICALL
{
ES_CLOUD_PROVISIONING_ERROR = -1,
ES_CLOUD_PROVISIONING_SUCCESS,
- ES_ENROLLEE_FOUND,
- ES_ENROLLEE_NOT_FOUND
+ ES_CLOUD_ENROLLEE_FOUND,
+ ES_CLOUD_ENROLLEE_NOT_FOUND
}ESCloudProvState;
typedef enum
m_cloudResource = std::make_shared<CloudResource>(std::move(m_ocResource));
std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared<
- CloudProvisioningStatus >(ESResult::ES_ERROR, ESCloudProvState::ES_ENROLLEE_FOUND);
+ CloudProvisioningStatus >(ESResult::ES_ERROR, ESCloudProvState::ES_CLOUD_ENROLLEE_FOUND);
+
m_cloudProvStatusCb(provStatus);
}
else
"Exception caught in startCloudProvisioning = %s", e.what());
std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared<
- CloudProvisioningStatus >(ESResult::ES_ERROR, ESCloudProvState::ES_ENROLLEE_NOT_FOUND);
+ CloudProvisioningStatus >(ESResult::ES_ERROR, ESCloudProvState::ES_CLOUD_ENROLLEE_NOT_FOUND);
m_cloudProvStatusCb(provStatus);
}