Added platform information to the android code, as per the spec compliance changes
authorRahul Rahul <rahul.rahul@intel.com>
Mon, 29 Jun 2015 20:27:18 +0000 (13:27 -0700)
committerErich Keane <erich.keane@intel.com>
Wed, 1 Jul 2015 22:00:33 +0000 (22:00 +0000)
Change-Id: I78fba71991d8e9da92f706f26166be86a6704c7c
Signed-off-by: Rahul Rahul <rahul.rahul@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1443
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
android/android_api/base/jni/Android.mk
android/android_api/base/jni/JniOcPlatform.cpp
android/android_api/base/jni/JniOcPlatform.h
android/android_api/base/jni/JniOnPlatformInfoListener.cpp [new file with mode: 0644]
android/android_api/base/jni/JniOnPlatformInfoListener.h [new file with mode: 0644]
android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java
android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java
android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java
android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/OcStackConfig.java [new file with mode: 0644]

index aa2cbae..6a7e613 100644 (file)
@@ -43,6 +43,7 @@ LOCAL_SRC_FILES :=  JniOcStack.cpp \
                     JniEntityHandler.cpp \\r
                     JniOnResourceFoundListener.cpp \\r
                     JniOnDeviceInfoListener.cpp \\r
+                   JniOnPlatformInfoListener.cpp \\r
                     JniOnPresenceListener.cpp \\r
                     JniOnGetListener.cpp \\r
                     JniOnPutListener.cpp \\r
