From 38dd087a5fc619536cacde3aca1b53f717daed3e Mon Sep 17 00:00:00 2001 From: Jihun Ha Date: Mon, 1 Aug 2016 20:25:10 +0900 Subject: [PATCH] Add getStatus API in RemoteEnrollee class for Android platform Along with a getStatus API for Linux platform, I've implemented the API for Android platform. Additionally, DeviceConfig and WiFiConfig classes are removed because they are not used anymore. Conflicts: service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java Change-Id: If49f50d1ecd03fbc29aba5ba0a066bfd3a298e91 Signed-off-by: Jihun Ha Reviewed-on: https://gerrit.iotivity.org/gerrit/9887 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- .../service/easysetup/mediator/DeviceConfig.java | 76 ---------- .../service/easysetup/mediator/EnrolleeStatus.java | 88 ++++++++++++ .../mediator/GetConfigurationCallback.java | 2 - .../easysetup/mediator/GetEnrolleeStatus.java | 69 ++++++++++ .../easysetup/mediator/GetStatusCallback.java | 39 ++++++ .../service/easysetup/mediator/RemoteEnrollee.java | 20 +++ .../service/easysetup/mediator/WiFiConfig.java | 88 ------------ .../easysetup/mediator/enums/ESErrorCode.java | 80 +++++++++++ .../easysetup/mediator/enums/ProvStatus.java | 75 ++++++++++ .../android/jni/JniGetEnrolleeStatusListener.cpp | 153 +++++++++++++++++++++ .../android/jni/JniGetEnrolleeStatusListener.h | 61 ++++++++ .../mediator/richsdk/android/jni/JniJvm.cpp | 42 +++--- .../mediator/richsdk/android/jni/JniJvm.h | 8 +- .../richsdk/android/jni/JniRemoteEnrollee.cpp | 36 +++++ .../richsdk/android/jni/JniRemoteEnrollee.h | 9 ++ .../easy-setup/mediator/richsdk/inc/ESRichCommon.h | 10 ++ 16 files changed, 665 insertions(+), 191 deletions(-) delete mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/DeviceConfig.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeStatus.java create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetEnrolleeStatus.java create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetStatusCallback.java delete mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiConfig.java create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESErrorCode.java create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ProvStatus.java create mode 100755 service/easy-setup/mediator/richsdk/android/jni/JniGetEnrolleeStatusListener.cpp create mode 100755 service/easy-setup/mediator/richsdk/android/jni/JniGetEnrolleeStatusListener.h diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/DeviceConfig.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/DeviceConfig.java deleted file mode 100755 index 0cc59ee..0000000 --- a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/DeviceConfig.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * *************************************************************** - * - * 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 stores an Enrollee's configuration specific to device configuration - * device name, language, and country information are stored - */ -public class DeviceConfig -{ - private final String mName; - private final String mLanguage; - private final String mCountry; - - /** - * Constructor - * - * @param name Device's human-friendly name like device model name - * @param language IETF language tag using ISO 639X - * @param country ISO Country Code (ISO 3166-1 Alpha-2) - */ - public DeviceConfig(String name, String language, String country) - { - mName = name; - mLanguage = language; - mCountry = country; - } - - /** - * Get a device name - * - * @return a device name - */ - public String getName() - { - return mName; - } - - /** - * Get a language - * - * @return a language - */ - public String getLanguage() - { - return mLanguage; - } - - /** - * Get a country - * - * @return a country - */ - public String getCountry() - { - return mCountry; - } -} diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeStatus.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeStatus.java new file mode 100755 index 0000000..3421c40 --- /dev/null +++ b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeStatus.java @@ -0,0 +1,88 @@ +/** + * *************************************************************** + * + * 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 android.util.Log; + +import org.iotivity.base.OcException; +import org.iotivity.base.OcRepresentation; +import org.iotivity.service.easysetup.mediator.ESConstants; +import org.iotivity.service.easysetup.mediator.enums.ESErrorCode; +import org.iotivity.service.easysetup.mediator.enums.ProvStatus; + +/** + * This class stores Enrollee's status including provisioning status and last error code. + */ +public class EnrolleeStatus +{ + private static final String TAG = EnrolleeStatus.class.getName(); + private OcRepresentation mRep = null; + /** + * Constructor + * + * @param rep received properties in a form of OcRepresentation + * + */ + public EnrolleeStatus(OcRepresentation rep) + { + mRep = rep; + } + + /** + * Get a provisioning status property of Enrollee. + * + * @return a provisioning status property of Enrollee + */ + public ProvStatus getProvStatus() + { + try + { + if(mRep != null && mRep.hasAttribute(ESConstants.OC_RSRVD_ES_PROVSTATUS)) { + int provStatus = mRep.getValue(ESConstants.OC_RSRVD_ES_PROVSTATUS); + return ProvStatus.fromInt(provStatus); + } + } catch (OcException e) { + Log.e(TAG, "getProvStatus is failed."); + } + return ProvStatus.fromInt(0); + } + + /** + * Get a last error code property of Enrollee. + * + * @return a last error code property of Enrollee. + */ + public ESErrorCode getLastErrCode() + { + try + { + if(mRep != null && mRep.hasAttribute(ESConstants.OC_RSRVD_ES_LAST_ERRORCODE)) { + int errCode = mRep.getValue(ESConstants.OC_RSRVD_ES_LAST_ERRORCODE); + return ESErrorCode.fromInt(errCode); + } + } catch (OcException e) { + Log.e(TAG, "getLastErrCode is failed."); + } + return ESErrorCode.fromInt(0); + } +} + + diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetConfigurationCallback.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetConfigurationCallback.java index 83f583e..60a6e01 100644 --- a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetConfigurationCallback.java +++ b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetConfigurationCallback.java @@ -20,8 +20,6 @@ package org.iotivity.service.easysetup.mediator; -import org.iotivity.service.easysetup.mediator.GetConfigurationCallback; - /** * This interface class is used as a callback function called after receiving * Enrollee's configuration. diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetEnrolleeStatus.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetEnrolleeStatus.java new file mode 100644 index 0000000..916a9c6 --- /dev/null +++ b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetEnrolleeStatus.java @@ -0,0 +1,69 @@ +/** + * *************************************************************** + * + * 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.enums.ESResult; + +/** + * This class indicates a result if a getConfiguartion API succeed or fails and + * Enrollee's configuration delivered by a response. + */ +public class GetEnrolleeStatus +{ + private ESResult mResult; + private EnrolleeStatus mEnrolleeStatus; + + /** + * Constructor + * + * @param result a result if a getStatus API succeed or fail + * @param status Enrollee's status + * + */ + public GetEnrolleeStatus(int result, EnrolleeStatus status) + { + mResult = ESResult.fromInt(result); + mEnrolleeStatus = status; + } + + /** + * Get a result of a getStatus API call + * + * @return ESResult + * + */ + public ESResult getESResult() + { + return mResult; + } + + /** + * Get Enrollee's status + * + * @return EnrolleeStatus includes a provisioning status and last error code. + * + * @see EnrolleeStatus + */ + public EnrolleeStatus getEnrolleeStatus() + { + return mEnrolleeStatus; + } +}; diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetStatusCallback.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetStatusCallback.java new file mode 100644 index 0000000..80ee811 --- /dev/null +++ b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetStatusCallback.java @@ -0,0 +1,39 @@ +/** + * *************************************************************** + * + * 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 class is used as a callback function called after receiving + * Enrollee's status. + * + * @see GetEnrolleeStatus + */ +public abstract class GetStatusCallback { + + /** + * Called after receiving Enrollee's status + * + * @param status + * result if the request succeeds or fails + * Enrollee's status like a provisioning status and last error code + */ + public abstract void onProgress(GetEnrolleeStatus status); +} diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java index 0ff4652..b32d6d9 100755 --- a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java +++ b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java @@ -40,6 +40,7 @@ public class RemoteEnrollee{ public static final String TAG = RemoteEnrollee.class.getName(); private long m_nativeHandle; + private native void nativeGetStatus(GetStatusCallback callback); private native void nativeGetConfiguration(GetConfigurationCallback callback); private native void nativeProvisionSecurity(SecurityProvisioningCallback callback); private native void nativeProvisionDeviceProperties(OcRepresentation deviceProp, @@ -53,6 +54,25 @@ public class RemoteEnrollee{ } /** + * Get an Enrollee's status which includes a provisioning status and last error code + * + * @param callback will give the requested status + * + * @throws ESException If some errors happen in this function + * + * @see GetStatusCallback + */ + public void getStatus(GetStatusCallback callback) throws ESException + { + if(callback != null) + { + nativeGetStatus(callback); + return; + } + Log.d(TAG, "GetStatusCallback is null "); + } + + /** * Get an Enrollee's configuration which includes WiFi supported frequency and device name * * @param callback will give the requested configuration diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiConfig.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiConfig.java deleted file mode 100755 index d8ee7d2..0000000 --- a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiConfig.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * *************************************************************** - * - * 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 android.util.Log; - -import org.iotivity.service.easysetup.mediator.enums.WIFI_FREQ; -import org.iotivity.service.easysetup.mediator.enums.WIFI_MODE; - -import java.util.ArrayList; - -/** - * This class stores an Enrollee's configuration specific to WiFi configuration - * supported WiFi modes and frequency are stored - */ -public class WiFiConfig -{ - public static final String TAG = WiFiConfig.class.getName(); - private final ArrayList mWifiModes; - private final WIFI_FREQ mWifiFreq; - - /** - * Constructor - * - * @param types - * stores an array of Wifi modes like 11G and 11N. - * 11A(0), 11B, 11G, 11N, 11AC(4) are supported - * @param wifiFreq - * stores WiFi frequency like 2.4G, 5G, or both - */ - public WiFiConfig(ArrayList types, int wifiFreq) - { - mWifiModes = convertWifiModes(types); - mWifiFreq = WIFI_FREQ.fromInt(wifiFreq); - } - - private ArrayList convertWifiModes(ArrayList types) - { - ArrayList wifiModes = new ArrayList<>(); - for (Integer type: types) { - wifiModes.add(WIFI_MODE.fromInt(type.intValue())); - }; - return wifiModes; - } - - /** - * get WiFi mode - * - * @return ArrayList - * 11A(0), 11B, 11G, 11N, 11AC(4) are supported - * @see WIFI_MODE - */ - public ArrayList getWifiModes() - { - return mWifiModes; - } - - /** - * get WiFi frequency - * - * @param WIFI_FREQ - * 2.4G, 5G, or both - * - * @see WIFI_FREQ - */ - public WIFI_FREQ getWifiFreq() - { - return mWifiFreq; - } -} diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESErrorCode.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESErrorCode.java new file mode 100644 index 0000000..a908748 --- /dev/null +++ b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESErrorCode.java @@ -0,0 +1,80 @@ +/** + * *************************************************************** + * + * 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.enums; + +/** + * @brief Indicate last error code to describe a reason of error during easy setup. + */ +public enum ESErrorCode { + + /** + * Init Error Code + */ + ES_ERRCODE_NO_ERROR(0), + + /** + * Error Code that given WiFi's SSID is not found + */ + ES_ERRCODE_SSID_NOT_FOUND(1), + + /** + * Error Code that given WiFi's Password is wrong + */ + ES_ERRCODE_PW_WRONG(2), + + /** + * Error Code that IP address is not allocated + */ + ES_ERRCODE_IP_NOT_ALLOCATED(3), + + /** + * Error Code that there is no Internet connection + */ + ES_ERRCODE_NO_INTERNETCONNECTION(4), + + /** + * Error Code that Timeout occured + */ + ES_ERRCODE_TIMEOUT(5), + + /** + * Error Code that Unknown error occured + */ + ES_ERRCODE_UNKNOWN(6); + + private int value; + + private ESErrorCode(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public static ESErrorCode fromInt(int i) { + for (ESErrorCode b : ESErrorCode.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/enums/ProvStatus.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ProvStatus.java new file mode 100644 index 0000000..68d289c --- /dev/null +++ b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ProvStatus.java @@ -0,0 +1,75 @@ +/** + * *************************************************************** + * + * 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.enums; + +/** + * It defines various states of the cloud provisioning during easy setup process + */ +public enum ProvStatus { + + /** + * Default state of the device + */ + ES_STATE_INIT(0), + + /** + * Status indicating being connecting to target network + */ + ES_STATE_CONNECTING_TO_ENROLLER(1), + + /** + * Status indicating successful connection to target network + */ + ES_STATE_CONNECTED_TO_ENROLLER(2), + + /** + * Status indicating failure connection to target network + */ + ES_STATE_CONNECTED_FAIL_TO_ENROLLER(3), + + /** + * Status indicating successful registration to cloud + */ + ES_STATE_REGISTERED_TO_CLOUD(4), + + /** + * Status indicating failure registration to cloud + */ + ES_STATE_REGISTRRED_FAIL_TO_CLOUD(5); + + private int value; + + private ProvStatus(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public static ProvStatus fromInt(int i) { + for (ProvStatus b : ProvStatus.values()) { + if (b.getValue() == i) { return b; } + } + return null; + } +}; + diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniGetEnrolleeStatusListener.cpp b/service/easy-setup/mediator/richsdk/android/jni/JniGetEnrolleeStatusListener.cpp new file mode 100755 index 0000000..f2ddee8 --- /dev/null +++ b/service/easy-setup/mediator/richsdk/android/jni/JniGetEnrolleeStatusListener.cpp @@ -0,0 +1,153 @@ +/****************************************************************** + * + * 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 "JniGetEnrolleeStatusListener.h" +#include "JniRemoteEnrollee.h" + +using namespace OC; +using namespace OIC::Service; + +JniGetEnrolleeStatusListener::JniGetEnrolleeStatusListener(JNIEnv *env, jobject jListener, + JniRemoteEnrollee *owner) + : m_ownerResource(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); +} + +JniGetEnrolleeStatusListener::~JniGetEnrolleeStatusListener() +{ + ES_LOGI("~JniGetEnrolleeStatusListener()"); + 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 JniGetEnrolleeStatusListener::getEnrolleeStatusCallback ( + std::shared_ptr getEnrolleeStatusCb) +{ + ES_LOGI("JniGetEnrolleeStatusListener::getEnrolleeStatusCallback 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/" + "GetEnrolleeStatus;" + ")V"); + + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + + EnrolleeStatus enrolleeStatus = getEnrolleeStatusCb->getEnrolleeStatus(); + OCRepresentation m_Rep = enrolleeStatus.getRepresentation(); + OCRepresentation* rep = new OCRepresentation(m_Rep); + jlong handle = reinterpret_cast(rep); + jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, + g_mid_OcRepresentation_N_ctor_bool, + handle, true); + if (!jRepresentation) + { + delete rep; + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jobject jEnrolleeStatus = NULL; + jEnrolleeStatus = env->NewObject(g_cls_EnrolleeStatus, + g_mid_EnrolleeStatus_ctor, + (jobject)jRepresentation); + if (!jEnrolleeStatus) { + ES_LOGE("JniGetEnrolleeStatusListener::getEnrolleeStatusCallback Unable to create the jEnrolleeStatus"); + return ; + } + + ESResult esResult = getEnrolleeStatusCb->getESResult(); + jobject jgetEnrolleeStatus = NULL; + jgetEnrolleeStatus = env->NewObject(g_cls_getEnrolleeStatus, + g_mid_getEnrolleeStatus_ctor, + (jint)esResult, + (jobject)jEnrolleeStatus); + + if (!jgetEnrolleeStatus) + { + ES_LOGE("JniGetEnrolleeStatusListener::getEnrolleeStatusCallback Unable to create the java object"); + return ; + } + + env->CallVoidMethod(jListener, midL, jgetEnrolleeStatus); + + if (env->ExceptionCheck()) + { + ES_LOGE("Java exception is thrown"); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); +} + +void JniGetEnrolleeStatusListener::checkExAndRemoveListener(JNIEnv *env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeStatusListener + (env, m_jwListener); + + env->Throw((jthrowable)ex); + } + else + { + m_ownerResource->removeStatusListener + (env, m_jwListener); + } +} + diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniGetEnrolleeStatusListener.h b/service/easy-setup/mediator/richsdk/android/jni/JniGetEnrolleeStatusListener.h new file mode 100755 index 0000000..794d431 --- /dev/null +++ b/service/easy-setup/mediator/richsdk/android/jni/JniGetEnrolleeStatusListener.h @@ -0,0 +1,61 @@ +/****************************************************************** + * + * 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_GET_ENROLLEE_STATUS_LISTENER_H_ +#define __JNI_ES_GET_ENROLLEE_STATUS_LISTENER_H_ + +#include + +#include "OCPlatform.h" +#include "RemoteEnrollee.h" +#include "ESRichCommon.h" + +#include "JniJvm.h" + +class JniRemoteEnrollee; + +using namespace OIC::Service; + +class JniGetEnrolleeStatusListener +{ + public: + /** + * @brief constructor + */ + JniGetEnrolleeStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource); + + /** + * @brief destructor + */ + ~JniGetEnrolleeStatusListener(); + + /** + * @brief callback function that will be passed to Native layer + */ + void getEnrolleeStatusCallback (std::shared_ptr getEnrolleeStatus); + + private: + jweak m_jwListener; + JniRemoteEnrollee *m_ownerResource; + void checkExAndRemoveListener(JNIEnv *env); +}; + +#endif //__JNI_ES_GET_CONFIGURATION_STATUS_LISTENER_H_ + diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniJvm.cpp b/service/easy-setup/mediator/richsdk/android/jni/JniJvm.cpp index 9f11652..a686730 100755 --- a/service/easy-setup/mediator/richsdk/android/jni/JniJvm.cpp +++ b/service/easy-setup/mediator/richsdk/android/jni/JniJvm.cpp @@ -23,9 +23,9 @@ JavaVM *g_jvm = NULL; jclass g_cls_RemoteEnrollee = NULL; jclass g_cls_ESException = NULL; +jclass g_cls_EnrolleeStatus = NULL; jclass g_cls_EnrolleeConf = NULL; -jclass g_cls_DeviceConfig = NULL; -jclass g_cls_WiFiConfig = NULL; +jclass g_cls_getEnrolleeStatus = NULL; jclass g_cls_getConfigurationStatus = NULL; jclass g_cls_SecurityProvisioningStatus = NULL; jclass g_cls_DevicePropProvisioningStatus = NULL; @@ -35,9 +35,9 @@ jclass g_cls_OcRepresentation = NULL; jmethodID g_mid_RemoteEnrollee_ctor = NULL; jmethodID g_mid_ESException_ctor = NULL; +jmethodID g_mid_EnrolleeStatus_ctor = NULL; jmethodID g_mid_EnrolleeConf_ctor = NULL; -jmethodID g_mid_DeviceConfig_ctor = NULL; -jmethodID g_mid_WiFiConfig_ctor = NULL; +jmethodID g_mid_getEnrolleeStatus_ctor = NULL; jmethodID g_mid_getConfigurationStatus_ctor = NULL; jmethodID g_mid_SecurityProvisioningStatus_ctor = NULL; jmethodID g_mid_DevicePropProvisioningStatus_ctor = NULL; @@ -79,27 +79,16 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) g_mid_ESException_ctor = env->GetMethodID(g_cls_ESException, "", "(Ljava/lang/String;)V"); if (!g_mid_ESException_ctor) return JNI_ERR; - // DeviceConfig - clazz = env->FindClass("org/iotivity/service/easysetup/mediator/DeviceConfig"); + // EnrolleeStatus + clazz = env->FindClass("org/iotivity/service/easysetup/mediator/EnrolleeStatus"); if (!clazz) return JNI_ERR; - g_cls_DeviceConfig = (jclass)env->NewGlobalRef(clazz); + g_cls_EnrolleeStatus = (jclass)env->NewGlobalRef(clazz); env->DeleteLocalRef(clazz); - g_mid_DeviceConfig_ctor = env->GetMethodID(g_cls_DeviceConfig, "", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); - if (!g_mid_DeviceConfig_ctor) return JNI_ERR; - - // WiFiConfig - clazz = env->FindClass("org/iotivity/service/easysetup/mediator/WiFiConfig"); - if (!clazz) return JNI_ERR; - - g_cls_WiFiConfig = (jclass)env->NewGlobalRef(clazz); - env->DeleteLocalRef(clazz); - - g_mid_WiFiConfig_ctor = env->GetMethodID(g_cls_WiFiConfig, "", - "(Ljava/util/ArrayList;I)V"); - if (!g_mid_WiFiConfig_ctor) return JNI_ERR; + g_mid_EnrolleeStatus_ctor = env->GetMethodID(g_cls_EnrolleeStatus, "", + "(Lorg/iotivity/base/OcRepresentation;)V"); + if (!g_mid_EnrolleeStatus_ctor) return JNI_ERR; // EnrolleeConf clazz = env->FindClass("org/iotivity/service/easysetup/mediator/EnrolleeConf"); @@ -112,6 +101,17 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) "(Lorg/iotivity/base/OcRepresentation;)V"); if (!g_mid_EnrolleeConf_ctor) return JNI_ERR; + // getEnrolleeStatus + clazz = env->FindClass("org/iotivity/service/easysetup/mediator/GetEnrolleeStatus"); + if (!clazz) return JNI_ERR; + + g_cls_getEnrolleeStatus = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + g_mid_getEnrolleeStatus_ctor = env->GetMethodID(g_cls_getEnrolleeStatus, "", + "(ILorg/iotivity/service/easysetup/mediator/EnrolleeStatus;)V"); + if (!g_mid_getEnrolleeStatus_ctor) return JNI_ERR; + // getConfigurationStatus clazz = env->FindClass("org/iotivity/service/easysetup/mediator/GetConfigurationStatus"); if (!clazz) return JNI_ERR; diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniJvm.h b/service/easy-setup/mediator/richsdk/android/jni/JniJvm.h index 542d745..ce8111b 100755 --- a/service/easy-setup/mediator/richsdk/android/jni/JniJvm.h +++ b/service/easy-setup/mediator/richsdk/android/jni/JniJvm.h @@ -43,9 +43,9 @@ extern JavaVM *g_jvm; extern jclass g_cls_RemoteEnrollee; extern jclass g_cls_ESException; +extern jclass g_cls_EnrolleeStatus; extern jclass g_cls_EnrolleeConf; -extern jclass g_cls_DeviceConfig; -extern jclass g_cls_WiFiConfig; +extern jclass g_cls_getEnrolleeStatus; extern jclass g_cls_getConfigurationStatus; extern jclass g_cls_SecurityProvisioningStatus; extern jclass g_cls_DevicePropProvisioningStatus; @@ -55,9 +55,9 @@ extern jclass g_cls_OcRepresentation; extern jmethodID g_mid_RemoteEnrollee_ctor; extern jmethodID g_mid_ESException_ctor; +extern jmethodID g_mid_EnrolleeStatus_ctor; extern jmethodID g_mid_EnrolleeConf_ctor; -extern jmethodID g_mid_DeviceConfig_ctor; -extern jmethodID g_mid_WiFiConfig_ctor; +extern jmethodID g_mid_getEnrolleeStatus_ctor; extern jmethodID g_mid_getConfigurationStatus_ctor; extern jmethodID g_mid_SecurityProvisioningStatus_ctor; extern jmethodID g_mid_DevicePropProvisioningStatus_ctor; diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.cpp b/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.cpp index 0faef04..458bb4d 100755 --- a/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.cpp +++ b/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.cpp @@ -53,6 +53,29 @@ JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject return remoteEnrollee; } +void JniRemoteEnrollee::getStatus(JNIEnv *env, jobject jListener) +{ + JniGetEnrolleeStatusListener *onGetEnrolleeStatusReceived = + addStatusListener(env, jListener); + + GetStatusCb getEnrolleeStatusCallback = [onGetEnrolleeStatusReceived] + (std::shared_ptr getEnrolleeStatus) + { + onGetEnrolleeStatusReceived->getEnrolleeStatusCallback(getEnrolleeStatus); + }; + + try + { + m_sharedResource->getStatus(getEnrolleeStatusCallback); + } + catch (ESBadRequestException exception) + { + ES_LOGE("JNI getStatus :: Exception occured"); + //throw the exception to java + throwESException( env, exception.what()); + } +} + void JniRemoteEnrollee::getConfiguration(JNIEnv *env, jobject jListener) { JniGetConfigurationStatusListener *onGetConfigurationStatusReceived = @@ -169,6 +192,19 @@ void JniRemoteEnrollee::provisionCloudProperties(JNIEnv *env, //JNI JNIEXPORT void JNICALL +Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeGetStatus +(JNIEnv *env, jobject jClass, jobject jListener) +{ + ES_LOGD("nativeGetStatus Enter"); + + JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass); + remoteEnrollee->getStatus(env, jListener); + + ES_LOGD("nativeGetStatus Exit"); +} + +//JNI +JNIEXPORT void JNICALL Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeGetConfiguration (JNIEnv *env, jobject jClass, jobject jListener) { diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h b/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h index b279051..483d2f6 100755 --- a/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h +++ b/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h @@ -33,6 +33,7 @@ #include "JniJvm.h" #include "JniEsUtils.h" +#include "JniGetEnrolleeStatusListener.h" #include "JniGetConfigurationStatusListener.h" #include "JniSecurityStatusListener.h" #include "JniDevicePropProvisioningStatusListener.h" @@ -62,6 +63,7 @@ class JniRemoteEnrollee ~JniRemoteEnrollee(); // ***** JNI APIs internally call the APIs of this class ***** // + void getStatus(JNIEnv *env, jobject jListener); void getConfiguration(JNIEnv *env, jobject jListener); void provisionSecurity(JNIEnv *env, jobject jListener); void provisionDeviceProperties(JNIEnv *env, jobject jRepresentation, jobject jListener); @@ -91,6 +93,13 @@ extern "C" { #endif /** + * API for starting the Request Enrollee status process. + */ +JNIEXPORT void JNICALL +Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeGetStatus +(JNIEnv *env, jobject jClass, jobject jListener); + +/** * API for starting the Request EnrolleeConf process. */ JNIEXPORT void JNICALL diff --git a/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h b/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h index a3178ff..56fc35e 100755 --- a/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h +++ b/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h @@ -80,6 +80,16 @@ namespace OIC m_rep.getValue(OC_RSRVD_ES_LAST_ERRORCODE)); return ES_ERRCODE_NO_ERROR; } + + /** + * Get OCRepresentation object + * + * @return OCRepresentation object + */ + const OCRepresentation& getRepresentation() + { + return m_rep; + } protected: OCRepresentation m_rep; }; -- 2.7.4