Add APIs of cloud provisioning for Android and JNI layer
authorJihun Ha <jihun.ha@samsung.com>
Wed, 22 Jun 2016 08:44:25 +0000 (17:44 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 23 Jun 2016 07:02:09 +0000 (07:02 +0000)
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>
20 files changed:
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvInfo.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningCallback.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningStatus.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESCloudProvState.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESResult.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetup.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java
service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.cpp [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.h [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/jni/JniEasySetup.cpp
service/easy-setup/mediator/richsdk/android/jni/JniEasySetup.h
service/easy-setup/mediator/richsdk/android/jni/JniEsUtils.cpp
service/easy-setup/mediator/richsdk/android/jni/JniEsUtils.h
service/easy-setup/mediator/richsdk/android/jni/JniJvm.cpp
service/easy-setup/mediator/richsdk/android/jni/JniJvm.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.cpp
service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h
service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp

diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvInfo.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvInfo.java
new file mode 100755 (executable)
index 0000000..ebe7a97
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * ***************************************************************
+ *
+ * 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;
+    }
+}
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningCallback.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningCallback.java
new file mode 100755 (executable)
index 0000000..7e7aeb5
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * ***************************************************************
+ *
+ * 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);
+}
+
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningStatus.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningStatus.java
new file mode 100755 (executable)
index 0000000..3bee761
--- /dev/null
@@ -0,0 +1,47 @@
+/**
+ * ***************************************************************
+ *
+ * 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;
+    }
+};
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESCloudProvState.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESCloudProvState.java
new file mode 100755 (executable)
index 0000000..6b31dfc
--- /dev/null
@@ -0,0 +1,65 @@
+/**
+ * ***************************************************************
+ *
+ * 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;
+    }
+};
+
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESResult.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESResult.java
new file mode 100755 (executable)
index 0000000..f7bdd24
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * ***************************************************************
+ *
+ * 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
index 597e681..2e47b0e 100755 (executable)
@@ -29,6 +29,7 @@ import java.io.IOException;
 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.
@@ -41,19 +42,13 @@ public class EasySetup {
 
     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 {
@@ -63,19 +58,13 @@ public class EasySetup {
     }
 
     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();
@@ -84,24 +73,23 @@ public class 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();
+        }
 }
index db0206d..9e4d35c 100755 (executable)
@@ -30,30 +30,26 @@ public class RemoteEnrollee{
     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 ");
+    }
 }
diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.cpp b/service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.cpp
new file mode 100755 (executable)
index 0000000..22343b2
--- /dev/null
@@ -0,0 +1,133 @@
+/******************************************************************
+ *
+ * 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);
+    }
+}
diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.h b/service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.h
new file mode 100755 (executable)
index 0000000..5fafc71
--- /dev/null
@@ -0,0 +1,68 @@
+/******************************************************************
+ *
+ * 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_
+
index 88521a0..4c4b4d8 100755 (executable)
@@ -26,7 +26,7 @@ using namespace OIC::Service;
 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)
 {
 
index 8dd3882..99fbc80 100755 (executable)
@@ -50,7 +50,7 @@ extern "C" {
  * @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
index 5eff9d2..71e4341 100755 (executable)
@@ -44,20 +44,3 @@ OCConnectivityType  getOCConnectivityTypeFromInt(int connectivityType)
     }
     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
index 6b90f6b..7ae6390 100755 (executable)
@@ -47,9 +47,4 @@ void throwESException(JNIEnv *env, std::string reason);
 */
 OCConnectivityType  getOCConnectivityTypeFromInt(int connectivityType);
 
-/**
-* @brief Convert EasySetupState Enum Value to int
-*/
-//int convertNativeProvisionStateToInt(EasySetupState nativeState);
-
 #endif //__JNI_ES_UTILS_H_
index 2e02060..9c7fb12 100755 (executable)
@@ -23,9 +23,11 @@ JavaVM *g_jvm = NULL;
 
 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)
@@ -42,7 +44,7 @@ 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);
@@ -52,7 +54,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
                                 "(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);
@@ -61,6 +63,16 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     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;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 8f69842..11e6447
@@ -29,7 +29,7 @@
 #define __JNI_ES_JVM_H
 
 #include <jni.h>
-#include<string>
+#include <string>
 #include <android/log.h>
 
 #define ESTAG "ES-JNI"
@@ -43,9 +43,11 @@ extern JavaVM *g_jvm;
 
 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);
 
index a1d9696..31de275 100755 (executable)
@@ -35,7 +35,6 @@ JniRemoteEnrollee::~JniRemoteEnrollee()
     if (NULL == env) return;
 
     if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
-
 }
 
 JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject thiz)
@@ -51,109 +50,74 @@ JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject
     }
     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");
-}
-*/
index d8779a0..2d48eba 100755 (executable)
@@ -34,6 +34,7 @@
 #include "JniJvm.h"
 #include "JniEsUtils.h"
 #include "JniProvisioningStatusListener.h"
+#include "JniCloudProvisioningStatusListener.h"
 #include "JniEsListenerManager.h"
 
 using namespace OIC::Service;
@@ -60,17 +61,18 @@ class JniRemoteEnrollee
 
         // ***** 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;
 
 };
@@ -81,6 +83,20 @@ extern "C" {
 #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
index 7de9bb6..2fed504 100755 (executable)
@@ -186,8 +186,8 @@ namespace OIC
         {
             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
index 22fd384..28a6287 100755 (executable)
@@ -422,7 +422,8 @@ namespace OIC
                     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
@@ -457,7 +458,7 @@ namespace OIC
                     "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);
             }