index 40b5898..5dfe78b 100644 (file)
-/*\r
-* //******************************************************************\r
-* //\r
-* // Copyright 2015 Intel Corporation.\r
-* //\r
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-* //\r
-* // Licensed under the Apache License, Version 2.0 (the "License");\r
-* // you may not use this file except in compliance with the License.\r
-* // You may obtain a copy of the License at\r
-* //\r
-* //      http://www.apache.org/licenses/LICENSE-2.0\r
-* //\r
-* // Unless required by applicable law or agreed to in writing, software\r
-* // distributed under the License is distributed on an "AS IS" BASIS,\r
-* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* // See the License for the specific language governing permissions and\r
-* // limitations under the License.\r
-* //\r
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-*/\r
-#include "JniOcPlatform.h"\r
-#include "OCPlatform.h"\r
-#include "JniOcResource.h"\r
-#include "JniOcResourceHandle.h"\r
-#include "JniOcPresenceHandle.h"\r
-#include "JniOcResourceResponse.h"\r
-#include "JniUtils.h"\r
-\r
-using namespace OC;\r
-\r
-JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener)\r
-{\r
-    JniOnResourceFoundListener *onResourceFoundListener = NULL;\r
-\r
-    resourceFoundMapLock.lock();\r
-\r
-    for (auto it = onResourceFoundListenerMap.begin(); it != onResourceFoundListenerMap.end(); ++it)\r
-    {\r
-        if (env->IsSameObject(jListener, it->first))\r
-        {\r
-            auto refPair = it->second;\r
-            onResourceFoundListener = refPair.first;\r
-            refPair.second++;\r
-            it->second = refPair;\r
-            onResourceFoundListenerMap.insert(*it);\r
-            LOGD("OnResourceFoundListener: ref. count incremented");\r
-            break;\r
-        }\r
-    }\r
-\r
-    if (!onResourceFoundListener)\r
-    {\r
-        onResourceFoundListener = new JniOnResourceFoundListener(env, jListener, RemoveOnResourceFoundListener);\r
-        jobject jgListener = env->NewGlobalRef(jListener);\r
-\r
-        onResourceFoundListenerMap.insert(std::pair < jobject, std::pair < JniOnResourceFoundListener*,\r
-            int >> (jgListener, std::pair<JniOnResourceFoundListener*, int>(onResourceFoundListener, 1)));\r
-        LOGD("OnResourceFoundListener: new listener");\r
-    }\r
-    resourceFoundMapLock.unlock();\r
-    return onResourceFoundListener;\r
-}\r
-\r
-void RemoveOnResourceFoundListener(JNIEnv* env, jobject jListener)\r
-{\r
-    resourceFoundMapLock.lock();\r
-\r
-    for (auto it = onResourceFoundListenerMap.begin(); it != onResourceFoundListenerMap.end(); ++it)\r
-    {\r
-        if (env->IsSameObject(jListener, it->first))\r
-        {\r
-            auto refPair = it->second;\r
-            if (refPair.second > 1)\r
-            {\r
-                refPair.second--;\r
-                it->second = refPair;\r
-                onResourceFoundListenerMap.insert(*it);\r
-                LOGI("OnResourceFoundListener: ref. count decremented");\r
-            }\r
-            else\r
-            {\r
-                env->DeleteGlobalRef(it->first);\r
-                JniOnResourceFoundListener* listener = refPair.first;\r
-                delete listener;\r
-                onResourceFoundListenerMap.erase(it);\r
-                LOGI("OnResourceFoundListener removed");\r
-            }\r
-            break;\r
-        }\r
-    }\r
-    resourceFoundMapLock.unlock();\r
-}\r
-\r
-JniOnDeviceInfoListener* AddOnDeviceInfoListener(JNIEnv* env, jobject jListener)\r
-{\r
-    JniOnDeviceInfoListener *onDeviceInfoListener = NULL;\r
-\r
-    deviceInfoMapLock.lock();\r
-\r
-    for (auto it = onDeviceInfoListenerMap.begin(); it != onDeviceInfoListenerMap.end(); ++it)\r
-    {\r
-        if (env->IsSameObject(jListener, it->first))\r
-        {\r
-            auto refPair = it->second;\r
-            onDeviceInfoListener = refPair.first;\r
-            refPair.second++;\r
-            it->second = refPair;\r
-            onDeviceInfoListenerMap.insert(*it);\r
-            LOGD("OnDeviceInfoListener: ref. count incremented");\r
-            break;\r
-        }\r
-    }\r
-\r
-    if (!onDeviceInfoListener)\r
-    {\r
-        onDeviceInfoListener = new JniOnDeviceInfoListener(env, jListener, RemoveOnDeviceInfoListener);\r
-        jobject jgListener = env->NewGlobalRef(jListener);\r
-\r
-        onDeviceInfoListenerMap.insert(std::pair < jobject, std::pair < JniOnDeviceInfoListener*,\r
-            int >> (jgListener, std::pair<JniOnDeviceInfoListener*, int>(onDeviceInfoListener, 1)));\r
-        LOGI("OnDeviceInfoListener: new listener");\r
-    }\r
-\r
-    deviceInfoMapLock.unlock();\r
-    return onDeviceInfoListener;\r
-}\r
-\r
-void RemoveOnDeviceInfoListener(JNIEnv* env, jobject jListener)\r
-{\r
-    deviceInfoMapLock.lock();\r
-    bool isFound = false;\r
-    for (auto it = onDeviceInfoListenerMap.begin(); it != onDeviceInfoListenerMap.end(); ++it)\r
-    {\r
-        if (env->IsSameObject(jListener, it->first))\r
-        {\r
-            auto refPair = it->second;\r
-            if (refPair.second > 1)\r
-            {\r
-                refPair.second--;\r
-                it->second = refPair;\r
-                onDeviceInfoListenerMap.insert(*it);\r
-                LOGI("OnDeviceInfoListener: ref. count decremented");\r
-            }\r
-            else\r
-            {\r
-                env->DeleteGlobalRef(it->first);\r
-                JniOnDeviceInfoListener* listener = refPair.first;\r
-                delete listener;\r
-                onDeviceInfoListenerMap.erase(it);\r
-\r
-                LOGI("OnDeviceInfoListener removed");\r
-            }\r
-\r
-            isFound = true;\r
-            break;\r
-        }\r
-    }\r
-\r
-    if (!isFound)\r
-    {\r
-        ThrowOcException(JNI_EXCEPTION, "OnDeviceInfoListenet not found");\r
-    }\r
-    deviceInfoMapLock.unlock();\r
-}\r
-\r
-JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener)\r
-{\r
-    JniOnPresenceListener *onPresenceListener = NULL;\r
-\r
-    presenceMapLock.lock();\r
-\r
-    for (auto it = onPresenceListenerMap.begin(); it != onPresenceListenerMap.end(); ++it)\r
-    {\r
-        if (env->IsSameObject(jListener, it->first))\r
-        {\r
-            auto refPair = it->second;\r
-            onPresenceListener = refPair.first;\r
-            refPair.second++;\r
-            it->second = refPair;\r
-            onPresenceListenerMap.insert(*it);\r
-            LOGD("OnPresenceListener: ref. count incremented");\r
-            break;\r
-        }\r
-    }\r
-    if (!onPresenceListener)\r
-    {\r
-        onPresenceListener = new JniOnPresenceListener(env, jListener, RemoveOnPresenceListener);\r
-        jobject jgListener = env->NewGlobalRef(jListener);\r
-        onPresenceListenerMap.insert(std::pair < jobject, std::pair < JniOnPresenceListener*,\r
-            int >> (jgListener, std::pair<JniOnPresenceListener*, int>(onPresenceListener, 1)));\r
-        LOGI("OnPresenceListener: new listener");\r
-    }\r
-    presenceMapLock.unlock();\r
-    return onPresenceListener;\r
-}\r
-\r
-void RemoveOnPresenceListener(JNIEnv* env, jobject jListener)\r
-{\r
-    presenceMapLock.lock();\r
-    bool isFound = false;\r
-    for (auto it = onPresenceListenerMap.begin(); it != onPresenceListenerMap.end(); ++it)\r
-    {\r
-        if (env->IsSameObject(jListener, it->first))\r
-        {\r
-            auto refPair = it->second;\r
-            if (refPair.second > 1)\r
-            {\r
-                refPair.second--;\r
-                it->second = refPair;\r
-                onPresenceListenerMap.insert(*it);\r
-                LOGI("OnPresenceListener: ref. count decremented");\r
-            }\r
-            else\r
-            {\r
-                env->DeleteGlobalRef(it->first);\r
-                JniOnPresenceListener* listener = refPair.first;\r
-                delete listener;\r
-                onPresenceListenerMap.erase(it);\r
-                LOGI("OnPresenceListener is removed");\r
-            }\r
-            isFound = true;\r
-            break;\r
-        }\r
-    }\r
-    if (!isFound)\r
-    {\r
-        ThrowOcException(JNI_EXCEPTION, "OnPresenceListener not found");\r
-    }\r
-    presenceMapLock.unlock();\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    configure\r
-* Signature: (IILjava/lang/String;II)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure\r
-(JNIEnv *env, jclass clazz, jint jServiceType, jint jModeType, jstring jIpAddress, jint jPort, jint jQOS)\r
-{\r
-    LOGI("OcPlatform_configure");\r
-\r
-    std::string ipAddress;\r
-    if (jIpAddress)\r
-    {\r
-        ipAddress = env->GetStringUTFChars(jIpAddress, NULL);\r
-    }\r
-    uint16_t port;\r
-    if (jPort > 0)\r
-    {\r
-        port = static_cast<uint16_t>(jPort);\r
-    }\r
-    PlatformConfig cfg{\r
-        JniUtils::getServiceType(env, jServiceType),\r
-        JniUtils::getModeType(env, jModeType),\r
-        ipAddress,\r
-        port,\r
-        JniUtils::getQOS(env, static_cast<int>(jQOS))\r
-    };\r
-\r
-    OCPlatform::Configure(cfg);\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    notifyAllObservers0\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0\r
-(JNIEnv *env, jclass clazz, jobject jResourceHandle)\r
-{\r
-    LOGI("OcPlatform_notifyAllObservers");\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::notifyAllObservers(jniOcResourceHandle->getOCResourceHandle());\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to notify all observers");\r
-            return;\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    notifyAllObservers1\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;I)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1\r
-(JNIEnv *env, jclass clazz, jobject jResourceHandle, jint jQoS)\r
-{\r
-    LOGI("OcPlatform_notifyAllObservers1");\r
-\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    try{\r
-        OCStackResult result = OCPlatform::notifyAllObservers(\r
-            jniOcResourceHandle->getOCResourceHandle(),\r
-            JniUtils::getQOS(env, static_cast<int>(jQoS)));\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to notify all observers");\r
-            return;\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    notifyListOfObservers2\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2\r
-(JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse)\r
-{\r
-    LOGD("OcPlatform_notifyListOfObservers2");\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-    if (!jObservationIdArr)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null");\r
-        return;\r
-    }\r
-    if (!jResourceResponse)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    JniOcResourceResponse* jniOcResourceResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(\r
-        env, jResourceResponse);\r
-    if (!jniOcResourceResponse) return;\r
-\r
-    int len = env->GetArrayLength(jObservationIdArr);\r
-    uint8_t* bArr = (uint8_t*)env->GetByteArrayElements(jObservationIdArr, 0);\r
-\r
-    ObservationIds observationIds;\r
-    for (int i = 0; i < len; ++i)\r
-    {\r
-        observationIds.push_back(bArr[i]);\r
-    }\r
-\r
-    env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0);\r
-\r
-    try{\r
-        OCStackResult result = OCPlatform::notifyListOfObservers(\r
-            jniOcResourceHandle->getOCResourceHandle(),\r
-            observationIds,\r
-            jniOcResourceResponse->getOCResourceResponse());\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to notify all observers");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    notifyListOfObservers3\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;I)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3\r
-(JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse, jint jQoS)\r
-{\r
-    LOGD("OcPlatform_notifyListOfObservers3");\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-    if (!jObservationIdArr)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null");\r
-        return;\r
-    }\r
-    if (!jResourceResponse)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    JniOcResourceResponse* jniOcResourceResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(\r
-        env, jResourceResponse);\r
-    if (!jniOcResourceResponse) return;\r
-\r
-    int len = env->GetArrayLength(jObservationIdArr);\r
-    uint8_t* bArr = (uint8_t*)env->GetByteArrayElements(jObservationIdArr, 0);\r
-\r
-    ObservationIds observationIds;\r
-    for (int i = 0; i < len; ++i)\r
-    {\r
-        observationIds.push_back(bArr[i]);\r
-    }\r
-\r
-    env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0);\r
-\r
-    try{\r
-        OCStackResult result = OCPlatform::notifyListOfObservers(\r
-            jniOcResourceHandle->getOCResourceHandle(),\r
-            observationIds,\r
-            jniOcResourceResponse->getOCResourceResponse(),\r
-            JniUtils::getQOS(env, static_cast<int>(jQoS)));\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to notify all observers");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    findResource0\r
-* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0\r
-(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener)\r
-{\r
-    LOGD("OcPlatform_findResource");\r
-    std::string host;\r
-    if (jHost)\r
-    {\r
-        host = env->GetStringUTFChars(jHost, NULL);\r
-    }\r
-    std::string resourceUri;\r
-    if (jResourceUri)\r
-    {\r
-        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);\r
-    }\r
-    if (!jListener)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "onResourceFoundListener cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOnResourceFoundListener *onResFoundListener = AddOnResourceFoundListener(env, jListener);\r
-\r
-    FindCallback findCallback = [onResFoundListener](std::shared_ptr<OCResource> resource)\r
-    {\r
-        onResFoundListener->foundResourceCallback(resource);\r
-    };\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::findResource(\r
-            host,\r
-            resourceUri,\r
-            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),\r
-            findCallback);\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Find resource has failed");\r
-            return;\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    findResource1\r
-* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1\r
-(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS)\r
-{\r
-    LOGD("OcPlatform_findResource");\r
-    std::string host;\r
-    if (jHost)\r
-    {\r
-        host = env->GetStringUTFChars(jHost, NULL);\r
-    }\r
-    std::string resourceUri;\r
-    if (jResourceUri)\r
-    {\r
-        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);\r
-    }\r
-    if (!jListener)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "onResourceFoundListener cannot be null");\r
-        return;\r
-    }\r
-    JniOnResourceFoundListener *onResFoundListener = AddOnResourceFoundListener(env, jListener);\r
-\r
-    FindCallback findCallback = [onResFoundListener](std::shared_ptr<OCResource> resource)\r
-    {\r
-        onResFoundListener->foundResourceCallback(resource);\r
-    };\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::findResource(\r
-            host,\r
-            resourceUri,\r
-            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),\r
-            findCallback,\r
-            JniUtils::getQOS(env, static_cast<int>(jQoS)));\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Find resource has failed");\r
-            return;\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    getDeviceInfo0\r
-* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0\r
-(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener)\r
-{\r
-    LOGD("OcPlatform_getDeviceInfo0");\r
-    std::string host;\r
-    if (jHost)\r
-    {\r
-        host = env->GetStringUTFChars(jHost, NULL);\r
-    }\r
-    std::string resourceUri;\r
-    if (jResourceUri)\r
-    {\r
-        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);\r
-    }\r
-    if (!jListener)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeviceFoundListener cannot be null");\r
-        return;\r
-    }\r
-    JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener);\r
-\r
-    FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation)\r
-    {\r
-        onDeviceInfoListener->foundDeviceCallback(ocRepresentation);\r
-    };\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::getDeviceInfo(\r
-            host,\r
-            resourceUri,\r
-            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),\r
-            findDeviceCallback);\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Find device has failed");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    getDeviceInfo1\r
-* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;I)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1\r
-(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS)\r
-{\r
-    LOGD("OcPlatform_getDeviceInfo1");\r
-    std::string host;\r
-    if (jHost)\r
-    {\r
-        host = env->GetStringUTFChars(jHost, NULL);\r
-    }\r
-    std::string resourceUri;\r
-    if (jResourceUri)\r
-    {\r
-        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);\r
-    }\r
-    if (!jListener)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeviceFoundListener cannot be null");\r
-        return;\r
-    }\r
-    JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener);\r
-\r
-    FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation)\r
-    {\r
-        onDeviceInfoListener->foundDeviceCallback(ocRepresentation);\r
-    };\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::getDeviceInfo(\r
-            host,\r
-            resourceUri,\r
-            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),\r
-            findDeviceCallback,\r
-            JniUtils::getQOS(env, static_cast<int>(jQoS)));\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Find device has failed");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    registerResource0\r
-* Signature: (Lorg/iotivity/base/OcResource;)Lorg/iotivity/base/OcResourceHandle;\r
-*/\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0\r
-(JNIEnv *env, jclass clazz, jobject jResource)\r
-{\r
-    LOGD("OcPlatform_registerResource");\r
-    if (!jResource)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "Resource cannot be null");\r
-        return nullptr;\r
-    }\r
-    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, jResource);\r
-    if (!resource) return nullptr;\r
-\r
-    OCResourceHandle resourceHandle;\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::registerResource(\r
-            resourceHandle,\r
-            resource->getOCResource());\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "register resource");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-        return nullptr;\r
-    }\r
-\r
-    JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle);\r
-    jlong handle = reinterpret_cast<jlong>(jniHandle);\r
-    jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle);\r
-    if (!jResourceHandle)\r
-    {\r
-        LOGE("Failed to create OcResourceHandle");\r
-        delete jniHandle;\r
-    }\r
-    return jResourceHandle;\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    registerResource1\r
-* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcPlatform/EntityHandler;I)Lorg/iotivity/base/OcResourceHandle;\r
-*/\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource1\r
-(JNIEnv *env, jclass clazz, jstring jResourceUri, jstring jResourceTypeName, jstring jResourceInterface,\r
-jobject jListener, jint jResourceProperty)\r
-{\r
-    LOGI("OcPlatform_registerResource1");\r
-    std::string resourceUri;\r
-    if (jResourceUri)\r
-    {\r
-        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);\r
-    }\r
-    std::string resourceTypeName;\r
-    if (jResourceTypeName)\r
-    {\r
-        resourceTypeName = env->GetStringUTFChars(jResourceTypeName, NULL);\r
-    }\r
-    std::string resourceInterface;\r
-    if (jResourceInterface)\r
-    {\r
-        resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL);\r
-    }\r
-    if (!jListener)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "entityHandler cannot be null");\r
-        return nullptr;\r
-    }\r
-    JniEntityHandler* entityHandler = new JniEntityHandler(env, jListener);\r
-    EntityHandler handleEntityCallback = [entityHandler](const std::shared_ptr<OCResourceRequest> request) ->\r
-        OCEntityHandlerResult{\r
-        return entityHandler->handleEntity(request);\r
-    };\r
-\r
-    OCResourceHandle resourceHandle;\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::registerResource(\r
-            resourceHandle,\r
-            resourceUri,\r
-            resourceTypeName,\r
-            resourceInterface,\r
-            handleEntityCallback,\r
-            static_cast<int>(jResourceProperty));\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            delete entityHandler;\r
-            ThrowOcException(result, "register resource");\r
-            return nullptr;\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        delete entityHandler;\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-        return nullptr;\r
-    }\r
-\r
-    JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle);\r
-    jlong handle = reinterpret_cast<jlong>(jniHandle);\r
-    jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle);\r
-    if (!jResourceHandle)\r
-    {\r
-        LOGE("Failed to create OcResourceHandle");\r
-        delete jniHandle;\r
-    }\r
-\r
-    return jResourceHandle;\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    registerDeviceInfo0\r
-* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0\r
-(JNIEnv *env,\r
-jclass clazz,\r
-jstring jDeviceName)\r
-{\r
-    LOGI("OcPlatform_registerDeviceInfo");\r
-\r
-    std::string deviceName;\r
-    if (jDeviceName)\r
-    {\r
-        deviceName = env->GetStringUTFChars(jDeviceName, NULL);\r
-    }\r
-\r
-    OCDeviceInfo deviceInfo;\r
-    try\r
-    {\r
-        DuplicateString(&deviceInfo.deviceName, deviceName);\r
-    }\r
-    catch (std::exception &e)\r
-    {\r
-        ThrowOcException(JNI_EXCEPTION, "Failed to construct device info");\r
-        return;\r
-    }\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::registerDeviceInfo(deviceInfo);\r
-\r
-        delete deviceInfo.deviceName;\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to register device info");\r
-            return;\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    unregisterResource0\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unregisterResource0\r
-(JNIEnv *env, jclass clazz, jobject jResourceHandle)\r
-{\r
-    LOGI("OcPlatform_unregisterResource");\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    try\r
-    {\r
-        OCResourceHandle resHandle = jniOcResourceHandle->getOCResourceHandle();\r
-        OCStackResult result = OCPlatform::unregisterResource(resHandle);\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to unregister resource");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    bindResource0\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0\r
-(JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobject jResourceHandle)\r
-{\r
-    LOGI("OcPlatform_bindResource");\r
-    if (!jResourceCollectionHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null");\r
-        return;\r
-    }\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-    JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceCollectionHandle);\r
-    if (!jniOcResourceCollectionHandle) return;\r
-\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::bindResource(\r
-            jniOcResourceCollectionHandle->getOCResourceHandle(),\r
-            jniOcResourceHandle->getOCResourceHandle()\r
-            );\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to bind resource");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    bindResources0\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResources0\r
-(JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobjectArray jResourceHandleArray)\r
-{\r
-    LOGI("OcPlatform_bindResources");\r
-\r
-    if (!jResourceCollectionHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null");\r
-        return;\r
-    }\r
-    if (!jResourceHandleArray)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceCollectionHandle);\r
-    if (!jniOcResourceCollectionHandle) return;\r
-\r
-    std::vector<OCResourceHandle> resourceHandleList;\r
-    int len = env->GetArrayLength(jResourceHandleArray);\r
-    for (int i = 0; i < len; ++i)\r
-    {\r
-        jobject jResourceHandle = env->GetObjectArrayElement(jResourceHandleArray, i);\r
-        if (!jResourceHandle)\r
-        {\r
-            ThrowOcException(JNI_EXCEPTION, "resource handle cannot be null");\r
-            return;\r
-        }\r
-\r
-        JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-            env, jResourceHandle);\r
-        if (!jniOcResourceHandle) return;\r
-\r
-        resourceHandleList.push_back(\r
-            jniOcResourceHandle->getOCResourceHandle());\r
-    }\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::bindResources(\r
-            jniOcResourceCollectionHandle->getOCResourceHandle(),\r
-            resourceHandleList\r
-            );\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to bind resources");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    unbindResource0\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResource0\r
-(JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobject jResourceHandle)\r
-{\r
-    LOGI("OcPlatform_unbindResource");\r
-    if (!jResourceCollectionHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null");\r
-        return;\r
-    }\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceCollectionHandle);\r
-    if (!jniOcResourceCollectionHandle) return;\r
-\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::unbindResource(\r
-            jniOcResourceCollectionHandle->getOCResourceHandle(),\r
-            jniOcResourceHandle->getOCResourceHandle()\r
-            );\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to unbind resource");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    unbindResources0\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResources0\r
-(JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobjectArray jResourceHandleArray)\r
-{\r
-    LOGI("OcPlatform_unbindResources");\r
-    if (!jResourceCollectionHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null");\r
-        return;\r
-    }\r
-    if (!jResourceHandleArray)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceCollectionHandle);\r
-    if (!jniOcResourceCollectionHandle) return;\r
-\r
-    std::vector<OCResourceHandle> resourceHandleList;\r
-    int len = env->GetArrayLength(jResourceHandleArray);\r
-    for (int i = 0; i < len; ++i)\r
-    {\r
-        jobject jResourceHandle = env->GetObjectArrayElement(jResourceHandleArray, i);\r
-        if (!jResourceHandle)\r
-        {\r
-            ThrowOcException(JNI_EXCEPTION, "resource handle cannot be null");\r
-            return;\r
-        }\r
-\r
-        JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-            env, jResourceHandle);\r
-        if (!jniOcResourceHandle) return;\r
-\r
-        resourceHandleList.push_back(\r
-            jniOcResourceHandle->getOCResourceHandle());\r
-    }\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::unbindResources(\r
-            jniOcResourceCollectionHandle->getOCResourceHandle(),\r
-            resourceHandleList\r
-            );\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to unbind resources");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    bindTypeToResource0\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0\r
-(JNIEnv *env, jclass clazz, jobject jResourceHandle, jstring jResourceTypeName)\r
-{\r
-    LOGI("OcPlatform_bindTypeToResource");\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-    std::string typeName;\r
-    if (jResourceTypeName)\r
-    {\r
-        typeName = env->GetStringUTFChars(jResourceTypeName, NULL);\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::bindTypeToResource(\r
-            jniOcResourceHandle->getOCResourceHandle(),\r
-            typeName\r
-            );\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to bind type to resource");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    bindInterfaceToResource0\r
-* Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindInterfaceToResource0\r
-(JNIEnv *env, jclass clazz, jobject jResourceHandle, jstring jResourceInterfaceName)\r
-{\r
-    LOGI("OcPlatform_bindInterfaceToResource");\r
-    if (!jResourceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");\r
-        return;\r
-    }\r
-    std::string interfaceName;\r
-    if (jResourceInterfaceName)\r
-    {\r
-        interfaceName = env->GetStringUTFChars(jResourceInterfaceName, NULL);\r
-    }\r
-\r
-    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(\r
-        env, jResourceHandle);\r
-    if (!jniOcResourceHandle) return;\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::bindInterfaceToResource(\r
-            jniOcResourceHandle->getOCResourceHandle(),\r
-            interfaceName\r
-            );\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to bind interface to resource");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    startPresence0\r
-* Signature: (I)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_startPresence0\r
-(JNIEnv *env, jclass clazz, jint ttl)\r
-{\r
-    LOGI("OcPlatform_startPresence");\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::startPresence((unsigned int)ttl);\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to start presence");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    stopPresence0\r
-* Signature: ()V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_stopPresence0\r
-(JNIEnv *env, jclass clazz)\r
-{\r
-    LOGI("OcPlatform_stopPresence");\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::stopPresence();\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "Failed to stop presence");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    subscribePresence0\r
-* Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle;\r
-*/\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0\r
-(JNIEnv *env, jclass clazz, jstring jHost, jint jConnectivityType, jobject jListener)\r
-{\r
-    LOGD("OcPlatform_subscribePresence");\r
-    std::string host;\r
-    if (jHost)\r
-    {\r
-        host = env->GetStringUTFChars(jHost, NULL);\r
-    }\r
-    if (!jListener)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "onPresenceListener cannot be null");\r
-        return nullptr;\r
-    }\r
-\r
-    JniOnPresenceListener *onPresenceListener = AddOnPresenceListener(env, jListener);\r
-\r
-    SubscribeCallback subscribeCallback = [onPresenceListener](OCStackResult result, const unsigned int nonce,\r
-        const std::string& hostAddress)\r
-    {\r
-        onPresenceListener->onPresenceCallback(result, nonce, hostAddress);\r
-    };\r
-\r
-    OCPlatform::OCPresenceHandle presenceHandle;\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::subscribePresence(\r
-            presenceHandle,\r
-            host,\r
-            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),\r
-            subscribeCallback);\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "subscribe presence has failed");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-        return nullptr;\r
-    }\r
-\r
-    JniOcPresenceHandle* jniPresenceHandle = new JniOcPresenceHandle(onPresenceListener, presenceHandle);\r
-    jlong jhandle = reinterpret_cast<jlong>(jniPresenceHandle);\r
-    jobject jPresenceHandle = env->NewObject(g_cls_OcPresenceHandle, g_mid_OcPresenceHandle_N_ctor, jhandle);\r
-    if (!jPresenceHandle)\r
-    {\r
-        LOGE("Failed to create OcPresenceHandle");\r
-        delete jniPresenceHandle;\r
-    }\r
-\r
-    return jPresenceHandle;\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    subscribePresence1\r
-* Signature: (Ljava/lang/String;Ljava/lang/String;I\r
-Lorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle;\r
-*/\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1\r
-(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceType, jint jConnectivityType, jobject jListener)\r
-{\r
-    LOGD("OcPlatform_subscribePresence1");\r
-    std::string host;\r
-    if (jHost)\r
-    {\r
-        host = env->GetStringUTFChars(jHost, NULL);\r
-    }\r
-    std::string resourceType;\r
-    if (jResourceType)\r
-    {\r
-        resourceType = env->GetStringUTFChars(jResourceType, NULL);\r
-    }\r
-    if (!jListener)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "onPresenceListener cannot be null");\r
-        return nullptr;\r
-    }\r
-\r
-    JniOnPresenceListener *onPresenceListener = AddOnPresenceListener(env, jListener);\r
-\r
-    SubscribeCallback subscribeCallback = [onPresenceListener](OCStackResult result,\r
-        const unsigned int nonce, const std::string& hostAddress)\r
-    {\r
-        onPresenceListener->onPresenceCallback(result, nonce, hostAddress);\r
-    };\r
-\r
-    OCPlatform::OCPresenceHandle presenceHandle;\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::subscribePresence(\r
-            presenceHandle,\r
-            host,\r
-            resourceType,\r
-            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),\r
-            subscribeCallback);\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "subscribe presence has failed");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-        return nullptr;\r
-    }\r
-\r
-    JniOcPresenceHandle* jniPresenceHandle = new JniOcPresenceHandle(onPresenceListener, presenceHandle);\r
-    jlong jhandle = reinterpret_cast<jlong>(jniPresenceHandle);\r
-    jobject jPresenceHandle = env->NewObject(g_cls_OcPresenceHandle, g_mid_OcPresenceHandle_N_ctor, jhandle);\r
-    if (!jPresenceHandle)\r
-    {\r
-        LOGE("Failed to create OcPresenceHandle");\r
-        delete jniPresenceHandle;\r
-    }\r
-    return jPresenceHandle;\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    unsubscribePresence0\r
-* Signature: (Lorg/iotivity/base/OcPresenceHandle;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0\r
-(JNIEnv *env, jclass clazz, jobject jPresenceHandle)\r
-{\r
-    LOGD("OcPlatform_unsubscribePresence");\r
-    if (!jPresenceHandle)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "presenceHandle cannot be null");\r
-        return;\r
-    }\r
-    JniOcPresenceHandle* jniPresenceHandle = JniOcPresenceHandle::getJniOcPresenceHandlePtr(env, jPresenceHandle);\r
-    if (!jniPresenceHandle) return;\r
-\r
-    OCPresenceHandle presenceHandle = jniPresenceHandle->getOCPresenceHandle();\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::unsubscribePresence(presenceHandle);\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "unsubscribe presence has failed");\r
-            return;\r
-        }\r
-        jweak jwOnPresenceListener = jniPresenceHandle->getJniOnPresenceListener()->getJWListener();\r
-        if (jwOnPresenceListener)\r
-        {\r
-            RemoveOnPresenceListener(env, jwOnPresenceListener);\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    constructResourceObject0\r
-* Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;)\r
-Lorg/iotivity/base/OcResource;\r
-*/\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObject0\r
-(JNIEnv *env, jclass clazz, jstring jHost, jstring jUri, jint jConnectivityType,\r
-jboolean jIsObservable, jobjectArray jResourceTypeArray, jobjectArray jInterfaceArray)\r
-{\r
-    LOGD("OcPlatform_constructResourceObject");\r
-    std::string host;\r
-    if (jHost)\r
-    {\r
-        host = env->GetStringUTFChars(jHost, NULL);\r
-    }\r
-    std::string uri;\r
-    if (jUri)\r
-    {\r
-        uri = env->GetStringUTFChars(jUri, NULL);\r
-    }\r
-    if (!jResourceTypeArray)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null");\r
-        return nullptr;\r
-    }\r
-    if (!jInterfaceArray)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "interfaceList cannot be null");\r
-        return nullptr;\r
-    }\r
-\r
-    std::vector<std::string> resourceTypes;\r
-    JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);\r
-\r
-    std::vector<std::string> interfaces;\r
-    JniUtils::convertJavaStrArrToStrVector(env, jInterfaceArray, interfaces);\r
-\r
-    std::shared_ptr<OCResource> resource = OCPlatform::constructResourceObject(\r
-        host,\r
-        uri,\r
-        JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),\r
-        static_cast<bool>(jIsObservable),\r
-        resourceTypes,\r
-        interfaces);\r
-\r
-    if (!resource)\r
-    {\r
-        ThrowOcException(OC_STACK_ERROR, "Failed to create OCResource");\r
-        return nullptr;\r
-    }\r
-\r
-    JniOcResource *jniOcResource = new JniOcResource(resource);\r
-    jlong handle = reinterpret_cast<jlong>(jniOcResource);\r
-\r
-    jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor);\r
-    if (!jResource)\r
-    {\r
-        delete jniOcResource;\r
-        return nullptr;\r
-    }\r
-    SetHandle<JniOcResource>(env, jResource, jniOcResource);\r
-    if (env->ExceptionCheck())\r
-    {\r
-        delete jniOcResource;\r
-        return nullptr;\r
-    }\r
-    return jResource;\r
-}\r
-\r
-/*\r
-* Class:     org_iotivity_base_OcPlatform\r
-* Method:    sendResponse0\r
-* Signature: (Lorg/iotivity/base/OcResourceResponse;)V\r
-*/\r
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0\r
-(JNIEnv *env, jclass clazz, jobject jResourceResponse)\r
-{\r
-    LOGD("OcPlatform_sendResponse");\r
-    if (!jResourceResponse)\r
-    {\r
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null");\r
-        return;\r
-    }\r
-\r
-    JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(\r
-        env, jResourceResponse);\r
-    if (!jniResponse) return;\r
-\r
-    try\r
-    {\r
-        OCStackResult result = OCPlatform::sendResponse(jniResponse->getOCResourceResponse());\r
-\r
-        if (OC_STACK_OK != result)\r
-        {\r
-            ThrowOcException(result, "failed to send response");\r
-        }\r
-    }\r
-    catch (OCException& e)\r
-    {\r
-        LOGE("%s", e.reason().c_str());\r
-        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
-    }\r
-}
\ No newline at end of file
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Intel Corporation.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // 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 "JniOcPlatform.h"
+#include "OCPlatform.h"
+#include "JniOcResource.h"
+#include "JniOcResourceHandle.h"
+#include "JniOcPresenceHandle.h"
+#include "JniOcResourceResponse.h"
+#include "JniUtils.h"
+
+using namespace OC;
+
+JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener)
+{
+    JniOnResourceFoundListener *onResourceFoundListener = NULL;
+
+    resourceFoundMapLock.lock();
+
+    for (auto it = onResourceFoundListenerMap.begin(); it != onResourceFoundListenerMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            onResourceFoundListener = refPair.first;
+            refPair.second++;
+            it->second = refPair;
+            onResourceFoundListenerMap.insert(*it);
+            LOGD("OnResourceFoundListener: ref. count incremented");
+            break;
+        }
+    }
+
+    if (!onResourceFoundListener)
+    {
+        onResourceFoundListener = new JniOnResourceFoundListener(env, jListener, RemoveOnResourceFoundListener);
+        jobject jgListener = env->NewGlobalRef(jListener);
+
+        onResourceFoundListenerMap.insert(std::pair < jobject, std::pair < JniOnResourceFoundListener*,
+            int >> (jgListener, std::pair<JniOnResourceFoundListener*, int>(onResourceFoundListener, 1)));
+        LOGD("OnResourceFoundListener: new listener");
+    }
+    resourceFoundMapLock.unlock();
+    return onResourceFoundListener;
+}
+
+void RemoveOnResourceFoundListener(JNIEnv* env, jobject jListener)
+{
+    resourceFoundMapLock.lock();
+
+    for (auto it = onResourceFoundListenerMap.begin(); it != onResourceFoundListenerMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            if (refPair.second > 1)
+            {
+                refPair.second--;
+                it->second = refPair;
+                onResourceFoundListenerMap.insert(*it);
+                LOGI("OnResourceFoundListener: ref. count decremented");
+            }
+            else
+            {
+                env->DeleteGlobalRef(it->first);
+                JniOnResourceFoundListener* listener = refPair.first;
+                delete listener;
+                onResourceFoundListenerMap.erase(it);
+                LOGI("OnResourceFoundListener removed");
+            }
+            break;
+        }
+    }
+    resourceFoundMapLock.unlock();
+}
+
+JniOnDeviceInfoListener* AddOnDeviceInfoListener(JNIEnv* env, jobject jListener)
+{
+    JniOnDeviceInfoListener *onDeviceInfoListener = NULL;
+
+    deviceInfoMapLock.lock();
+
+    for (auto it = onDeviceInfoListenerMap.begin(); it != onDeviceInfoListenerMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            onDeviceInfoListener = refPair.first;
+            refPair.second++;
+            it->second = refPair;
+            onDeviceInfoListenerMap.insert(*it);
+            LOGD("OnDeviceInfoListener: ref. count incremented");
+            break;
+        }
+    }
+
+    if (!onDeviceInfoListener)
+    {
+        onDeviceInfoListener = new JniOnDeviceInfoListener(env, jListener, RemoveOnDeviceInfoListener);
+        jobject jgListener = env->NewGlobalRef(jListener);
+
+        onDeviceInfoListenerMap.insert(std::pair < jobject, std::pair < JniOnDeviceInfoListener*,
+            int >> (jgListener, std::pair<JniOnDeviceInfoListener*, int>(onDeviceInfoListener, 1)));
+        LOGI("OnDeviceInfoListener: new listener");
+    }
+
+    deviceInfoMapLock.unlock();
+    return onDeviceInfoListener;
+}
+
+void RemoveOnDeviceInfoListener(JNIEnv* env, jobject jListener)
+{
+    deviceInfoMapLock.lock();
+    bool isFound = false;
+    for (auto it = onDeviceInfoListenerMap.begin(); it != onDeviceInfoListenerMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            if (refPair.second > 1)
+            {
+                refPair.second--;
+                it->second = refPair;
+                onDeviceInfoListenerMap.insert(*it);
+                LOGI("OnDeviceInfoListener: ref. count decremented");
+            }
+            else
+            {
+                env->DeleteGlobalRef(it->first);
+                JniOnDeviceInfoListener* listener = refPair.first;
+                delete listener;
+                onDeviceInfoListenerMap.erase(it);
+
+                LOGI("OnDeviceInfoListener removed");
+            }
+
+            isFound = true;
+            break;
+        }
+    }
+
+    if (!isFound)
+    {
+        ThrowOcException(JNI_EXCEPTION, "OnDeviceInfoListenet not found");
+    }
+    deviceInfoMapLock.unlock();
+}
+
+JniOnPlatformInfoListener* AddOnPlatformInfoListener(JNIEnv* env, jobject jListener)
+{
+    JniOnPlatformInfoListener *onPlatformInfoListener = NULL;
+
+    platformInfoMapLock.lock();
+
+    for (auto it = onPlatformInfoListenerMap.begin(); it != onPlatformInfoListenerMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            onPlatformInfoListener = refPair.first;
+            refPair.second++;
+            it->second = refPair;
+            onPlatformInfoListenerMap.insert(*it);
+            LOGD("OnPlatformInfoListener: ref. count incremented");
+            break;
+        }
+    }
+
+    if (!onPlatformInfoListener)
+    {
+        onPlatformInfoListener = new JniOnPlatformInfoListener(env, jListener, RemoveOnPlatformInfoListener);
+        jobject jgListener = env->NewGlobalRef(jListener);
+
+        onPlatformInfoListenerMap.insert(std::pair < jobject, std::pair < JniOnPlatformInfoListener*,
+            int >> (jgListener, std::pair<JniOnPlatformInfoListener*, int>(onPlatformInfoListener, 1)));
+        LOGI("OnPlatformInfoListener: new listener");
+    }
+
+    platformInfoMapLock.unlock();
+    return onPlatformInfoListener;
+}
+
+void RemoveOnPlatformInfoListener(JNIEnv* env, jobject jListener)
+{
+    platformInfoMapLock.lock();
+    bool isFound = false;
+    for (auto it = onPlatformInfoListenerMap.begin(); it != onPlatformInfoListenerMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            if (refPair.second > 1)
+            {
+                refPair.second--;
+                it->second = refPair;
+                onPlatformInfoListenerMap.insert(*it);
+                LOGI("OnPlatformInfoListener: ref. count decremented");
+            }
+            else
+            {
+                env->DeleteGlobalRef(it->first);
+                JniOnPlatformInfoListener* listener = refPair.first;
+                delete listener;
+                onPlatformInfoListenerMap.erase(it);
+
+                LOGI("OnPlatformInfoListener removed");
+            }
+
+            isFound = true;
+            break;
+        }
+    }
+
+    if (!isFound)
+    {
+        ThrowOcException(JNI_EXCEPTION, "OnPlatformInfoListenet not found");
+    }
+    platformInfoMapLock.unlock();
+}
+
+JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener)
+{
+    JniOnPresenceListener *onPresenceListener = NULL;
+
+    presenceMapLock.lock();
+
+    for (auto it = onPresenceListenerMap.begin(); it != onPresenceListenerMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            onPresenceListener = refPair.first;
+            refPair.second++;
+            it->second = refPair;
+            onPresenceListenerMap.insert(*it);
+            LOGD("OnPresenceListener: ref. count incremented");
+            break;
+        }
+    }
+    if (!onPresenceListener)
+    {
+        onPresenceListener = new JniOnPresenceListener(env, jListener, RemoveOnPresenceListener);
+        jobject jgListener = env->NewGlobalRef(jListener);
+        onPresenceListenerMap.insert(std::pair < jobject, std::pair < JniOnPresenceListener*,
+            int >> (jgListener, std::pair<JniOnPresenceListener*, int>(onPresenceListener, 1)));
+        LOGI("OnPresenceListener: new listener");
+    }
+    presenceMapLock.unlock();
+    return onPresenceListener;
+}
+
+void RemoveOnPresenceListener(JNIEnv* env, jobject jListener)
+{
+    presenceMapLock.lock();
+    bool isFound = false;
+    for (auto it = onPresenceListenerMap.begin(); it != onPresenceListenerMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            if (refPair.second > 1)
+            {
+                refPair.second--;
+                it->second = refPair;
+                onPresenceListenerMap.insert(*it);
+                LOGI("OnPresenceListener: ref. count decremented");
+            }
+            else
+            {
+                env->DeleteGlobalRef(it->first);
+                JniOnPresenceListener* listener = refPair.first;
+                delete listener;
+                onPresenceListenerMap.erase(it);
+                LOGI("OnPresenceListener is removed");
+            }
+            isFound = true;
+            break;
+        }
+    }
+    if (!isFound)
+    {
+        ThrowOcException(JNI_EXCEPTION, "OnPresenceListener not found");
+    }
+    presenceMapLock.unlock();
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    configure
+* Signature: (IILjava/lang/String;II)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure
+(JNIEnv *env, jclass clazz, jint jServiceType, jint jModeType, jstring jIpAddress, jint jPort, jint jQOS)
+{
+    LOGI("OcPlatform_configure");
+
+    std::string ipAddress;
+    if (jIpAddress)
+    {
+        ipAddress = env->GetStringUTFChars(jIpAddress, NULL);
+    }
+    uint16_t port;
+    if (jPort > 0)
+    {
+        port = static_cast<uint16_t>(jPort);
+    }
+    PlatformConfig cfg{
+        JniUtils::getServiceType(env, jServiceType),
+        JniUtils::getModeType(env, jModeType),
+        ipAddress,
+        port,
+        JniUtils::getQOS(env, static_cast<int>(jQOS))
+    };
+
+    OCPlatform::Configure(cfg);
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    notifyAllObservers0
+* Signature: (Lorg/iotivity/base/OcResourceHandle;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0
+(JNIEnv *env, jclass clazz, jobject jResourceHandle)
+{
+    LOGI("OcPlatform_notifyAllObservers");
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    try
+    {
+        OCStackResult result = OCPlatform::notifyAllObservers(jniOcResourceHandle->getOCResourceHandle());
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to notify all observers");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    notifyAllObservers1
+* Signature: (Lorg/iotivity/base/OcResourceHandle;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1
+(JNIEnv *env, jclass clazz, jobject jResourceHandle, jint jQoS)
+{
+    LOGI("OcPlatform_notifyAllObservers1");
+
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    try{
+        OCStackResult result = OCPlatform::notifyAllObservers(
+            jniOcResourceHandle->getOCResourceHandle(),
+            JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to notify all observers");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    notifyListOfObservers2
+* Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2
+(JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse)
+{
+    LOGD("OcPlatform_notifyListOfObservers2");
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+    if (!jObservationIdArr)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null");
+        return;
+    }
+    if (!jResourceResponse)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null");
+        return;
+    }
+
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    JniOcResourceResponse* jniOcResourceResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(
+        env, jResourceResponse);
+    if (!jniOcResourceResponse) return;
+
+    int len = env->GetArrayLength(jObservationIdArr);
+    uint8_t* bArr = (uint8_t*)env->GetByteArrayElements(jObservationIdArr, 0);
+
+    ObservationIds observationIds;
+    for (int i = 0; i < len; ++i)
+    {
+        observationIds.push_back(bArr[i]);
+    }
+
+    env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0);
+
+    try{
+        OCStackResult result = OCPlatform::notifyListOfObservers(
+            jniOcResourceHandle->getOCResourceHandle(),
+            observationIds,
+            jniOcResourceResponse->getOCResourceResponse());
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to notify all observers");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    notifyListOfObservers3
+* Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3
+(JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse, jint jQoS)
+{
+    LOGD("OcPlatform_notifyListOfObservers3");
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+    if (!jObservationIdArr)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null");
+        return;
+    }
+    if (!jResourceResponse)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null");
+        return;
+    }
+
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    JniOcResourceResponse* jniOcResourceResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(
+        env, jResourceResponse);
+    if (!jniOcResourceResponse) return;
+
+    int len = env->GetArrayLength(jObservationIdArr);
+    uint8_t* bArr = (uint8_t*)env->GetByteArrayElements(jObservationIdArr, 0);
+
+    ObservationIds observationIds;
+    for (int i = 0; i < len; ++i)
+    {
+        observationIds.push_back(bArr[i]);
+    }
+
+    env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0);
+
+    try{
+        OCStackResult result = OCPlatform::notifyListOfObservers(
+            jniOcResourceHandle->getOCResourceHandle(),
+            observationIds,
+            jniOcResourceResponse->getOCResourceResponse(),
+            JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to notify all observers");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    findResource0
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener)
+{
+    LOGD("OcPlatform_findResource");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    std::string resourceUri;
+    if (jResourceUri)
+    {
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onResourceFoundListener cannot be null");
+        return;
+    }
+
+    JniOnResourceFoundListener *onResFoundListener = AddOnResourceFoundListener(env, jListener);
+
+    FindCallback findCallback = [onResFoundListener](std::shared_ptr<OCResource> resource)
+    {
+        onResFoundListener->foundResourceCallback(resource);
+    };
+
+    try
+    {
+        OCStackResult result = OCPlatform::findResource(
+            host,
+            resourceUri,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            findCallback);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Find resource has failed");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    findResource1
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS)
+{
+    LOGD("OcPlatform_findResource");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    std::string resourceUri;
+    if (jResourceUri)
+    {
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onResourceFoundListener cannot be null");
+        return;
+    }
+    JniOnResourceFoundListener *onResFoundListener = AddOnResourceFoundListener(env, jListener);
+
+    FindCallback findCallback = [onResFoundListener](std::shared_ptr<OCResource> resource)
+    {
+        onResFoundListener->foundResourceCallback(resource);
+    };
+
+    try
+    {
+        OCStackResult result = OCPlatform::findResource(
+            host,
+            resourceUri,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            findCallback,
+            JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Find resource has failed");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    getDeviceInfo0
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener)
+{
+    LOGD("OcPlatform_getDeviceInfo0");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    std::string resourceUri;
+    if (jResourceUri)
+    {
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeviceFoundListener cannot be null");
+        return;
+    }
+    JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener);
+
+    FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation)
+    {
+        onDeviceInfoListener->foundDeviceCallback(ocRepresentation);
+    };
+
+    try
+    {
+        OCStackResult result = OCPlatform::getDeviceInfo(
+            host,
+            resourceUri,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            findDeviceCallback);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Find device has failed");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    getDeviceInfo1
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS)
+{
+    LOGD("OcPlatform_getDeviceInfo1");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    std::string resourceUri;
+    if (jResourceUri)
+    {
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeviceFoundListener cannot be null");
+        return;
+    }
+    JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener);
+
+    FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation)
+    {
+        onDeviceInfoListener->foundDeviceCallback(ocRepresentation);
+    };
+
+    try
+    {
+        OCStackResult result = OCPlatform::getDeviceInfo(
+            host,
+            resourceUri,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            findDeviceCallback,
+            JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Find device has failed");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    getPlatformInfo0
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo0
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener)
+{
+    LOGD("OcPlatform_getPlatformInfo0");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    std::string resourceUri;
+    if (jResourceUri)
+    {
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null");
+        return;
+    }
+    JniOnPlatformInfoListener *onPlatformInfoListener = AddOnPlatformInfoListener(env, jListener);
+
+    FindPlatformCallback findPlatformCallback = [onPlatformInfoListener](const OCRepresentation& ocRepresentation)
+    {
+        onPlatformInfoListener->foundPlatformCallback(ocRepresentation);
+    };
+
+    try
+    {
+        OCStackResult result = OCPlatform::getPlatformInfo(
+            host,
+            resourceUri,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            findPlatformCallback);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Find platform has failed");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    getPlatformInfo1
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS)
+{
+    LOGD("OcPlatform_getPlatformInfo1");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    std::string resourceUri;
+    if (jResourceUri)
+    {
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null");
+        return;
+    }
+    JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener);
+
+    FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation)
+    {
+        onDeviceInfoListener->foundDeviceCallback(ocRepresentation);
+    };
+
+    try
+    {
+        OCStackResult result = OCPlatform::getPlatformInfo(
+            host,
+            resourceUri,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            findDeviceCallback,
+            JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Find platform has failed");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    registerResource0
+* Signature: (Lorg/iotivity/base/OcResource;)Lorg/iotivity/base/OcResourceHandle;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0
+(JNIEnv *env, jclass clazz, jobject jResource)
+{
+    LOGD("OcPlatform_registerResource");
+    if (!jResource)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "Resource cannot be null");
+        return nullptr;
+    }
+    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, jResource);
+    if (!resource) return nullptr;
+    LOGD("OcPlatform_registerResource1");
+    OCResourceHandle resourceHandle;
+    try
+    {
+        LOGD("OcPlatform_registerResource2");
+        OCStackResult result = OCPlatform::registerResource(
+            resourceHandle,
+            resource->getOCResource());
+        LOGD("OcPlatform_registerResource3");
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "register resource");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+        return nullptr;
+    }
+    LOGD("OcPlatform_registerResource4");
+    JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle);
+    jlong handle = reinterpret_cast<jlong>(jniHandle);
+    jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle);
+    LOGD("OcPlatform_registerResource5");
+    if (!jResourceHandle)
+    {
+        LOGE("Failed to create OcResourceHandle");
+        delete jniHandle;
+    }
+    return jResourceHandle;
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    registerResource1
+* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcPlatform/EntityHandler;I)Lorg/iotivity/base/OcResourceHandle;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource1
+(JNIEnv *env, jclass clazz, jstring jResourceUri, jstring jResourceTypeName, jstring jResourceInterface,
+jobject jListener, jint jResourceProperty)
+{
+    LOGI("OcPlatform_registerResource1");
+    std::string resourceUri;
+    if (jResourceUri)
+    {
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+    }
+    std::string resourceTypeName;
+    if (jResourceTypeName)
+    {
+        resourceTypeName = env->GetStringUTFChars(jResourceTypeName, NULL);
+    }
+    std::string resourceInterface;
+    if (jResourceInterface)
+    {
+        resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "entityHandler cannot be null");
+        return nullptr;
+    }
+    JniEntityHandler* entityHandler = new JniEntityHandler(env, jListener);
+    EntityHandler handleEntityCallback = [entityHandler](const std::shared_ptr<OCResourceRequest> request) ->
+        OCEntityHandlerResult{
+        return entityHandler->handleEntity(request);
+    };
+
+    OCResourceHandle resourceHandle;
+    try
+    {
+        OCStackResult result = OCPlatform::registerResource(
+            resourceHandle,
+            resourceUri,
+            resourceTypeName,
+            resourceInterface,
+            handleEntityCallback,
+            static_cast<int>(jResourceProperty));
+
+        if (OC_STACK_OK != result)
+        {
+            delete entityHandler;
+            ThrowOcException(result, "register resource");
+            return nullptr;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        delete entityHandler;
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+        return nullptr;
+    }
+
+    JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle);
+    jlong handle = reinterpret_cast<jlong>(jniHandle);
+    jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle);
+    if (!jResourceHandle)
+    {
+        LOGE("Failed to create OcResourceHandle");
+        delete jniHandle;
+    }
+
+    return jResourceHandle;
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    registerDeviceInfo0
+* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0
+(JNIEnv *env,
+jclass clazz,
+jstring jDeviceName)
+{
+    LOGI("OcPlatform_registerDeviceInfo");
+
+    std::string deviceName;
+    if (jDeviceName)
+    {
+        deviceName = env->GetStringUTFChars(jDeviceName, NULL);
+    }
+
+    OCDeviceInfo deviceInfo;
+    try
+    {
+        DuplicateString(&deviceInfo.deviceName, deviceName);
+    }
+    catch (std::exception &e)
+    {
+        ThrowOcException(JNI_EXCEPTION, "Failed to construct device info");
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = OCPlatform::registerDeviceInfo(deviceInfo);
+
+        delete deviceInfo.deviceName;
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to register device info");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    registerPlatformInfo0
+* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerPlatformInfo0
+(JNIEnv *env,
+jclass clazz,
+jstring jPlatformID,
+jstring jManufacturerName,
+jstring jManufacturerUrl,
+jstring jModelNumber,
+jstring jDateOfManufacture,
+jstring jPlatformVersion,
+jstring jOperatingSystemVersion,
+jstring jHardwareVersion,
+jstring jFirmwareVersion,
+jstring jSupportUrl,
+jstring jSystemTime)
+{
+    LOGI("OcPlatform_registerPlatformInfo");
+
+
+    std::string platformID;
+        std::string manufacturerName;
+        std::string manufacturerUrl;
+        std::string modelNumber;
+        std::string dateOfManufacture;
+        std::string platformVersion;
+        std::string operatingSystemVersion;
+        std::string hardwareVersion;
+        std::string firmwareVersion;
+        std::string supportUrl;
+        std::string systemTime;
+
+        if (jPlatformID)
+        {
+            platformID = env->GetStringUTFChars(jPlatformID, NULL);
+        }
+        if (jManufacturerName)
+        {
+            manufacturerName = env->GetStringUTFChars(jManufacturerName, NULL);
+        }
+        if (jManufacturerUrl)
+        {
+            manufacturerUrl = env->GetStringUTFChars(jManufacturerUrl, NULL);
+        }
+        if (jModelNumber)
+        {
+            modelNumber = env->GetStringUTFChars(jModelNumber, NULL);
+        }
+        if (jDateOfManufacture)
+        {
+            dateOfManufacture = env->GetStringUTFChars(jDateOfManufacture, NULL);
+        }
+        if (jPlatformVersion)
+        {
+            platformVersion = env->GetStringUTFChars(jPlatformVersion, NULL);
+        }
+        if (jOperatingSystemVersion)
+        {
+            operatingSystemVersion = env->GetStringUTFChars(jOperatingSystemVersion, NULL);
+        }
+        if (jHardwareVersion)
+        {
+            hardwareVersion = env->GetStringUTFChars(jHardwareVersion, NULL);
+        }
+        if (jFirmwareVersion)
+        {
+            firmwareVersion = env->GetStringUTFChars(jFirmwareVersion, NULL);
+        }
+        if (jSupportUrl)
+        {
+            supportUrl = env->GetStringUTFChars(jSupportUrl, NULL);
+        }
+        if (jSystemTime)
+        {
+            systemTime = env->GetStringUTFChars(jSystemTime, NULL);
+        }
+
+        OCPlatformInfo platformInfo;
+        try
+        {
+            DuplicateString(&platformInfo.platformID, platformID);
+            DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+            DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+            DuplicateString(&platformInfo.modelNumber, modelNumber);
+            DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+            DuplicateString(&platformInfo.platformVersion, platformVersion);
+            DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+            DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+            DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+            DuplicateString(&platformInfo.supportUrl, supportUrl);
+            DuplicateString(&platformInfo.systemTime, systemTime);
+        }
+        catch (std::exception &e)
+        {
+            ThrowOcException(JNI_EXCEPTION, "Failed to construct platform info");
+            return;
+        }
+
+       // __android_log_print(ANDROID_LOG_INFO, "Rahul", "platformID  = %s", platformID);
+        try
+        {
+            OCStackResult result = OCPlatform::registerPlatformInfo(platformInfo);
+
+            delete platformInfo.platformID;
+            delete platformInfo.manufacturerName;
+            delete platformInfo.manufacturerUrl;
+            delete platformInfo.modelNumber;
+            delete platformInfo.dateOfManufacture;
+            delete platformInfo.platformVersion;
+            delete platformInfo.operatingSystemVersion;
+            delete platformInfo.hardwareVersion;
+            delete platformInfo.firmwareVersion;
+            delete platformInfo.supportUrl;
+            delete platformInfo.systemTime;
+
+            if (OC_STACK_OK != result)
+            {
+                ThrowOcException(result, "Failed to register platform info");
+                return;
+            }
+        }
+        catch (OCException& e)
+        {
+            LOGE("Error is due to %s", e.reason().c_str());
+            ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+        }
+
+
+
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    unregisterResource0
+* Signature: (Lorg/iotivity/base/OcResourceHandle;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unregisterResource0
+(JNIEnv *env, jclass clazz, jobject jResourceHandle)
+{
+    LOGI("OcPlatform_unregisterResource");
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    try
+    {
+        OCResourceHandle resHandle = jniOcResourceHandle->getOCResourceHandle();
+        OCStackResult result = OCPlatform::unregisterResource(resHandle);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to unregister resource");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    bindResource0
+* Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0
+(JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobject jResourceHandle)
+{
+    LOGI("OcPlatform_bindResource");
+    if (!jResourceCollectionHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null");
+        return;
+    }
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+    JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceCollectionHandle);
+    if (!jniOcResourceCollectionHandle) return;
+
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    try
+    {
+        OCStackResult result = OCPlatform::bindResource(
+            jniOcResourceCollectionHandle->getOCResourceHandle(),
+            jniOcResourceHandle->getOCResourceHandle()
+            );
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to bind resource");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    bindResources0
+* Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResources0
+(JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobjectArray jResourceHandleArray)
+{
+    LOGI("OcPlatform_bindResources");
+
+    if (!jResourceCollectionHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null");
+        return;
+    }
+    if (!jResourceHandleArray)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null");
+        return;
+    }
+
+    JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceCollectionHandle);
+    if (!jniOcResourceCollectionHandle) return;
+
+    std::vector<OCResourceHandle> resourceHandleList;
+    int len = env->GetArrayLength(jResourceHandleArray);
+    for (int i = 0; i < len; ++i)
+    {
+        jobject jResourceHandle = env->GetObjectArrayElement(jResourceHandleArray, i);
+        if (!jResourceHandle)
+        {
+            ThrowOcException(JNI_EXCEPTION, "resource handle cannot be null");
+            return;
+        }
+
+        JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+            env, jResourceHandle);
+        if (!jniOcResourceHandle) return;
+
+        resourceHandleList.push_back(
+            jniOcResourceHandle->getOCResourceHandle());
+    }
+
+    try
+    {
+        OCStackResult result = OCPlatform::bindResources(
+            jniOcResourceCollectionHandle->getOCResourceHandle(),
+            resourceHandleList
+            );
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to bind resources");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    unbindResource0
+* Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResource0
+(JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobject jResourceHandle)
+{
+    LOGI("OcPlatform_unbindResource");
+    if (!jResourceCollectionHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null");
+        return;
+    }
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+
+    JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceCollectionHandle);
+    if (!jniOcResourceCollectionHandle) return;
+
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    try
+    {
+        OCStackResult result = OCPlatform::unbindResource(
+            jniOcResourceCollectionHandle->getOCResourceHandle(),
+            jniOcResourceHandle->getOCResourceHandle()
+            );
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to unbind resource");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    unbindResources0
+* Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResources0
+(JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobjectArray jResourceHandleArray)
+{
+    LOGI("OcPlatform_unbindResources");
+    if (!jResourceCollectionHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null");
+        return;
+    }
+    if (!jResourceHandleArray)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null");
+        return;
+    }
+
+    JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceCollectionHandle);
+    if (!jniOcResourceCollectionHandle) return;
+
+    std::vector<OCResourceHandle> resourceHandleList;
+    int len = env->GetArrayLength(jResourceHandleArray);
+    for (int i = 0; i < len; ++i)
+    {
+        jobject jResourceHandle = env->GetObjectArrayElement(jResourceHandleArray, i);
+        if (!jResourceHandle)
+        {
+            ThrowOcException(JNI_EXCEPTION, "resource handle cannot be null");
+            return;
+        }
+
+        JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+            env, jResourceHandle);
+        if (!jniOcResourceHandle) return;
+
+        resourceHandleList.push_back(
+            jniOcResourceHandle->getOCResourceHandle());
+    }
+
+    try
+    {
+        OCStackResult result = OCPlatform::unbindResources(
+            jniOcResourceCollectionHandle->getOCResourceHandle(),
+            resourceHandleList
+            );
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to unbind resources");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    bindTypeToResource0
+* Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0
+(JNIEnv *env, jclass clazz, jobject jResourceHandle, jstring jResourceTypeName)
+{
+    LOGI("OcPlatform_bindTypeToResource");
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+    std::string typeName;
+    if (jResourceTypeName)
+    {
+        typeName = env->GetStringUTFChars(jResourceTypeName, NULL);
+    }
+
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    try
+    {
+        OCStackResult result = OCPlatform::bindTypeToResource(
+            jniOcResourceHandle->getOCResourceHandle(),
+            typeName
+            );
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to bind type to resource");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    bindInterfaceToResource0
+* Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindInterfaceToResource0
+(JNIEnv *env, jclass clazz, jobject jResourceHandle, jstring jResourceInterfaceName)
+{
+    LOGI("OcPlatform_bindInterfaceToResource");
+    if (!jResourceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
+        return;
+    }
+    std::string interfaceName;
+    if (jResourceInterfaceName)
+    {
+        interfaceName = env->GetStringUTFChars(jResourceInterfaceName, NULL);
+    }
+
+    JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
+        env, jResourceHandle);
+    if (!jniOcResourceHandle) return;
+
+    try
+    {
+        OCStackResult result = OCPlatform::bindInterfaceToResource(
+            jniOcResourceHandle->getOCResourceHandle(),
+            interfaceName
+            );
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to bind interface to resource");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    startPresence0
+* Signature: (I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_startPresence0
+(JNIEnv *env, jclass clazz, jint ttl)
+{
+    LOGI("OcPlatform_startPresence");
+
+    try
+    {
+        OCStackResult result = OCPlatform::startPresence((unsigned int)ttl);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to start presence");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    stopPresence0
+* Signature: ()V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_stopPresence0
+(JNIEnv *env, jclass clazz)
+{
+    LOGI("OcPlatform_stopPresence");
+
+    try
+    {
+        OCStackResult result = OCPlatform::stopPresence();
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to stop presence");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    subscribePresence0
+* Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0
+(JNIEnv *env, jclass clazz, jstring jHost, jint jConnectivityType, jobject jListener)
+{
+    LOGD("OcPlatform_subscribePresence");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPresenceListener cannot be null");
+        return nullptr;
+    }
+
+    JniOnPresenceListener *onPresenceListener = AddOnPresenceListener(env, jListener);
+
+    SubscribeCallback subscribeCallback = [onPresenceListener](OCStackResult result, const unsigned int nonce,
+        const std::string& hostAddress)
+    {
+        onPresenceListener->onPresenceCallback(result, nonce, hostAddress);
+    };
+
+    OCPlatform::OCPresenceHandle presenceHandle;
+    try
+    {
+        OCStackResult result = OCPlatform::subscribePresence(
+            presenceHandle,
+            host,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            subscribeCallback);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "subscribe presence has failed");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+        return nullptr;
+    }
+
+    JniOcPresenceHandle* jniPresenceHandle = new JniOcPresenceHandle(onPresenceListener, presenceHandle);
+    jlong jhandle = reinterpret_cast<jlong>(jniPresenceHandle);
+    jobject jPresenceHandle = env->NewObject(g_cls_OcPresenceHandle, g_mid_OcPresenceHandle_N_ctor, jhandle);
+    if (!jPresenceHandle)
+    {
+        LOGE("Failed to create OcPresenceHandle");
+        delete jniPresenceHandle;
+    }
+    return jPresenceHandle;
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    subscribePresence1
+* Signature: (Ljava/lang/String;Ljava/lang/String;I
+Lorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceType, jint jConnectivityType, jobject jListener)
+{
+    LOGD("OcPlatform_subscribePresence1");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    std::string resourceType;
+    if (jResourceType)
+    {
+        resourceType = env->GetStringUTFChars(jResourceType, NULL);
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPresenceListener cannot be null");
+        return nullptr;
+    }
+
+    JniOnPresenceListener *onPresenceListener = AddOnPresenceListener(env, jListener);
+
+    SubscribeCallback subscribeCallback = [onPresenceListener](OCStackResult result,
+        const unsigned int nonce, const std::string& hostAddress)
+    {
+        onPresenceListener->onPresenceCallback(result, nonce, hostAddress);
+    };
+
+    OCPlatform::OCPresenceHandle presenceHandle;
+    try
+    {
+        OCStackResult result = OCPlatform::subscribePresence(
+            presenceHandle,
+            host,
+            resourceType,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            subscribeCallback);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "subscribe presence has failed");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+        return nullptr;
+    }
+
+    JniOcPresenceHandle* jniPresenceHandle = new JniOcPresenceHandle(onPresenceListener, presenceHandle);
+    jlong jhandle = reinterpret_cast<jlong>(jniPresenceHandle);
+    jobject jPresenceHandle = env->NewObject(g_cls_OcPresenceHandle, g_mid_OcPresenceHandle_N_ctor, jhandle);
+    if (!jPresenceHandle)
+    {
+        LOGE("Failed to create OcPresenceHandle");
+        delete jniPresenceHandle;
+    }
+    return jPresenceHandle;
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    unsubscribePresence0
+* Signature: (Lorg/iotivity/base/OcPresenceHandle;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0
+(JNIEnv *env, jclass clazz, jobject jPresenceHandle)
+{
+    LOGD("OcPlatform_unsubscribePresence");
+    if (!jPresenceHandle)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "presenceHandle cannot be null");
+        return;
+    }
+    JniOcPresenceHandle* jniPresenceHandle = JniOcPresenceHandle::getJniOcPresenceHandlePtr(env, jPresenceHandle);
+    if (!jniPresenceHandle) return;
+
+    OCPresenceHandle presenceHandle = jniPresenceHandle->getOCPresenceHandle();
+
+    try
+    {
+        OCStackResult result = OCPlatform::unsubscribePresence(presenceHandle);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "unsubscribe presence has failed");
+            return;
+        }
+        jweak jwOnPresenceListener = jniPresenceHandle->getJniOnPresenceListener()->getJWListener();
+        if (jwOnPresenceListener)
+        {
+            RemoveOnPresenceListener(env, jwOnPresenceListener);
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    constructResourceObject0
+* Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;)
+Lorg/iotivity/base/OcResource;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObject0
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jUri, jint jConnectivityType,
+jboolean jIsObservable, jobjectArray jResourceTypeArray, jobjectArray jInterfaceArray)
+{
+    LOGD("OcPlatform_constructResourceObject");
+    std::string host;
+    if (jHost)
+    {
+        host = env->GetStringUTFChars(jHost, NULL);
+    }
+    std::string uri;
+    if (jUri)
+    {
+        uri = env->GetStringUTFChars(jUri, NULL);
+    }
+    if (!jResourceTypeArray)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null");
+        return nullptr;
+    }
+    if (!jInterfaceArray)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "interfaceList cannot be null");
+        return nullptr;
+    }
+
+    std::vector<std::string> resourceTypes;
+    JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);
+
+    std::vector<std::string> interfaces;
+    JniUtils::convertJavaStrArrToStrVector(env, jInterfaceArray, interfaces);
+
+    std::shared_ptr<OCResource> resource = OCPlatform::constructResourceObject(
+        host,
+        uri,
+        JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+        static_cast<bool>(jIsObservable),
+        resourceTypes,
+        interfaces);
+
+    if (!resource)
+    {
+        ThrowOcException(OC_STACK_ERROR, "Failed to create OCResource");
+        return nullptr;
+    }
+
+    JniOcResource *jniOcResource = new JniOcResource(resource);
+    jlong handle = reinterpret_cast<jlong>(jniOcResource);
+
+    jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor);
+    if (!jResource)
+    {
+        delete jniOcResource;
+        return nullptr;
+    }
+    SetHandle<JniOcResource>(env, jResource, jniOcResource);
+    if (env->ExceptionCheck())
+    {
+        delete jniOcResource;
+        return nullptr;
+    }
+    return jResource;
+}
+
+/*
+* Class:     org_iotivity_base_OcPlatform
+* Method:    sendResponse0
+* Signature: (Lorg/iotivity/base/OcResourceResponse;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0
+(JNIEnv *env, jclass clazz, jobject jResourceResponse)
+{
+    LOGD("OcPlatform_sendResponse");
+    if (!jResourceResponse)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null");
+        return;
+    }
+
+    JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(
+        env, jResourceResponse);
+    if (!jniResponse) return;
+
+    try
+    {
+        OCStackResult result = OCPlatform::sendResponse(jniResponse->getOCResourceResponse());
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "failed to send response");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
index 1019147..62c9938 100644 (file)
-/*\r
-* //******************************************************************\r
-* //\r
-* // Copyright 2015 Intel Corporation.\r
-* //\r
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-* //\r
-* // Licensed under the Apache License, Version 2.0 (the "License");\r
-* // you may not use this file except in compliance with the License.\r
-* // You may obtain a copy of the License at\r
-* //\r
-* //      http://www.apache.org/licenses/LICENSE-2.0\r
-* //\r
-* // Unless required by applicable law or agreed to in writing, software\r
-* // distributed under the License is distributed on an "AS IS" BASIS,\r
-* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* // See the License for the specific language governing permissions and\r
-* // limitations under the License.\r
-* //\r
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-*/\r
-#include "JniOcStack.h"\r
-#include "JniOnResourceFoundListener.h"\r
-#include "JniOnDeviceInfoListener.h"\r
-#include "JniOnPresenceListener.h"\r
-#include <mutex>\r
-\r
-#ifndef _Included_org_iotivity_base_OcPlatform\r
-#define _Included_org_iotivity_base_OcPlatform\r
-\r
-using namespace OC;\r
-\r
-JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener);\r
-void RemoveOnResourceFoundListener(JNIEnv* env, jobject jListener);\r
-\r
-JniOnDeviceInfoListener* AddOnDeviceInfoListener(JNIEnv* env, jobject jListener);\r
-void RemoveOnDeviceInfoListener(JNIEnv* env, jobject jListener);\r
-\r
-JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener);\r
-void RemoveOnPresenceListener(JNIEnv* env, jobject jListener);\r
-\r
-std::map<jobject, std::pair<JniOnResourceFoundListener*, int>> onResourceFoundListenerMap;\r
-std::map<jobject, std::pair<JniOnDeviceInfoListener*, int>> onDeviceInfoListenerMap;\r
-std::map<jobject, std::pair<JniOnPresenceListener*, int>> onPresenceListenerMap;\r
-\r
-std::mutex resourceFoundMapLock;\r
-std::mutex deviceInfoMapLock;\r
-std::mutex presenceMapLock;\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    configure\r
-    * Signature: (IILjava/lang/String;II)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure\r
-        (JNIEnv *, jclass, jint, jint, jstring, jint, jint);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    notifyAllObservers0\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0\r
-        (JNIEnv *, jclass, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    notifyAllObservers1\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;I)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1\r
-        (JNIEnv *, jclass, jobject, jint);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    notifyListOfObservers2\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;[BLorg/iotivity/base/OcResourceResponse;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2\r
-        (JNIEnv *, jclass, jobject, jbyteArray, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    notifyListOfObservers3\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;[BLorg/iotivity/base/OcResourceResponse;I)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3\r
-        (JNIEnv *, jclass, jobject, jbyteArray, jobject, jint);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    findResource0\r
-    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0\r
-        (JNIEnv *, jclass, jstring, jstring, jint, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    findResource1\r
-    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1\r
-        (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    getDeviceInfo0\r
-    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0\r
-        (JNIEnv *, jclass, jstring, jstring, jint, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    getDeviceInfo1\r
-    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;I)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1\r
-        (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    registerResource0\r
-    * Signature: (Lorg/iotivity/base/OcResource;)Lorg/iotivity/base/OcResourceHandle;\r
-    */\r
-    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0\r
-        (JNIEnv *, jclass, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    registerResource1\r
-    * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcPlatform/EntityHandler;I)Lorg/iotivity/base/OcResourceHandle;\r
-    */\r
-    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource1\r
-        (JNIEnv *, jclass, jstring, jstring, jstring, jobject, jint);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    registerDeviceInfo0\r
-    * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0\r
-        (JNIEnv *, jclass, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    unregisterResource0\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unregisterResource0\r
-        (JNIEnv *, jclass, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    bindResource0\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0\r
-        (JNIEnv *, jclass, jobject, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    bindResources0\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResources0\r
-        (JNIEnv *, jclass, jobject, jobjectArray);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    unbindResource0\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResource0\r
-        (JNIEnv *, jclass, jobject, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    unbindResources0\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResources0\r
-        (JNIEnv *, jclass, jobject, jobjectArray);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    bindTypeToResource0\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0\r
-        (JNIEnv *, jclass, jobject, jstring);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    bindInterfaceToResource0\r
-    * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindInterfaceToResource0\r
-        (JNIEnv *, jclass, jobject, jstring);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    startPresence0\r
-    * Signature: (I)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_startPresence0\r
-        (JNIEnv *, jclass, jint);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    stopPresence0\r
-    * Signature: ()V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_stopPresence0\r
-        (JNIEnv *, jclass);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    subscribePresence0\r
-    * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle;\r
-    */\r
-    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0\r
-        (JNIEnv *, jclass, jstring, jint, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    subscribePresence1\r
-    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle;\r
-    */\r
-    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1\r
-        (JNIEnv *, jclass, jstring, jstring, jint, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    unsubscribePresence0\r
-    * Signature: (Lorg/iotivity/base/OcPresenceHandle;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0\r
-        (JNIEnv *, jclass, jobject);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform\r
-    * Method:    constructResourceObject0\r
-    * Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;)Lorg/iotivity/base/OcResource;\r
-    */\r
-    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObject0\r
-        (JNIEnv *, jclass, jstring, jstring, jint, jboolean, jobjectArray, jobjectArray);\r
-\r
-    /*\r
-    * Class:     org_iotivity_base_OcPlatform0\r
-    * Method:    sendResponse0\r
-    * Signature: (Lorg/iotivity/base/OcResourceResponse;)V\r
-    */\r
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0\r
-        (JNIEnv *, jclass, jobject);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-#endif\r
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Intel Corporation.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // 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 "JniOcStack.h"
+#include "JniOnResourceFoundListener.h"
+#include "JniOnDeviceInfoListener.h"
+#include "JniOnPlatformInfoListener.h"
+#include "JniOnPresenceListener.h"
+#include <mutex>
+
+#ifndef _Included_org_iotivity_base_OcPlatform
+#define _Included_org_iotivity_base_OcPlatform
+
+using namespace OC;
+
+JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener);
+void RemoveOnResourceFoundListener(JNIEnv* env, jobject jListener);
+
+JniOnDeviceInfoListener* AddOnDeviceInfoListener(JNIEnv* env, jobject jListener);
+void RemoveOnDeviceInfoListener(JNIEnv* env, jobject jListener);
+
+JniOnPlatformInfoListener* AddOnPlatformInfoListener(JNIEnv* env, jobject jListener);
+void RemoveOnPlatformInfoListener(JNIEnv* env, jobject jListener);
+
+JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener);
+void RemoveOnPresenceListener(JNIEnv* env, jobject jListener);
+
+std::map<jobject, std::pair<JniOnResourceFoundListener*, int>> onResourceFoundListenerMap;
+std::map<jobject, std::pair<JniOnDeviceInfoListener*, int>> onDeviceInfoListenerMap;
+std::map<jobject, std::pair<JniOnPlatformInfoListener*, int>> onPlatformInfoListenerMap;
+std::map<jobject, std::pair<JniOnPresenceListener*, int>> onPresenceListenerMap;
+
+std::mutex resourceFoundMapLock;
+std::mutex deviceInfoMapLock;
+std::mutex platformInfoMapLock;
+std::mutex presenceMapLock;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    configure
+    * Signature: (IILjava/lang/String;II)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure
+        (JNIEnv *, jclass, jint, jint, jstring, jint, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    notifyAllObservers0
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0
+        (JNIEnv *, jclass, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    notifyAllObservers1
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1
+        (JNIEnv *, jclass, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    notifyListOfObservers2
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;[BLorg/iotivity/base/OcResourceResponse;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2
+        (JNIEnv *, jclass, jobject, jbyteArray, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    notifyListOfObservers3
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;[BLorg/iotivity/base/OcResourceResponse;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3
+        (JNIEnv *, jclass, jobject, jbyteArray, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    findResource0
+    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0
+        (JNIEnv *, jclass, jstring, jstring, jint, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    findResource1
+    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1
+        (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    getDeviceInfo0
+    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0
+        (JNIEnv *, jclass, jstring, jstring, jint, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    getDeviceInfo1
+    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1
+        (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint);
+
+    /*
+     * Class:     org_iotivity_base_OcPlatform
+     * Method:    getPlatformInfo0
+     * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;)V
+     */
+     JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo0
+        (JNIEnv *, jclass, jstring, jstring, jint, jobject);
+
+    /*
+     * Class:     org_iotivity_base_OcPlatform
+     * Method:    getPlatformInfo1
+     * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;I)V
+     */
+     JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1
+        (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    registerResource0
+    * Signature: (Lorg/iotivity/base/OcResource;)Lorg/iotivity/base/OcResourceHandle;
+    */
+    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0
+        (JNIEnv *, jclass, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    registerResource1
+    * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcPlatform/EntityHandler;I)Lorg/iotivity/base/OcResourceHandle;
+    */
+    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource1
+        (JNIEnv *, jclass, jstring, jstring, jstring, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    registerDeviceInfo0
+    * Signature: (Ljava/lang/String;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0
+        (JNIEnv *, jclass, jstring);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    registerPlatformInfo0
+    * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerPlatformInfo0
+        (JNIEnv *, jclass, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    unregisterResource0
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unregisterResource0
+        (JNIEnv *, jclass, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    bindResource0
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0
+        (JNIEnv *, jclass, jobject, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    bindResources0
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResources0
+        (JNIEnv *, jclass, jobject, jobjectArray);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    unbindResource0
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResource0
+        (JNIEnv *, jclass, jobject, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    unbindResources0
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResources0
+        (JNIEnv *, jclass, jobject, jobjectArray);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    bindTypeToResource0
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0
+        (JNIEnv *, jclass, jobject, jstring);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    bindInterfaceToResource0
+    * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindInterfaceToResource0
+        (JNIEnv *, jclass, jobject, jstring);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    startPresence0
+    * Signature: (I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_startPresence0
+        (JNIEnv *, jclass, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    stopPresence0
+    * Signature: ()V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_stopPresence0
+        (JNIEnv *, jclass);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    subscribePresence0
+    * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle;
+    */
+    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0
+        (JNIEnv *, jclass, jstring, jint, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    subscribePresence1
+    * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle;
+    */
+    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1
+        (JNIEnv *, jclass, jstring, jstring, jint, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    unsubscribePresence0
+    * Signature: (Lorg/iotivity/base/OcPresenceHandle;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0
+        (JNIEnv *, jclass, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform
+    * Method:    constructResourceObject0
+    * Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;)Lorg/iotivity/base/OcResource;
+    */
+    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObject0
+        (JNIEnv *, jclass, jstring, jstring, jint, jboolean, jobjectArray, jobjectArray);
+
+    /*
+    * Class:     org_iotivity_base_OcPlatform0
+    * Method:    sendResponse0
+    * Signature: (Lorg/iotivity/base/OcResourceResponse;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0
+        (JNIEnv *, jclass, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
diff --git a/android/android_api/base/jni/JniOnPlatformInfoListener.cpp b/android/android_api/base/jni/JniOnPlatformInfoListener.cpp
new file mode 100644 (file)
index 0000000..27ecf74
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Intel Corporation.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // 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 "JniOnPlatformInfoListener.h"
+#include "JniOcRepresentation.h"
+
+JniOnPlatformInfoListener::JniOnPlatformInfoListener(JNIEnv *env, jobject jListener,
+    RemoveListenerCallback removeListenerCallback)
+{
+    m_jwListener = env->NewWeakGlobalRef(jListener);
+    m_removeListenerCallback = removeListenerCallback;
+}
+
+JniOnPlatformInfoListener::~JniOnPlatformInfoListener()
+{
+    LOGI("~JniOnPlatformInfoListener");
+    if (m_jwListener)
+    {
+        jint ret;
+        JNIEnv *env = GetJNIEnv(ret);
+        if (NULL == env) return;
+        env->DeleteWeakGlobalRef(m_jwListener);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    }
+}
+
+void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation& ocRepresentation)
+{
+    jint ret;
+    JNIEnv *env = GetJNIEnv(ret);
+    if (NULL == env) return;
+
+    jobject jListener = env->NewLocalRef(m_jwListener);
+    if (!jListener)
+    {
+        LOGI("Java onPlatformInfoListener object is already destroyed, quiting");
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    OCRepresentation* rep = new OCRepresentation(ocRepresentation);
+    jlong handle = reinterpret_cast<jlong>(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;
+    }
+
+    jclass clsL = env->GetObjectClass(jListener);
+    if (!clsL)
+    {
+        delete rep;
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+    jmethodID midL = env->GetMethodID(clsL, "onPlatformFound", "(Lorg/iotivity/base/OcRepresentation;)V");
+    if (!midL)
+    {
+        delete rep;
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    env->CallVoidMethod(jListener, midL, jRepresentation);
+    if (env->ExceptionCheck())
+    {
+        LOGE("Java exception is thrown");
+        delete rep;
+        checkExAndRemoveListener(env);
+    }
+
+    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniOnPlatformInfoListener::checkExAndRemoveListener(JNIEnv* env)
+{
+    if (env->ExceptionCheck())
+    {
+        jthrowable ex = env->ExceptionOccurred();
+        env->ExceptionClear();
+        m_removeListenerCallback(env, m_jwListener);
+        env->Throw((jthrowable)ex);
+    }
+    else
+    {
+        m_removeListenerCallback(env, m_jwListener);
+    }
+}
+
diff --git a/android/android_api/base/jni/JniOnPlatformInfoListener.h b/android/android_api/base/jni/JniOnPlatformInfoListener.h
new file mode 100644 (file)
index 0000000..ebc3c09
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Intel Corporation.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // 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 <jni.h>
+#include "JniOcStack.h"
+
+#ifndef _Included_org_iotivity_base_OcPlatform_OnPlatformFoundListener
+#define _Included_org_iotivity_base_OcPlatform_OnPlatformFoundListener
+
+class JniOnPlatformInfoListener
+{
+public:
+    JniOnPlatformInfoListener(JNIEnv *env, jobject jListener, RemoveListenerCallback removeListener);
+    ~JniOnPlatformInfoListener();
+
+    void foundPlatformCallback(const OC::OCRepresentation& ocRepresentation);
+
+private:
+    jweak m_jwListener;
+    RemoveListenerCallback m_removeListenerCallback;
+    void checkExAndRemoveListener(JNIEnv* env);
+};
+
+#endif
index 31a1a1d..596d2ca 100644 (file)
@@ -984,6 +984,56 @@ public class SmokeTest extends InstrumentationTestCase {
         }
     }
 
+    public void testPlatformInfo() throws InterruptedException {
+        final String resourceType = "unit.test.resource" + new Date().getTime();
+        final CountDownLatch signal = new CountDownLatch(1);
+
+        OcPlatform.OnPlatformFoundListener platformFoundListener = new OcPlatform.OnPlatformFoundListener() {
+            @Override
+            public void onPlatformFound(OcRepresentation ocRepresentation) {
+                Log.i(TAG, "Platform Info Received: ");
+                Log.i(TAG, "URI: " + ocRepresentation.getUri());
+                signal.countDown();
+            }
+        };
+
+        OcPlatformInfo platformInfo = null;
+        try {
+            platformInfo = new OcPlatformInfo("myPlatformID", "myManuName", "myManuUrl");
+        } catch (OcException e) {
+            Log.e(TAG, "Could not construct platformInfo. " + e.getMessage());
+            assertTrue(false);
+        }
+
+        platformInfo.setModelNumber("myModelNumber");
+        platformInfo.setDateOfManufacture("myDateOfManufacture");
+        platformInfo.setPlatformVersion("myPlatformVersion");
+        platformInfo.setOperatingSystemVersion("myOperatingSystemVersion");
+        platformInfo.setHardwareVersion("myHardwareVersion");
+        platformInfo.setFirmwareVersion("myFirmwareVersion");
+        platformInfo.setSupportUrl("mySupportUrl");
+        platformInfo.setSystemTime("mySystemTime");
+
+        try {
+            //server
+
+            OcPlatform.registerPlatformInfo(platformInfo);
+
+            //client
+            OcPlatform.getPlatformInfo(
+                    "",
+                    OcPlatform.MULTICAST_PREFIX + "/oic/p",
+                    OcConnectivityType.IPV4,
+                    platformFoundListener);
+
+            //wait for onPlatformFound event
+            assertTrue(signal.await(60, TimeUnit.SECONDS));
+        } catch (OcException e) {
+            Log.e(TAG, e.getMessage() + platformInfo.toString());
+            assertTrue(false);
+        }
+    }
+
 //    public void testRegisterDeviceInfoGetDeviceInfo() throws InterruptedException {
 //        final String resourceType = "unit.test.resource" + new Date().getTime();
 //        final CountDownLatch signal = new CountDownLatch(1);
index d1862e0..b83e4b3 100644 (file)
-/*\r
- * //******************************************************************\r
- * //\r
- * // Copyright 2015 Intel Corporation.\r
- * //\r
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- * //\r
- * // Licensed under the Apache License, Version 2.0 (the "License");\r
- * // you may not use this file except in compliance with the License.\r
- * // You may obtain a copy of the License at\r
- * //\r
- * //      http://www.apache.org/licenses/LICENSE-2.0\r
- * //\r
- * // Unless required by applicable law or agreed to in writing, software\r
- * // distributed under the License is distributed on an "AS IS" BASIS,\r
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * // See the License for the specific language governing permissions and\r
- * // limitations under the License.\r
- * //\r
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- */\r
-\r
-package org.iotivity.base;\r
-\r
-public enum ErrorCode {\r
-    /* Success status code - START HERE */\r
-    OK("OK", ""),\r
-    RESOURCE_CREATED("RESOURCE_CREATED", ""),\r
-    RESOURCE_DELETED("RESOURCE_DELETED", ""),\r
-    CONTINUE("CONTINUE", ""),\r
-    /* Success status code - END HERE */\r
-        /* Error status code - START HERE */\r
-    INVALID_URI("INVALID_URI", ""),\r
-    INVALID_QUERY("INVALID_QUERY", ""),\r
-    INVALID_IP("INVALID_IP", ""),\r
-    INVALID_PORT("INVALID_PORT", ""),\r
-    INVALID_CALLBACK("INVALID_CALLBACK", ""),\r
-    INVALID_METHOD("INVALID_METHOD", ""),\r
-    INVALID_PARAM("INVALID_PARAM", ""),\r
-    INVALID_OBSERVE_PARAM("INVALID_OBSERVE_PARAM", ""),\r
-    NO_MEMORY("NO_MEMORY", ""),\r
-    COMM_ERROR("COMM_ERROR", ""),\r
-    NOT_IMPL("NOTIMPL", ""),\r
-    NO_RESOURCE("NO_RESOURCE", "Resource not found"),\r
-    RESOURCE_ERROR("RESOURCE_ERROR", "Not supported method or interface"),\r
-    SLOW_RESOURCE("SLOW_RESOURCE", ""),\r
-    NO_OBSERVERS("NO_OBSERVERS", "Resource has no registered observers"),\r
-    OBSERVER_NOT_FOUND("OBSERVER_NOT_FOUND", ""),\r
-    PRESENCE_STOPPED("PRESENCE_STOPPED", ""),\r
-    PRESENCE_TIMEOUT("PRESENCE_TIMEOUT", ""),\r
-    PRESENCE_DO_NOT_HANDLE("PRESENCE_DO_NOT_HANDLE", ""),\r
-    VIRTUAL_DO_NOT_HANDLE("VIRTUAL_DO_NOT_HANDLE", ""),\r
-    INVALID_OPTION("INVALID_OPTION", ""),\r
-    MALFORMED_RESPONSE("MALFORMED_RESPONSE", "Remote reply contained malformed data"),\r
-    PERSISTENT_BUFFER_REQUIRED("PERSISTENT_BUFFER_REQUIRED", ""),\r
-    INVALID_REQUEST_HANDLE("INVALID_REQUEST_HANDLE", ""),\r
-    INVALID_DEVICE_INFO("INVALID_DEVICE_INFO", ""),\r
-    ERROR("ERROR", "Generic error"),\r
-\r
-    JNI_EXCEPTION("JNI_EXCEPTION", "Generic Java binder error"),\r
-    JNI_NO_NATIVE_OBJECT("JNI_NO_NATIVE_OBJECT", ""),\r
-    JNI_INVALID_VALUE("JNI_INVALID_VALUE", ""),\r
-\r
-    INVALID_CLASS_CAST("INVALID_CLASS_CAST", ""),;\r
-\r
-    private String error;\r
-    private String description;\r
-\r
-    private ErrorCode(String error, String description) {\r
-        this.error = error;\r
-        this.description = description;\r
-    }\r
-\r
-    public String getError() {\r
-        return error;\r
-    }\r
-\r
-    public String getDescription() {\r
-        return description;\r
-    }\r
-\r
-    public static ErrorCode get(String errorCode) {\r
-        for (ErrorCode eCode : ErrorCode.values()) {\r
-            if (eCode.getError().equals(errorCode)) {\r
-                return eCode;\r
-            }\r
-        }\r
-        throw new IllegalArgumentException("Unexpected ErrorCode value");\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return error + (description.isEmpty() ? "" : " : " + description);\r
-    }\r
-}\r
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // 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.base;
+
+public enum ErrorCode {
+    /* Success status code - START HERE */
+    OK("OK", ""),
+    RESOURCE_CREATED("RESOURCE_CREATED", ""),
+    RESOURCE_DELETED("RESOURCE_DELETED", ""),
+    CONTINUE("CONTINUE", ""),
+    /* Success status code - END HERE */
+        /* Error status code - START HERE */
+    INVALID_URI("INVALID_URI", ""),
+    INVALID_QUERY("INVALID_QUERY", ""),
+    INVALID_IP("INVALID_IP", ""),
+    INVALID_PORT("INVALID_PORT", ""),
+    INVALID_CALLBACK("INVALID_CALLBACK", ""),
+    INVALID_METHOD("INVALID_METHOD", ""),
+    INVALID_PARAM("INVALID_PARAM", ""),
+    INVALID_OBSERVE_PARAM("INVALID_OBSERVE_PARAM", ""),
+    NO_MEMORY("NO_MEMORY", ""),
+    COMM_ERROR("COMM_ERROR", ""),
+    NOT_IMPL("NOTIMPL", ""),
+    NO_RESOURCE("NO_RESOURCE", "Resource not found"),
+    RESOURCE_ERROR("RESOURCE_ERROR", "Not supported method or interface"),
+    SLOW_RESOURCE("SLOW_RESOURCE", ""),
+    NO_OBSERVERS("NO_OBSERVERS", "Resource has no registered observers"),
+    OBSERVER_NOT_FOUND("OBSERVER_NOT_FOUND", ""),
+    PRESENCE_STOPPED("PRESENCE_STOPPED", ""),
+    PRESENCE_TIMEOUT("PRESENCE_TIMEOUT", ""),
+    PRESENCE_DO_NOT_HANDLE("PRESENCE_DO_NOT_HANDLE", ""),
+    VIRTUAL_DO_NOT_HANDLE("VIRTUAL_DO_NOT_HANDLE", ""),
+    INVALID_OPTION("INVALID_OPTION", ""),
+    MALFORMED_RESPONSE("MALFORMED_RESPONSE", "Remote reply contained malformed data"),
+    PERSISTENT_BUFFER_REQUIRED("PERSISTENT_BUFFER_REQUIRED", ""),
+    INVALID_REQUEST_HANDLE("INVALID_REQUEST_HANDLE", ""),
+    INVALID_DEVICE_INFO("INVALID_DEVICE_INFO", ""),
+    INVALID_PLATFORM_INFO_PLATFORMID("INVALID_PLATFORM_INFO_PLATFORMID",
+            "PlatformID cannot be null or empty"),
+    INVALID_PLATFORM_INFO_MANUFACTURER_NAME("INVALID_PLATFORM_INFO_MANUFACTURER_NAME",
+            "ManufacturerName cannot be null, empty or greater than " +
+                    OcStackConfig.MAX_MANUFACTURER_NAME_LENGTH + " characters long"),
+    INVALID_PLATFORM_INFO_PLATFORMID_MANUFACTURER_URL("INVALID_PLATFORM_INFO_MANUFACTURER_URL",
+            "MANUFACTURER_URL cannot be null, empty or greater than " +
+                    OcStackConfig.MAX_MANUFACTURER_URL_LENGTH + " characters long"),
+    ERROR("ERROR", "Generic error"),
+
+    JNI_EXCEPTION("JNI_EXCEPTION", "Generic Java binder error"),
+    JNI_NO_NATIVE_OBJECT("JNI_NO_NATIVE_OBJECT", ""),
+    JNI_INVALID_VALUE("JNI_INVALID_VALUE", ""),
+
+    INVALID_CLASS_CAST("INVALID_CLASS_CAST", ""),;
+
+    private String error;
+    private String description;
+
+    private ErrorCode(String error, String description) {
+        this.error = error;
+        this.description = description;
+    }
+
+    public String getError() {
+        return error;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public static ErrorCode get(String errorCode) {
+        for (ErrorCode eCode : ErrorCode.values()) {
+            if (eCode.getError().equals(errorCode)) {
+                return eCode;
+            }
+        }
+        throw new IllegalArgumentException("Unexpected ErrorCode value");
+    }
+
+    @Override
+    public String toString() {
+        return error + (description.isEmpty() ? "" : " : " + description);
+    }
+}
index ac17a5b..891d487 100644 (file)
-/*\r
- * //******************************************************************\r
- * //\r
- * // Copyright 2015 Intel Corporation.\r
- * //\r
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- * //\r
- * // Licensed under the Apache License, Version 2.0 (the "License");\r
- * // you may not use this file except in compliance with the License.\r
- * // You may obtain a copy of the License at\r
- * //\r
- * //      http://www.apache.org/licenses/LICENSE-2.0\r
- * //\r
- * // Unless required by applicable law or agreed to in writing, software\r
- * // distributed under the License is distributed on an "AS IS" BASIS,\r
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * // See the License for the specific language governing permissions and\r
- * // limitations under the License.\r
- * //\r
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- */\r
-\r
-package org.iotivity.base;\r
-\r
-import org.iotivity.ca.CaInterface;\r
-\r
-import java.util.EnumSet;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-/**\r
- * Contains the main entrance/functionality of the product. To set a custom configuration, the\r
- * implementer must make a call to OcPlatform.Configure before the first usage of a function in this\r
- * class.\r
- */\r
-public final class OcPlatform {\r
-\r
-    static {\r
-        System.loadLibrary("oc_logger");\r
-        System.loadLibrary("octbstack");\r
-        System.loadLibrary("connectivity_abstraction");\r
-        System.loadLibrary("oc");\r
-        System.loadLibrary("ocstack-jni");\r
-    }\r
-\r
-    /**\r
-     * Default interface\r
-     */\r
-    public static final String DEFAULT_INTERFACE = "oic.if.baseline";\r
-\r
-    /**\r
-     * Used in discovering (GET) links to other resources of a collection\r
-     */\r
-    public static final String LINK_INTERFACE = "oic.if.ll";\r
-\r
-    /**\r
-     * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection\r
-     */\r
-    public static final String BATCH_INTERFACE = "oic.if.b";\r
-\r
-    /**\r
-     * Used in GET, PUT, POST methods on links to other remote resources of a group\r
-     */\r
-    public static final String GROUP_INTERFACE = "oic.mi.grp";\r
-\r
-    public static final String WELL_KNOWN_QUERY = "224.0.1.187:5683/oic/res";\r
-    public static final String MULTICAST_PREFIX = "224.0.1.187:5683";\r
-    public static final String MULTICAST_IP = "224.0.1.187";\r
-    public static final int MULTICAST_PORT = 5683;\r
-    public static final int DEFAULT_PRESENCE_TTL = 60;\r
-    public static final String DEVICE_URI = "/oic/d";\r
-    public static final String PRESENCE_URI = "/oic/ad";\r
-\r
-    private static volatile boolean sIsPlatformInitialized = false;\r
-\r
-    private OcPlatform() {\r
-    }\r
-\r
-    /**\r
-     * API for setting the configuration of the OcPlatform.\r
-     * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect\r
-     *\r
-     * @param platformConfig platform configuration\r
-     */\r
-    public synchronized static void Configure(PlatformConfig platformConfig) {\r
-        if (!sIsPlatformInitialized) {\r
-            CaInterface.initialize(platformConfig.getContext());\r
-\r
-            OcPlatform.configure(\r
-                    platformConfig.getServiceType().getValue(),\r
-                    platformConfig.getModeType().getValue(),\r
-                    platformConfig.getIpAddress(),\r
-                    platformConfig.getPort(),\r
-                    platformConfig.getQualityOfService().getValue()\r
-            );\r
-\r
-            sIsPlatformInitialized = true;\r
-        }\r
-    }\r
-\r
-    private static native void configure(int serviceType,\r
-                                         int modeType,\r
-                                         String ipAddress,\r
-                                         int port,\r
-                                         int qualityOfService);\r
-\r
-    /**\r
-     * API for notifying base that resource's attributes have changed.\r
-     *\r
-     * @param ocResourceHandle resource handle of the resource\r
-     * @throws OcException\r
-     */\r
-    public static void notifyAllObservers(\r
-            OcResourceHandle ocResourceHandle) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.notifyAllObservers0(ocResourceHandle);\r
-    }\r
-\r
-    private static native void notifyAllObservers0(\r
-            OcResourceHandle ocResourceHandle) throws OcException;\r
-\r
-    /**\r
-     * API for notifying base that resource's attributes have changed.\r
-     *\r
-     * @param ocResourceHandle resource handle of the resource\r
-     * @param qualityOfService the quality of communication\r
-     * @throws OcException\r
-     */\r
-    public static void notifyAllObservers(\r
-            OcResourceHandle ocResourceHandle,\r
-            QualityOfService qualityOfService) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());\r
-    }\r
-\r
-    private static native void notifyAllObservers1(\r
-            OcResourceHandle ocResourceHandle,\r
-            int qualityOfService) throws OcException;\r
-\r
-    /**\r
-     * API for notifying only specific clients that resource's attributes have changed.\r
-     *\r
-     * @param ocResourceHandle    resource handle of the resource\r
-     * @param ocObservationIdList These set of ids are ones which which will be notified upon\r
-     *                            resource change.\r
-     * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for\r
-     *                            this resource change\r
-     * @throws OcException\r
-     */\r
-    public static void notifyListOfObservers(\r
-            OcResourceHandle ocResourceHandle,\r
-            List<Byte> ocObservationIdList,\r
-            OcResourceResponse ocResourceResponse) throws OcException {\r
-        OcPlatform.initCheck();\r
-\r
-        byte[] idArr = new byte[ocObservationIdList.size()];\r
-        Iterator<Byte> it = ocObservationIdList.iterator();\r
-        int i = 0;\r
-        while (it.hasNext()) {\r
-            idArr[i++] = (byte) it.next();\r
-        }\r
-\r
-        OcPlatform.notifyListOfObservers2(\r
-                ocResourceHandle,\r
-                idArr,\r
-                ocResourceResponse);\r
-    }\r
-\r
-    private static native void notifyListOfObservers2(\r
-            OcResourceHandle ocResourceHandle,\r
-            byte[] ocObservationIdArray,\r
-            OcResourceResponse ocResourceResponse) throws OcException;\r
-\r
-    /**\r
-     * API for notifying only specific clients that resource's attributes have changed.\r
-     *\r
-     * @param ocResourceHandle    resource handle of the resource\r
-     * @param ocObservationIdList These set of ids are ones which which will be notified upon\r
-     *                            resource change.\r
-     * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for\r
-     *                            this resource change\r
-     * @param qualityOfService    the quality of communication\r
-     * @throws OcException\r
-     */\r
-    public static void notifyListOfObservers(\r
-            OcResourceHandle ocResourceHandle,\r
-            List<Byte> ocObservationIdList,\r
-            OcResourceResponse ocResourceResponse,\r
-            QualityOfService qualityOfService) throws OcException {\r
-        OcPlatform.initCheck();\r
-\r
-        byte[] idArr = new byte[ocObservationIdList.size()];\r
-        Iterator<Byte> it = ocObservationIdList.iterator();\r
-        int i = 0;\r
-        while (it.hasNext()) {\r
-            idArr[i++] = (byte) it.next();\r
-        }\r
-\r
-        OcPlatform.notifyListOfObservers3(\r
-                ocResourceHandle,\r
-                idArr,\r
-                ocResourceResponse,\r
-                qualityOfService.getValue()\r
-        );\r
-    }\r
-\r
-    private static native void notifyListOfObservers3(\r
-            OcResourceHandle ocResourceHandle,\r
-            byte[] ocObservationIdArray,\r
-            OcResourceResponse ocResourceResponse,\r
-            int qualityOfService) throws OcException;\r
-\r
-    /**\r
-     * API for Service and Resource Discovery. NOTE: This API applies to client side only\r
-     *\r
-     * @param host                    Host IP Address of a service to direct resource discovery query.\r
-     *                                If empty, performs multicast resource discovery query\r
-     * @param resourceUri             name of the resource. If null or empty, performs search for all\r
-     *                                resource names\r
-     * @param connectivityType        a type of connectivity indicating the interface. Example: IPV4,\r
-     *                                IPV6, ALL\r
-     * @param onResourceFoundListener Handles events, success states and failure states.\r
-     * @throws OcException\r
-     */\r
-    public static void findResource(\r
-            String host,\r
-            String resourceUri,\r
-            OcConnectivityType connectivityType,\r
-            OnResourceFoundListener onResourceFoundListener) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.findResource0(\r
-                host,\r
-                resourceUri,\r
-                connectivityType.getValue(),\r
-                onResourceFoundListener\r
-        );\r
-    }\r
-\r
-    private static native void findResource0(\r
-            String host,\r
-            String resourceUri,\r
-            int connectivityType,\r
-            OnResourceFoundListener onResourceFoundListener) throws OcException;\r
-\r
-    /**\r
-     * API for Service and Resource Discovery. NOTE: This API applies to client side only\r
-     *\r
-     * @param host                    Host IP Address of a service to direct resource discovery query.\r
-     *                                If empty, performs multicast resource discovery query\r
-     * @param resourceUri             name of the resource. If null or empty, performs search for all\r
-     *                                resource names\r
-     * @param connectivityType        a type of connectivity indicating the interface. Example: IPV4,\r
-     *                                IPV6, ALL\r
-     * @param onResourceFoundListener Handles events, success states and failure states.\r
-     * @param qualityOfService        the quality of communication\r
-     * @throws OcException\r
-     */\r
-    public static void findResource(\r
-            String host,\r
-            String resourceUri,\r
-            OcConnectivityType connectivityType,\r
-            OnResourceFoundListener onResourceFoundListener,\r
-            QualityOfService qualityOfService) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.findResource1(host,\r
-                resourceUri,\r
-                connectivityType.getValue(),\r
-                onResourceFoundListener,\r
-                qualityOfService.getValue()\r
-        );\r
-    }\r
-\r
-    private static native void findResource1(\r
-            String host,\r
-            String resourceUri,\r
-            int connectivityType,\r
-            OnResourceFoundListener onResourceFoundListener,\r
-            int qualityOfService) throws OcException;\r
-\r
-    /**\r
-     * API for Device Discovery\r
-     *\r
-     * @param host                  Host IP Address. If null or empty, Multicast is performed.\r
-     * @param deviceUri             Uri containing address to the virtual device\r
-     * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,\r
-     *                              IPV6, ALL\r
-     * @param onDeviceFoundListener Handles events, success states and failure states.\r
-     * @throws OcException\r
-     */\r
-    public static void getDeviceInfo(\r
-            String host,\r
-            String deviceUri,\r
-            OcConnectivityType connectivityType,\r
-            OnDeviceFoundListener onDeviceFoundListener) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.getDeviceInfo0(\r
-                host,\r
-                deviceUri,\r
-                connectivityType.getValue(),\r
-                onDeviceFoundListener\r
-        );\r
-    }\r
-\r
-    private static native void getDeviceInfo0(\r
-            String host,\r
-            String deviceUri,\r
-            int connectivityType,\r
-            OnDeviceFoundListener onDeviceFoundListener) throws OcException;\r
-\r
-    /**\r
-     * API for Device Discovery\r
-     *\r
-     * @param host                  Host IP Address. If null or empty, Multicast is performed.\r
-     * @param deviceUri             Uri containing address to the virtual device\r
-     * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,\r
-     *                              IPV6, ALL\r
-     * @param onDeviceFoundListener Handles events, success states and failure states.\r
-     * @param qualityOfService      the quality of communication\r
-     * @throws OcException\r
-     */\r
-    public static void getDeviceInfo(\r
-            String host,\r
-            String deviceUri,\r
-            OcConnectivityType connectivityType,\r
-            OnDeviceFoundListener onDeviceFoundListener,\r
-            QualityOfService qualityOfService) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.getDeviceInfo1(\r
-                host,\r
-                deviceUri,\r
-                connectivityType.getValue(),\r
-                onDeviceFoundListener,\r
-                qualityOfService.getValue()\r
-        );\r
-    }\r
-\r
-    private static native void getDeviceInfo1(\r
-            String host,\r
-            String deviceUri,\r
-            int connectivityType,\r
-            OnDeviceFoundListener onDeviceFoundListener,\r
-            int qualityOfService) throws OcException;\r
-\r
-    /**\r
-     * This API registers a resource with the server NOTE: This API applies to server side only.\r
-     *\r
-     * @param ocResource The instance of OcResource with all data filled\r
-     * @return resource handle\r
-     * @throws OcException\r
-     */\r
-    public static OcResourceHandle registerResource(\r
-            OcResource ocResource) throws OcException {\r
-        OcPlatform.initCheck();\r
-        return OcPlatform.registerResource0(ocResource);\r
-    }\r
-\r
-    private static native OcResourceHandle registerResource0(\r
-            OcResource ocResource) throws OcException;\r
-\r
-    /**\r
-     * This API registers a resource with the server NOTE: This API applies to server side only.\r
-     *\r
-     * @param resourceUri         The URI of the resource. Example: "a/light"\r
-     * @param resourceTypeName    The resource type. Example: "light"\r
-     * @param resourceInterface   The resource interface (whether it is collection etc).\r
-     * @param entityHandler       entity handler.\r
-     * @param resourcePropertySet indicates the property of the resource\r
-     * @return resource handle\r
-     * @throws OcException\r
-     */\r
-    public static OcResourceHandle registerResource(\r
-            String resourceUri,\r
-            String resourceTypeName,\r
-            String resourceInterface,\r
-            EntityHandler entityHandler,\r
-            EnumSet<ResourceProperty> resourcePropertySet) throws OcException {\r
-        OcPlatform.initCheck();\r
-\r
-        int resProperty = 0;\r
-\r
-        for (ResourceProperty prop : ResourceProperty.values()) {\r
-            if (resourcePropertySet.contains(prop))\r
-                resProperty |= prop.getValue();\r
-        }\r
-\r
-        return OcPlatform.registerResource1(resourceUri,\r
-                resourceTypeName,\r
-                resourceInterface,\r
-                entityHandler,\r
-                resProperty);\r
-    }\r
-\r
-    private static native OcResourceHandle registerResource1(\r
-            String resourceUri,\r
-            String resourceTypeName,\r
-            String resourceInterface,\r
-            EntityHandler entityHandler,\r
-            int resourceProperty) throws OcException;\r
-\r
-    /**\r
-     * Register Device Info\r
-     *\r
-     * @param ocDeviceInfo object containing all the device specific information\r
-     * @throws OcException\r
-     */\r
-    public static void registerDeviceInfo(\r
-            OcDeviceInfo ocDeviceInfo) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.registerDeviceInfo0(\r
-                ocDeviceInfo.getDeviceName()\r
-        );\r
-    }\r
-\r
-    private static native void registerDeviceInfo0(\r
-            String deviceName\r
-            ) throws OcException;\r
-\r
-    /**\r
-     * This API unregisters a resource with the server NOTE: This API applies to server side only.\r
-     *\r
-     * @param ocResourceHandle This is the resource handle which we which to unregister from the\r
-     *                         server\r
-     * @throws OcException\r
-     */\r
-    public static void unregisterResource(\r
-            OcResourceHandle ocResourceHandle) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.unregisterResource0(ocResourceHandle);\r
-    }\r
-\r
-    private static native void unregisterResource0(\r
-            OcResourceHandle ocResourceHandle) throws OcException;\r
-\r
-\r
-    /**\r
-     * Add a resource to a collection resource\r
-     *\r
-     * @param ocResourceCollectionHandle handle to the collection resource\r
-     * @param ocResourceHandle           handle to resource to be added to the collection resource\r
-     * @throws OcException\r
-     */\r
-    public static void bindResource(\r
-            OcResourceHandle ocResourceCollectionHandle,\r
-            OcResourceHandle ocResourceHandle) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);\r
-    }\r
-\r
-    private static native void bindResource0(\r
-            OcResourceHandle ocResourceCollectionHandle,\r
-            OcResourceHandle ocResourceHandle) throws OcException;\r
-\r
-    /**\r
-     * Add multiple resources to a collection resource.\r
-     *\r
-     * @param ocResourceCollectionHandle handle to the collection resource\r
-     * @param ocResourceHandleList       reference to list of resource handles to be added to the\r
-     *                                   collection resource\r
-     * @throws OcException\r
-     */\r
-    public static void bindResources(\r
-            OcResourceHandle ocResourceCollectionHandle,\r
-            List<OcResourceHandle> ocResourceHandleList) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.bindResources0(\r
-                ocResourceCollectionHandle,\r
-                ocResourceHandleList.toArray(\r
-                        new OcResourceHandle[ocResourceHandleList.size()])\r
-        );\r
-    }\r
-\r
-    private static native void bindResources0(\r
-            OcResourceHandle ocResourceCollectionHandle,\r
-            OcResourceHandle[] ocResourceHandleArray) throws OcException;\r
-\r
-    /**\r
-     * Unbind a resource from a collection resource.\r
-     *\r
-     * @param ocResourceCollectionHandle handle to the collection resource\r
-     * @param ocResourceHandle           resource handle to be unbound from the collection resource\r
-     * @throws OcException\r
-     */\r
-    public static void unbindResource(\r
-            OcResourceHandle ocResourceCollectionHandle,\r
-            OcResourceHandle ocResourceHandle) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);\r
-    }\r
-\r
-    private static native void unbindResource0(\r
-            OcResourceHandle ocResourceCollectionHandle,\r
-            OcResourceHandle ocResourceHandle) throws OcException;\r
-\r
-    /**\r
-     * Unbind resources from a collection resource.\r
-     *\r
-     * @param ocResourceCollectionHandle Handle to the collection resource\r
-     * @param ocResourceHandleList       List of resource handles to be unbound from the collection\r
-     *                                   resource\r
-     * @throws OcException\r
-     */\r
-    public static void unbindResources(\r
-            OcResourceHandle ocResourceCollectionHandle,\r
-            List<OcResourceHandle> ocResourceHandleList) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.unbindResources0(\r
-                ocResourceCollectionHandle,\r
-                ocResourceHandleList.toArray(\r
-                        new OcResourceHandle[ocResourceHandleList.size()])\r
-        );\r
-    }\r
-\r
-    private static native void unbindResources0(\r
-            OcResourceHandle ocResourceCollectionHandle,\r
-            OcResourceHandle[] ocResourceHandleArray) throws OcException;\r
-\r
-    /**\r
-     * Binds a type to a particular resource\r
-     *\r
-     * @param ocResourceHandle handle to the resource\r
-     * @param resourceTypeName new typename to bind to the resource\r
-     * @throws OcException\r
-     */\r
-    public static void bindTypeToResource(\r
-            OcResourceHandle ocResourceHandle,\r
-            String resourceTypeName) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);\r
-    }\r
-\r
-    private static native void bindTypeToResource0(\r
-            OcResourceHandle ocResourceHandle,\r
-            String resourceTypeName) throws OcException;\r
-\r
-    /**\r
-     * Binds an interface to a particular resource\r
-     *\r
-     * @param ocResourceHandle      handle to the resource\r
-     * @param resourceInterfaceName new interface to bind to the resource\r
-     * @throws OcException\r
-     */\r
-    public static void bindInterfaceToResource(\r
-            OcResourceHandle ocResourceHandle,\r
-            String resourceInterfaceName) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);\r
-    }\r
-\r
-    private static native void bindInterfaceToResource0(\r
-            OcResourceHandle ocResourceHandle,\r
-            String resourceInterfaceName) throws OcException;\r
-\r
-    /**\r
-     * Start Presence announcements.\r
-     *\r
-     * @param ttl time to live in seconds\r
-     * @throws OcException\r
-     */\r
-    public static void startPresence(int ttl) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.startPresence0(ttl);\r
-    }\r
-\r
-    private static native void startPresence0(int ttl) throws OcException;\r
-\r
-    /**\r
-     * Stop Presence announcements.\r
-     *\r
-     * @throws OcException\r
-     */\r
-    public static void stopPresence() throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.stopPresence0();\r
-    }\r
-\r
-    private static native void stopPresence0() throws OcException;\r
-\r
-    /**\r
-     * Subscribes to a server's presence change events. By making this subscription, every time a\r
-     * server adds/removes/alters a resource, starts or is intentionally stopped\r
-     *\r
-     * @param host               The IP address/addressable name of the server to subscribe to\r
-     * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
-     *                           IPV6, ALL\r
-     * @param onPresenceListener listener that will receive notifications/subscription events\r
-     * @return a handle object that can be used to identify this subscription request. It can be\r
-     * used to unsubscribe from these events in the future\r
-     * @throws OcException\r
-     */\r
-    public static OcPresenceHandle subscribePresence(\r
-            String host,\r
-            OcConnectivityType connectivityType,\r
-            OnPresenceListener onPresenceListener) throws OcException {\r
-        OcPlatform.initCheck();\r
-        return OcPlatform.subscribePresence0(\r
-                host,\r
-                connectivityType.getValue(),\r
-                onPresenceListener\r
-        );\r
-    }\r
-\r
-    private static native OcPresenceHandle subscribePresence0(\r
-            String host,\r
-            int connectivityType,\r
-            OnPresenceListener onPresenceListener) throws OcException;\r
-\r
-    /**\r
-     * Subscribes to a server's presence change events. By making this subscription, every time a\r
-     * server adds/removes/alters a resource, starts or is intentionally stopped\r
-     *\r
-     * @param host               The IP address/addressable name of the server to subscribe to\r
-     * @param resourceType       a resource type specified as a filter for subscription events.\r
-     * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
-     *                           IPV6, ALL\r
-     * @param onPresenceListener listener that will receive notifications/subscription events\r
-     * @return a handle object that can be used to identify this subscription request. It can be\r
-     * used to unsubscribe from these events in the future\r
-     * @throws OcException\r
-     */\r
-    public static OcPresenceHandle subscribePresence(\r
-            String host,\r
-            String resourceType,\r
-            OcConnectivityType connectivityType,\r
-            OnPresenceListener onPresenceListener) throws OcException {\r
-        OcPlatform.initCheck();\r
-        return OcPlatform.subscribePresence1(\r
-                host,\r
-                resourceType,\r
-                connectivityType.getValue(),\r
-                onPresenceListener);\r
-    }\r
-\r
-    private static native OcPresenceHandle subscribePresence1(\r
-            String host,\r
-            String resourceType,\r
-            int connectivityType,\r
-            OnPresenceListener onPresenceListener) throws OcException;\r
-\r
-    /**\r
-     * Unsubscribes from a previously subscribed server's presence events. Note that you may for\r
-     * a short time still receive events from the server since it may take time for the\r
-     * unsubscribe to take effect.\r
-     *\r
-     * @param ocPresenceHandle the handle object provided by the subscribePresence call that\r
-     *                         identifies this subscription\r
-     * @throws OcException\r
-     */\r
-    public static void unsubscribePresence(\r
-            OcPresenceHandle ocPresenceHandle) throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.unsubscribePresence0(ocPresenceHandle);\r
-    }\r
-\r
-    private static native void unsubscribePresence0(\r
-            OcPresenceHandle ocPresenceHandle) throws OcException;\r
-\r
-    /**\r
-     * Creates a resource proxy object so that get/put/observe functionality can be used without\r
-     * discovering the object in advance. Note that the consumer of this method needs to provide\r
-     * all of the details required to correctly contact and observe the object. If the consumer\r
-     * lacks any of this information, they should discover the resource object normally.\r
-     * Additionally, you can only create this object if OcPlatform was initialized to be a Client\r
-     * or Client/Server.\r
-     *\r
-     * @param host             a string containing a resolvable host address of the server holding\r
-     *                         the resource\r
-     * @param uri              the rest of the resource's URI that will permit messages to be\r
-     *                         properly routed.\r
-     *                         Example: /a/light\r
-     * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,\r
-     *                         IPV6, ALL\r
-     * @param isObservable     a boolean containing whether the resource supports observation\r
-     * @param resourceTypeList a collection of resource types implemented by the resource\r
-     * @param interfaceList    a collection of interfaces that the resource supports/implements\r
-     * @return new resource object\r
-     * @throws OcException\r
-     */\r
-    public static OcResource constructResourceObject(\r
-            String host,\r
-            String uri,\r
-            OcConnectivityType connectivityType,\r
-            boolean isObservable,\r
-            List<String> resourceTypeList,\r
-            List<String> interfaceList) throws OcException {\r
-        OcPlatform.initCheck();\r
-        return OcPlatform.constructResourceObject0(\r
-                host,\r
-                uri,\r
-                connectivityType.getValue(),\r
-                isObservable,\r
-                resourceTypeList.toArray(new String[resourceTypeList.size()]),\r
-                interfaceList.toArray(new String[interfaceList.size()])\r
-        );\r
-    }\r
-\r
-    private static native OcResource constructResourceObject0(\r
-            String host,\r
-            String uri,\r
-            int connectivityType,\r
-            boolean isObservable,\r
-            String[] resourceTypes,\r
-            String[] interfaces) throws OcException;\r
-\r
-    /**\r
-     * Allows application entity handler to send response to an incoming request.\r
-     *\r
-     * @param ocResourceResponse resource response\r
-     * @throws OcException\r
-     */\r
-    public static void sendResponse(OcResourceResponse ocResourceResponse)\r
-            throws OcException {\r
-        OcPlatform.initCheck();\r
-        OcPlatform.sendResponse0(ocResourceResponse);\r
-    }\r
-\r
-    private static native void sendResponse0(OcResourceResponse ocResourceResponse)\r
-            throws OcException;\r
-\r
-    /**\r
-     * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.\r
-     * Event listeners are notified asynchronously\r
-     */\r
-    public interface OnResourceFoundListener {\r
-        public void onResourceFound(OcResource resource);\r
-    }\r
-\r
-    /**\r
-     * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.\r
-     * Event listeners are notified asynchronously\r
-     */\r
-    public interface OnDeviceFoundListener {\r
-        public void onDeviceFound(OcRepresentation ocRepresentation);\r
-    }\r
-\r
-    /**\r
-     * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.\r
-     * Event listeners are notified asynchronously\r
-     */\r
-    public interface OnPresenceListener {\r
-        public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);\r
-    }\r
-\r
-    /**\r
-     * An EntityHandler can be registered via the OcPlatform.registerResource call.\r
-     * Event listeners are notified asynchronously\r
-     */\r
-    public interface EntityHandler {\r
-        public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);\r
-    }\r
-\r
-    private static void initCheck() {\r
-        if (!sIsPlatformInitialized) {\r
-            throw new IllegalStateException("OcPlatform must be configured by making a call to " +\r
-                    "OcPlatform.Configure before any other API calls are permitted");\r
-        }\r
-    }\r
-}\r
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // 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.base;
+
+import org.iotivity.ca.CaInterface;
+
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Contains the main entrance/functionality of the product. To set a custom configuration, the
+ * implementer must make a call to OcPlatform.Configure before the first usage of a function in this
+ * class.
+ */
+public final class OcPlatform {
+
+    static {
+        System.loadLibrary("oc_logger");
+        System.loadLibrary("octbstack");
+        System.loadLibrary("connectivity_abstraction");
+        System.loadLibrary("oc");
+        System.loadLibrary("ocstack-jni");
+    }
+
+    /**
+     * Default interface
+     */
+    public static final String DEFAULT_INTERFACE = "oic.if.baseline";
+
+    /**
+     * Used in discovering (GET) links to other resources of a collection
+     */
+    public static final String LINK_INTERFACE = "oic.if.ll";
+
+    /**
+     * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
+     */
+    public static final String BATCH_INTERFACE = "oic.if.b";
+
+    /**
+     * Used in GET, PUT, POST methods on links to other remote resources of a group
+     */
+    public static final String GROUP_INTERFACE = "oic.mi.grp";
+
+    public static final String WELL_KNOWN_QUERY = "224.0.1.187:5683/oic/res";
+    public static final String MULTICAST_PREFIX = "224.0.1.187:5683";
+    public static final String MULTICAST_IP = "224.0.1.187";
+    public static final int MULTICAST_PORT = 5683;
+    public static final int DEFAULT_PRESENCE_TTL = 60;
+    public static final String DEVICE_URI = "/oic/d";
+    public static final String PRESENCE_URI = "/oic/ad";
+
+    private static volatile boolean sIsPlatformInitialized = false;
+
+    private OcPlatform() {
+    }
+
+    /**
+     * API for setting the configuration of the OcPlatform.
+     * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect
+     *
+     * @param platformConfig platform configuration
+     */
+    public synchronized static void Configure(PlatformConfig platformConfig) {
+        if (!sIsPlatformInitialized) {
+            CaInterface.initialize(platformConfig.getContext());
+
+            OcPlatform.configure(
+                    platformConfig.getServiceType().getValue(),
+                    platformConfig.getModeType().getValue(),
+                    platformConfig.getIpAddress(),
+                    platformConfig.getPort(),
+                    platformConfig.getQualityOfService().getValue()
+            );
+
+            sIsPlatformInitialized = true;
+        }
+    }
+
+    private static native void configure(int serviceType,
+                                         int modeType,
+                                         String ipAddress,
+                                         int port,
+                                         int qualityOfService);
+
+    /**
+     * API for notifying base that resource's attributes have changed.
+     *
+     * @param ocResourceHandle resource handle of the resource
+     * @throws OcException
+     */
+    public static void notifyAllObservers(
+            OcResourceHandle ocResourceHandle) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.notifyAllObservers0(ocResourceHandle);
+    }
+
+    private static native void notifyAllObservers0(
+            OcResourceHandle ocResourceHandle) throws OcException;
+
+    /**
+     * API for notifying base that resource's attributes have changed.
+     *
+     * @param ocResourceHandle resource handle of the resource
+     * @param qualityOfService the quality of communication
+     * @throws OcException
+     */
+    public static void notifyAllObservers(
+            OcResourceHandle ocResourceHandle,
+            QualityOfService qualityOfService) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
+    }
+
+    private static native void notifyAllObservers1(
+            OcResourceHandle ocResourceHandle,
+            int qualityOfService) throws OcException;
+
+    /**
+     * API for notifying only specific clients that resource's attributes have changed.
+     *
+     * @param ocResourceHandle    resource handle of the resource
+     * @param ocObservationIdList These set of ids are ones which which will be notified upon
+     *                            resource change.
+     * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for
+     *                            this resource change
+     * @throws OcException
+     */
+    public static void notifyListOfObservers(
+            OcResourceHandle ocResourceHandle,
+            List<Byte> ocObservationIdList,
+            OcResourceResponse ocResourceResponse) throws OcException {
+        OcPlatform.initCheck();
+
+        byte[] idArr = new byte[ocObservationIdList.size()];
+        Iterator<Byte> it = ocObservationIdList.iterator();
+        int i = 0;
+        while (it.hasNext()) {
+            idArr[i++] = (byte) it.next();
+        }
+
+        OcPlatform.notifyListOfObservers2(
+                ocResourceHandle,
+                idArr,
+                ocResourceResponse);
+    }
+
+    private static native void notifyListOfObservers2(
+            OcResourceHandle ocResourceHandle,
+            byte[] ocObservationIdArray,
+            OcResourceResponse ocResourceResponse) throws OcException;
+
+    /**
+     * API for notifying only specific clients that resource's attributes have changed.
+     *
+     * @param ocResourceHandle    resource handle of the resource
+     * @param ocObservationIdList These set of ids are ones which which will be notified upon
+     *                            resource change.
+     * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for
+     *                            this resource change
+     * @param qualityOfService    the quality of communication
+     * @throws OcException
+     */
+    public static void notifyListOfObservers(
+            OcResourceHandle ocResourceHandle,
+            List<Byte> ocObservationIdList,
+            OcResourceResponse ocResourceResponse,
+            QualityOfService qualityOfService) throws OcException {
+        OcPlatform.initCheck();
+
+        byte[] idArr = new byte[ocObservationIdList.size()];
+        Iterator<Byte> it = ocObservationIdList.iterator();
+        int i = 0;
+        while (it.hasNext()) {
+            idArr[i++] = (byte) it.next();
+        }
+
+        OcPlatform.notifyListOfObservers3(
+                ocResourceHandle,
+                idArr,
+                ocResourceResponse,
+                qualityOfService.getValue()
+        );
+    }
+
+    private static native void notifyListOfObservers3(
+            OcResourceHandle ocResourceHandle,
+            byte[] ocObservationIdArray,
+            OcResourceResponse ocResourceResponse,
+            int qualityOfService) throws OcException;
+
+    /**
+     * API for Service and Resource Discovery. NOTE: This API applies to client side only
+     *
+     * @param host                    Host IP Address of a service to direct resource discovery query.
+     *                                If empty, performs multicast resource discovery query
+     * @param resourceUri             name of the resource. If null or empty, performs search for all
+     *                                resource names
+     * @param connectivityType        a type of connectivity indicating the interface. Example: IPV4,
+     *                                IPV6, ALL
+     * @param onResourceFoundListener Handles events, success states and failure states.
+     * @throws OcException
+     */
+    public static void findResource(
+            String host,
+            String resourceUri,
+            OcConnectivityType connectivityType,
+            OnResourceFoundListener onResourceFoundListener) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.findResource0(
+                host,
+                resourceUri,
+                connectivityType.getValue(),
+                onResourceFoundListener
+        );
+    }
+
+    private static native void findResource0(
+            String host,
+            String resourceUri,
+            int connectivityType,
+            OnResourceFoundListener onResourceFoundListener) throws OcException;
+
+    /**
+     * API for Service and Resource Discovery. NOTE: This API applies to client side only
+     *
+     * @param host                    Host IP Address of a service to direct resource discovery query.
+     *                                If empty, performs multicast resource discovery query
+     * @param resourceUri             name of the resource. If null or empty, performs search for all
+     *                                resource names
+     * @param connectivityType        a type of connectivity indicating the interface. Example: IPV4,
+     *                                IPV6, ALL
+     * @param onResourceFoundListener Handles events, success states and failure states.
+     * @param qualityOfService        the quality of communication
+     * @throws OcException
+     */
+    public static void findResource(
+            String host,
+            String resourceUri,
+            OcConnectivityType connectivityType,
+            OnResourceFoundListener onResourceFoundListener,
+            QualityOfService qualityOfService) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.findResource1(host,
+                resourceUri,
+                connectivityType.getValue(),
+                onResourceFoundListener,
+                qualityOfService.getValue()
+        );
+    }
+
+    private static native void findResource1(
+            String host,
+            String resourceUri,
+            int connectivityType,
+            OnResourceFoundListener onResourceFoundListener,
+            int qualityOfService) throws OcException;
+
+    /**
+     * API for Device Discovery
+     *
+     * @param host                  Host IP Address. If null or empty, Multicast is performed.
+     * @param deviceUri             Uri containing address to the virtual device
+     * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,
+     *                              IPV6, ALL
+     * @param onDeviceFoundListener Handles events, success states and failure states.
+     * @throws OcException
+     */
+    public static void getDeviceInfo(
+            String host,
+            String deviceUri,
+            OcConnectivityType connectivityType,
+            OnDeviceFoundListener onDeviceFoundListener) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.getDeviceInfo0(
+                host,
+                deviceUri,
+                connectivityType.getValue(),
+                onDeviceFoundListener
+        );
+    }
+
+    private static native void getDeviceInfo0(
+            String host,
+            String deviceUri,
+            int connectivityType,
+            OnDeviceFoundListener onDeviceFoundListener) throws OcException;
+
+    /**
+     * API for Device Discovery
+     *
+     * @param host                  Host IP Address. If null or empty, Multicast is performed.
+     * @param deviceUri             Uri containing address to the virtual device
+     * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,
+     *                              IPV6, ALL
+     * @param onDeviceFoundListener Handles events, success states and failure states.
+     * @param qualityOfService      the quality of communication
+     * @throws OcException
+     */
+    public static void getDeviceInfo(
+            String host,
+            String deviceUri,
+            OcConnectivityType connectivityType,
+            OnDeviceFoundListener onDeviceFoundListener,
+            QualityOfService qualityOfService) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.getDeviceInfo1(
+                host,
+                deviceUri,
+                connectivityType.getValue(),
+                onDeviceFoundListener,
+                qualityOfService.getValue()
+        );
+    }
+
+    private static native void getDeviceInfo1(
+            String host,
+            String deviceUri,
+            int connectivityType,
+            OnDeviceFoundListener onDeviceFoundListener,
+            int qualityOfService) throws OcException;
+
+    /**
+     * API for Platform Discovery
+     *
+     * @param host                  Host IP Address. If null or empty, Multicast is performed.
+     * @param platformUri           Uri containing address to the platform
+     * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,
+     *                              IPV6, ALL
+     * @param onPlatformFoundListener Handles events, success states and failure states.
+     * @throws OcException
+     */
+
+    public static void getPlatformInfo(
+            String host,
+            String platformUri,
+            OcConnectivityType connectivityType,
+            OnPlatformFoundListener onPlatformFoundListener) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.getPlatformInfo0(
+                host,
+                platformUri,
+                connectivityType.getValue(),
+                onPlatformFoundListener
+        );
+    }
+
+    private static native void getPlatformInfo0(
+            String host,
+            String platformUri,
+            int connectivityType,
+            OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
+
+    /**
+     * API for Platform Discovery
+     *
+     * @param host                  Host IP Address. If null or empty, Multicast is performed.
+     * @param platformUri           Uri containing address to the platform
+     * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,
+     *                              IPV6, ALL
+     * @param onPlatformFoundListener Handles events, success states and failure states.
+     * @param qualityOfService      the quality of communication
+     * @throws OcException
+     */
+
+    public static void getPlatformInfo(
+            String host,
+            String platformUri,
+            OcConnectivityType connectivityType,
+            OnPlatformFoundListener onPlatformFoundListener,
+            QualityOfService qualityOfService) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.getPlatformInfo1(
+                host,
+                platformUri,
+                connectivityType.getValue(),
+                onPlatformFoundListener,
+                qualityOfService.getValue()
+        );
+    }
+
+    private static native void getPlatformInfo1(
+            String host,
+            String platformUri,
+            int connectivityType,
+            OnPlatformFoundListener onPlatformFoundListener,
+            int qualityOfService) throws OcException;
+
+    /**
+     * This API registers a resource with the server NOTE: This API applies to server side only.
+     *
+     * @param ocResource The instance of OcResource with all data filled
+     * @return resource handle
+     * @throws OcException
+     */
+    public static OcResourceHandle registerResource(
+            OcResource ocResource) throws OcException {
+        OcPlatform.initCheck();
+        return OcPlatform.registerResource0(ocResource);
+    }
+
+    private static native OcResourceHandle registerResource0(
+            OcResource ocResource) throws OcException;
+
+    /**
+     * This API registers a resource with the server NOTE: This API applies to server side only.
+     *
+     * @param resourceUri         The URI of the resource. Example: "a/light"
+     * @param resourceTypeName    The resource type. Example: "light"
+     * @param resourceInterface   The resource interface (whether it is collection etc).
+     * @param entityHandler       entity handler.
+     * @param resourcePropertySet indicates the property of the resource
+     * @return resource handle
+     * @throws OcException
+     */
+    public static OcResourceHandle registerResource(
+            String resourceUri,
+            String resourceTypeName,
+            String resourceInterface,
+            EntityHandler entityHandler,
+            EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
+        OcPlatform.initCheck();
+
+        int resProperty = 0;
+
+        for (ResourceProperty prop : ResourceProperty.values()) {
+            if (resourcePropertySet.contains(prop))
+                resProperty |= prop.getValue();
+        }
+
+        return OcPlatform.registerResource1(resourceUri,
+                resourceTypeName,
+                resourceInterface,
+                entityHandler,
+                resProperty);
+    }
+
+    private static native OcResourceHandle registerResource1(
+            String resourceUri,
+            String resourceTypeName,
+            String resourceInterface,
+            EntityHandler entityHandler,
+            int resourceProperty) throws OcException;
+
+    /**
+     * Register Device Info
+     *
+     * @param ocDeviceInfo object containing all the device specific information
+     * @throws OcException
+     */
+    public static void registerDeviceInfo(
+            OcDeviceInfo ocDeviceInfo) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.registerDeviceInfo0(
+                ocDeviceInfo.getDeviceName()
+        );
+    }
+
+    private static native void registerDeviceInfo0(
+            String deviceName
+            ) throws OcException;
+
+    /**
+     * Register Platform Info
+     *
+     * @param ocPlatformInfo object containing all the platform specific information
+     * @throws OcException
+     */
+    public static void registerPlatformInfo(
+            OcPlatformInfo ocPlatformInfo) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.registerPlatformInfo0(
+                ocPlatformInfo.getPlatformID(),
+                ocPlatformInfo.getManufacturerName(),
+                ocPlatformInfo.getManufacturerUrl(),
+                ocPlatformInfo.getModelNumber(),
+                ocPlatformInfo.getDateOfManufacture(),
+                ocPlatformInfo.getPlatformVersion(),
+                ocPlatformInfo.getOperatingSystemVersion(),
+                ocPlatformInfo.getHardwareVersion(),
+                ocPlatformInfo.getFirmwareVersion(),
+                ocPlatformInfo.getSupportUrl(),
+                ocPlatformInfo.getSystemTime()
+        );
+    }
+
+    private static native void registerPlatformInfo0(
+            String platformId, String manufacturerName, String manufacturerUrl,
+            String modelNumber, String dateOfManufacture, String platformVersion,
+            String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
+            String supportUrl, String systemTime
+    ) throws OcException;
+
+    /**
+     * This API unregisters a resource with the server NOTE: This API applies to server side only.
+     *
+     * @param ocResourceHandle This is the resource handle which we which to unregister from the
+     *                         server
+     * @throws OcException
+     */
+    public static void unregisterResource(
+            OcResourceHandle ocResourceHandle) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.unregisterResource0(ocResourceHandle);
+    }
+
+    private static native void unregisterResource0(
+            OcResourceHandle ocResourceHandle) throws OcException;
+
+
+    /**
+     * Add a resource to a collection resource
+     *
+     * @param ocResourceCollectionHandle handle to the collection resource
+     * @param ocResourceHandle           handle to resource to be added to the collection resource
+     * @throws OcException
+     */
+    public static void bindResource(
+            OcResourceHandle ocResourceCollectionHandle,
+            OcResourceHandle ocResourceHandle) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
+    }
+
+    private static native void bindResource0(
+            OcResourceHandle ocResourceCollectionHandle,
+            OcResourceHandle ocResourceHandle) throws OcException;
+
+    /**
+     * Add multiple resources to a collection resource.
+     *
+     * @param ocResourceCollectionHandle handle to the collection resource
+     * @param ocResourceHandleList       reference to list of resource handles to be added to the
+     *                                   collection resource
+     * @throws OcException
+     */
+    public static void bindResources(
+            OcResourceHandle ocResourceCollectionHandle,
+            List<OcResourceHandle> ocResourceHandleList) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.bindResources0(
+                ocResourceCollectionHandle,
+                ocResourceHandleList.toArray(
+                        new OcResourceHandle[ocResourceHandleList.size()])
+        );
+    }
+
+    private static native void bindResources0(
+            OcResourceHandle ocResourceCollectionHandle,
+            OcResourceHandle[] ocResourceHandleArray) throws OcException;
+
+    /**
+     * Unbind a resource from a collection resource.
+     *
+     * @param ocResourceCollectionHandle handle to the collection resource
+     * @param ocResourceHandle           resource handle to be unbound from the collection resource
+     * @throws OcException
+     */
+    public static void unbindResource(
+            OcResourceHandle ocResourceCollectionHandle,
+            OcResourceHandle ocResourceHandle) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
+    }
+
+    private static native void unbindResource0(
+            OcResourceHandle ocResourceCollectionHandle,
+            OcResourceHandle ocResourceHandle) throws OcException;
+
+    /**
+     * Unbind resources from a collection resource.
+     *
+     * @param ocResourceCollectionHandle Handle to the collection resource
+     * @param ocResourceHandleList       List of resource handles to be unbound from the collection
+     *                                   resource
+     * @throws OcException
+     */
+    public static void unbindResources(
+            OcResourceHandle ocResourceCollectionHandle,
+            List<OcResourceHandle> ocResourceHandleList) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.unbindResources0(
+                ocResourceCollectionHandle,
+                ocResourceHandleList.toArray(
+                        new OcResourceHandle[ocResourceHandleList.size()])
+        );
+    }
+
+    private static native void unbindResources0(
+            OcResourceHandle ocResourceCollectionHandle,
+            OcResourceHandle[] ocResourceHandleArray) throws OcException;
+
+    /**
+     * Binds a type to a particular resource
+     *
+     * @param ocResourceHandle handle to the resource
+     * @param resourceTypeName new typename to bind to the resource
+     * @throws OcException
+     */
+    public static void bindTypeToResource(
+            OcResourceHandle ocResourceHandle,
+            String resourceTypeName) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
+    }
+
+    private static native void bindTypeToResource0(
+            OcResourceHandle ocResourceHandle,
+            String resourceTypeName) throws OcException;
+
+    /**
+     * Binds an interface to a particular resource
+     *
+     * @param ocResourceHandle      handle to the resource
+     * @param resourceInterfaceName new interface to bind to the resource
+     * @throws OcException
+     */
+    public static void bindInterfaceToResource(
+            OcResourceHandle ocResourceHandle,
+            String resourceInterfaceName) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
+    }
+
+    private static native void bindInterfaceToResource0(
+            OcResourceHandle ocResourceHandle,
+            String resourceInterfaceName) throws OcException;
+
+    /**
+     * Start Presence announcements.
+     *
+     * @param ttl time to live in seconds
+     * @throws OcException
+     */
+    public static void startPresence(int ttl) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.startPresence0(ttl);
+    }
+
+    private static native void startPresence0(int ttl) throws OcException;
+
+    /**
+     * Stop Presence announcements.
+     *
+     * @throws OcException
+     */
+    public static void stopPresence() throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.stopPresence0();
+    }
+
+    private static native void stopPresence0() throws OcException;
+
+    /**
+     * Subscribes to a server's presence change events. By making this subscription, every time a
+     * server adds/removes/alters a resource, starts or is intentionally stopped
+     *
+     * @param host               The IP address/addressable name of the server to subscribe to
+     * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,
+     *                           IPV6, ALL
+     * @param onPresenceListener listener that will receive notifications/subscription events
+     * @return a handle object that can be used to identify this subscription request. It can be
+     * used to unsubscribe from these events in the future
+     * @throws OcException
+     */
+    public static OcPresenceHandle subscribePresence(
+            String host,
+            OcConnectivityType connectivityType,
+            OnPresenceListener onPresenceListener) throws OcException {
+        OcPlatform.initCheck();
+        return OcPlatform.subscribePresence0(
+                host,
+                connectivityType.getValue(),
+                onPresenceListener
+        );
+    }
+
+    private static native OcPresenceHandle subscribePresence0(
+            String host,
+            int connectivityType,
+            OnPresenceListener onPresenceListener) throws OcException;
+
+    /**
+     * Subscribes to a server's presence change events. By making this subscription, every time a
+     * server adds/removes/alters a resource, starts or is intentionally stopped
+     *
+     * @param host               The IP address/addressable name of the server to subscribe to
+     * @param resourceType       a resource type specified as a filter for subscription events.
+     * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,
+     *                           IPV6, ALL
+     * @param onPresenceListener listener that will receive notifications/subscription events
+     * @return a handle object that can be used to identify this subscription request. It can be
+     * used to unsubscribe from these events in the future
+     * @throws OcException
+     */
+    public static OcPresenceHandle subscribePresence(
+            String host,
+            String resourceType,
+            OcConnectivityType connectivityType,
+            OnPresenceListener onPresenceListener) throws OcException {
+        OcPlatform.initCheck();
+        return OcPlatform.subscribePresence1(
+                host,
+                resourceType,
+                connectivityType.getValue(),
+                onPresenceListener);
+    }
+
+    private static native OcPresenceHandle subscribePresence1(
+            String host,
+            String resourceType,
+            int connectivityType,
+            OnPresenceListener onPresenceListener) throws OcException;
+
+    /**
+     * Unsubscribes from a previously subscribed server's presence events. Note that you may for
+     * a short time still receive events from the server since it may take time for the
+     * unsubscribe to take effect.
+     *
+     * @param ocPresenceHandle the handle object provided by the subscribePresence call that
+     *                         identifies this subscription
+     * @throws OcException
+     */
+    public static void unsubscribePresence(
+            OcPresenceHandle ocPresenceHandle) throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.unsubscribePresence0(ocPresenceHandle);
+    }
+
+    private static native void unsubscribePresence0(
+            OcPresenceHandle ocPresenceHandle) throws OcException;
+
+    /**
+     * Creates a resource proxy object so that get/put/observe functionality can be used without
+     * discovering the object in advance. Note that the consumer of this method needs to provide
+     * all of the details required to correctly contact and observe the object. If the consumer
+     * lacks any of this information, they should discover the resource object normally.
+     * Additionally, you can only create this object if OcPlatform was initialized to be a Client
+     * or Client/Server.
+     *
+     * @param host             a string containing a resolvable host address of the server holding
+     *                         the resource
+     * @param uri              the rest of the resource's URI that will permit messages to be
+     *                         properly routed.
+     *                         Example: /a/light
+     * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
+     *                         IPV6, ALL
+     * @param isObservable     a boolean containing whether the resource supports observation
+     * @param resourceTypeList a collection of resource types implemented by the resource
+     * @param interfaceList    a collection of interfaces that the resource supports/implements
+     * @return new resource object
+     * @throws OcException
+     */
+    public static OcResource constructResourceObject(
+            String host,
+            String uri,
+            OcConnectivityType connectivityType,
+            boolean isObservable,
+            List<String> resourceTypeList,
+            List<String> interfaceList) throws OcException {
+        OcPlatform.initCheck();
+        return OcPlatform.constructResourceObject0(
+                host,
+                uri,
+                connectivityType.getValue(),
+                isObservable,
+                resourceTypeList.toArray(new String[resourceTypeList.size()]),
+                interfaceList.toArray(new String[interfaceList.size()])
+        );
+    }
+
+    private static native OcResource constructResourceObject0(
+            String host,
+            String uri,
+            int connectivityType,
+            boolean isObservable,
+            String[] resourceTypes,
+            String[] interfaces) throws OcException;
+
+    /**
+     * Allows application entity handler to send response to an incoming request.
+     *
+     * @param ocResourceResponse resource response
+     * @throws OcException
+     */
+    public static void sendResponse(OcResourceResponse ocResourceResponse)
+            throws OcException {
+        OcPlatform.initCheck();
+        OcPlatform.sendResponse0(ocResourceResponse);
+    }
+
+    private static native void sendResponse0(OcResourceResponse ocResourceResponse)
+            throws OcException;
+
+    /**
+     * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
+     * Event listeners are notified asynchronously
+     */
+    public interface OnResourceFoundListener {
+        public void onResourceFound(OcResource resource);
+    }
+
+    /**
+     * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
+     * Event listeners are notified asynchronously
+     */
+    public interface OnDeviceFoundListener {
+        public void onDeviceFound(OcRepresentation ocRepresentation);
+    }
+
+    /**
+     * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
+     * Event listeners are notified asynchronously
+     */
+    public interface OnPlatformFoundListener {
+        public void onPlatformFound(OcRepresentation ocRepresentation);
+    }
+
+    /**
+     * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
+     * Event listeners are notified asynchronously
+     */
+    public interface OnPresenceListener {
+        public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
+    }
+
+    /**
+     * An EntityHandler can be registered via the OcPlatform.registerResource call.
+     * Event listeners are notified asynchronously
+     */
+    public interface EntityHandler {
+        public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
+    }
+
+    private static void initCheck() {
+        if (!sIsPlatformInitialized) {
+            throw new IllegalStateException("OcPlatform must be configured by making a call to " +
+                    "OcPlatform.Configure before any other API calls are permitted");
+        }
+    }
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java
new file mode 100644 (file)
index 0000000..53d366d
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // 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.base;
+
+import java.lang.Error;
+
+public class OcPlatformInfo {
+
+    private String platformID;
+    private String manufacturerName;
+    private String manufacturerUrl;
+    private String modelNumber;
+    private String dateOfManufacture;
+    private String platformVersion;
+    private String operatingSystemVersion;
+    private String hardwareVersion;
+    private String firmwareVersion;
+    private String supportUrl;
+    private String systemTime;
+
+    // construct OcPlatformInfo with mandatory fields which cannot be null
+    // manufacturerName cannot be > 16 chars
+    // manufacturerUrl cannot be > 32 chars
+    protected OcPlatformInfo(String platformID, String manufacturerName,
+                             String manufacturerUrl) throws OcException {
+        ErrorCode result = validatePlatformInfo(platformID, manufacturerName, manufacturerUrl);
+        if (ErrorCode.OK == result) {
+            this.platformID = platformID;
+            this.manufacturerName = manufacturerName;
+            this.manufacturerUrl = manufacturerUrl;
+        } else {
+            throw new OcException(result, result.getDescription());
+        }
+    }
+
+    public ErrorCode validatePlatformInfo(String platformID, String manufacturerName,
+                                          String manufacturerUrl) {
+        // checks to see if the mandatory fields have non-null values or not
+        if (platformID == null || platformID.isEmpty()) return ErrorCode.INVALID_PLATFORM_INFO_PLATFORMID;
+        if (manufacturerName == null || manufacturerName.isEmpty() ||
+                manufacturerName.length() > OcStackConfig.MAX_MANUFACTURER_NAME_LENGTH)
+            return ErrorCode.INVALID_PLATFORM_INFO_MANUFACTURER_NAME;
+        if (manufacturerUrl == null || manufacturerUrl.isEmpty() ||
+                manufacturerUrl.length() > OcStackConfig.MAX_MANUFACTURER_URL_LENGTH)
+            return ErrorCode.INVALID_PLATFORM_INFO_PLATFORMID_MANUFACTURER_URL;
+        return ErrorCode.OK;
+    }
+
+    public String getPlatformID() {
+        return platformID;
+    }
+
+    public void setPlatformID(String platformID) {
+        this.platformID = platformID;
+    }
+
+    public String getManufacturerName() {
+        return manufacturerName;
+    }
+
+    public void setManufacturerName(String manufacturerName) {
+        this.manufacturerName = manufacturerName;
+    }
+
+    public String getManufacturerUrl() {
+        return manufacturerUrl;
+    }
+
+    public void setManufacturerUrl(String manufacturerUrl) {
+        this.manufacturerUrl = manufacturerUrl;
+    }
+
+    public String getModelNumber() {
+        return modelNumber;
+    }
+
+    public void setModelNumber(String modelNumber) {
+        this.modelNumber = modelNumber;
+    }
+
+    public String getDateOfManufacture() {
+        return dateOfManufacture;
+    }
+
+    public void setDateOfManufacture(String dateOfManufacture) {
+        this.dateOfManufacture = dateOfManufacture;
+    }
+
+    public String getPlatformVersion() {
+        return platformVersion;
+    }
+
+    public void setPlatformVersion(String platformVersion) {
+        this.platformVersion = platformVersion;
+    }
+
+    public String getOperatingSystemVersion() {
+        return operatingSystemVersion;
+    }
+
+    public void setOperatingSystemVersion(String operatingSystemVersion) {
+        this.operatingSystemVersion = operatingSystemVersion;
+    }
+
+    public String getHardwareVersion() {
+        return hardwareVersion;
+    }
+
+    public void setHardwareVersion(String hardwareVersion) {
+        this.hardwareVersion = hardwareVersion;
+    }
+
+    public String getFirmwareVersion() {
+        return firmwareVersion;
+    }
+
+    public void setFirmwareVersion(String firmwareVersion) {
+        this.firmwareVersion = firmwareVersion;
+    }
+
+    public String getSupportUrl() {
+        return supportUrl;
+    }
+
+    public void setSupportUrl(String supportUrl) {
+        this.supportUrl = supportUrl;
+    }
+
+    public String getSystemTime() {
+        return systemTime;
+    }
+
+    public void setSystemTime(String systemTime) {
+        this.systemTime = systemTime;
+    }
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcStackConfig.java b/android/android_api/base/src/main/java/org/iotivity/base/OcStackConfig.java
new file mode 100644 (file)
index 0000000..ff48d22
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // 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.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+// This file contains all the variables which can be configured/modified as
+// per platform or specific product usage scenarios.
+
+package org.iotivity.base;
+
+public interface OcStackConfig {
+    // max manufacturer name length for OcPlatformInfo supported by server
+    public static final int MAX_MANUFACTURER_NAME_LENGTH = 16;
+    // max manufacturer url length for OcPlatformInfo supported by server
+    public static final int MAX_MANUFACTURER_URL_LENGTH = 32;
+}
\ No newline at end of file