Merge 'security-basecamp' branch into master with CBOR
authorSachin Agrawal <sachin.agrawal@intel.com>
Wed, 15 Jul 2015 16:40:26 +0000 (09:40 -0700)
committerSachin Agrawal <sachin.agrawal@intel.com>
Wed, 15 Jul 2015 16:40:26 +0000 (09:40 -0700)
security-basecamp for 0.9.2 is merged in master brach.

Change-Id: Ia5cd2710a688d3e631009ed03f7e5eb97aba5d24
Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
33 files changed:
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/JniOcSecurity.cpp [new file with mode: 0644]
android/android_api/base/jni/JniOcSecurity.h [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java
android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java
android/examples/simpleclient/src/main/AndroidManifest.xml
android/examples/simpleclient/src/main/assets/oic_svr_db_client.json [new file with mode: 0755]
android/examples/simpleclient/src/main/java/org/iotivity/base/examples/simpleclient/SimpleClient.java
android/examples/simpleclient/src/main/java/org/iotivity/base/examples/simpleclient/StringConstants.java
android/examples/simpleserver/src/main/AndroidManifest.xml
android/examples/simpleserver/src/main/assets/oic_svr_db_server.json [new file with mode: 0755]
android/examples/simpleserver/src/main/java/org/iotivity/base/examples/simpleserver/LightResource.java
android/examples/simpleserver/src/main/java/org/iotivity/base/examples/simpleserver/SimpleServer.java
android/examples/simpleserver/src/main/java/org/iotivity/base/examples/simpleserver/StringConstants.java
resource/csdk/security/include/internal/secureresourcemanager.h
resource/csdk/security/include/internal/srmresourcestrings.h
resource/csdk/security/provisioning/SConscript
resource/csdk/security/provisioning/src/provisioningmanager.c
resource/csdk/security/src/policyengine.c
resource/csdk/security/src/secureresourcemanager.c
resource/csdk/security/src/srmresourcestrings.c
resource/examples/SConscript
resource/examples/oic_svr_db_client.json [new file with mode: 0755]
resource/examples/oic_svr_db_server.json [new file with mode: 0755]
resource/examples/simpleclient.cpp
resource/examples/simpleserver.cpp
resource/include/OCApi.h
resource/include/OCSerialization.h
resource/src/OCPlatform_impl.cpp
resource/unittests/OCPlatformTest.cpp
resource/unittests/SConscript

index 6a7e613..be7e3ca 100644 (file)
@@ -58,7 +58,8 @@ LOCAL_SRC_FILES :=  JniOcStack.cpp \
                     JniOcResourceResponse.cpp \\r
                     JniOcPlatform.cpp \\r
                     JniOcResource.cpp \\r
-                    JniOcResourceIdentifier.cpp\r
+                    JniOcResourceIdentifier.cpp \
+                    JniOcSecurity.cpp
 \r
 LOCAL_LDLIBS := -llog\r
 LOCAL_STATIC_LIBRARIES := android-oc\r
index 5dfe78b..2023fa4 100644 (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();
+/*\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 "JniOcSecurity.h"
+#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
 }
 
 JniOnPlatformInfoListener* AddOnPlatformInfoListener(JNIEnv* env, jobject jListener)
@@ -234,170 +235,512 @@ void RemoveOnPlatformInfoListener(JNIEnv* env, jobject jListener)
         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;
+}\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, jstring jDbPath)
+{\r
+    LOGI("OcPlatform_configure");\r
+\r
+    std::string ipAddress;\r
+    std::string dbfile;
+    if (jIpAddress)\r
+    {\r
+        ipAddress = env->GetStringUTFChars(jIpAddress, NULL);\r
+    }\r
+    if (jDbPath)
+    {
+        dbfile = env->GetStringUTFChars(jDbPath, nullptr);
+        JniOcSecurity::StoreDbPath(dbfile);
+    }
+    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)),
+        JniOcSecurity::getOCPersistentStorage()
+    };\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
         }
     }
     catch (OCException& e)
@@ -409,57 +752,46 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1
 
 /*
 * Class:     org_iotivity_base_OcPlatform
-* Method:    notifyListOfObservers2
-* Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;)V
+* Method:    getPlatformInfo0
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;)V
 */
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2
-(JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse)
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo0
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener)
 {
-    LOGD("OcPlatform_notifyListOfObservers2");
-    if (!jResourceHandle)
+    LOGD("OcPlatform_getPlatformInfo0");
+    std::string host;
+    if (jHost)
     {
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
-        return;
+        host = env->GetStringUTFChars(jHost, NULL);
     }
-    if (!jObservationIdArr)
+    std::string resourceUri;
+    if (jResourceUri)
     {
-        ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null");
-        return;
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
     }
-    if (!jResourceResponse)
+    if (!jListener)
     {
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null");
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null");
         return;
     }
+    JniOnPlatformInfoListener *onPlatformInfoListener = AddOnPlatformInfoListener(env, jListener);
 
-    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)
+    FindPlatformCallback findPlatformCallback = [onPlatformInfoListener](const OCRepresentation& ocRepresentation)
     {
-        observationIds.push_back(bArr[i]);
-    }
-
-    env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0);
+        onPlatformInfoListener->foundPlatformCallback(ocRepresentation);
+    };
 
-    try{
-        OCStackResult result = OCPlatform::notifyListOfObservers(
-            jniOcResourceHandle->getOCResourceHandle(),
-            observationIds,
-            jniOcResourceResponse->getOCResourceResponse());
+    try
+    {
+        OCStackResult result = OCPlatform::getPlatformInfo(
+            host,
+            resourceUri,
+            JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+            findPlatformCallback);
 
         if (OC_STACK_OK != result)
         {
-            ThrowOcException(result, "Failed to notify all observers");
+            ThrowOcException(result, "Find platform has failed");
         }
     }
     catch (OCException& e)
@@ -471,553 +803,230 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2
 
 /*
 * Class:     org_iotivity_base_OcPlatform
-* Method:    notifyListOfObservers3
-* Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;I)V
+* Method:    getPlatformInfo1
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;I)V
 */
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3
-(JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse, jint jQoS)
+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_notifyListOfObservers3");
-    if (!jResourceHandle)
+    LOGD("OcPlatform_getPlatformInfo1");
+    std::string host;
+    if (jHost)
     {
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null");
-        return;
+        host = env->GetStringUTFChars(jHost, NULL);
     }
-    if (!jObservationIdArr)
+    std::string resourceUri;
+    if (jResourceUri)
     {
-        ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null");
-        return;
+        resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
     }
-    if (!jResourceResponse)
+    if (!jListener)
     {
-        ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null");
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null");
         return;
     }
+    JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener);
 
-    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)
+    FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation)
     {
-        observationIds.push_back(bArr[i]);
-    }
-
-    env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0);
+        onDeviceInfoListener->foundDeviceCallback(ocRepresentation);
+    };
 
-    try{
-        OCStackResult result = OCPlatform::notifyListOfObservers(
-            jniOcResourceHandle->getOCResourceHandle(),
-            observationIds,
-            jniOcResourceResponse->getOCResourceResponse(),
+    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, "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
+            ThrowOcException(result, "Find platform has failed");
+        }\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
+    LOGD("OcPlatform_registerResource1");
+    OCResourceHandle resourceHandle;\r
+    try\r
+    {\r
+        LOGD("OcPlatform_registerResource2");
+        OCStackResult result = OCPlatform::registerResource(\r
+            resourceHandle,\r
+            resource->getOCResource());\r
+        LOGD("OcPlatform_registerResource3");
+\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
+    LOGD("OcPlatform_registerResource4");
+    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
+    LOGD("OcPlatform_registerResource5");
+    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:    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
 */
@@ -1065,750 +1074,750 @@ jstring jSystemTime)
         }
         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)
+            modelNumber = env->GetStringUTFChars(jModelNumber, NULL);
+        }
+        if (jDateOfManufacture)
         {
-            ThrowOcException(result, "Failed to bind type to resource");
+            dateOfManufacture = env->GetStringUTFChars(jDateOfManufacture, NULL);
         }
-    }
-    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)
+        if (jPlatformVersion)
         {
-            ThrowOcException(result, "Failed to bind interface to resource");
+            platformVersion = env->GetStringUTFChars(jPlatformVersion, NULL);
         }
-    }
-    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)
+        if (jOperatingSystemVersion)
         {
-            ThrowOcException(result, "Failed to start presence");
+            operatingSystemVersion = env->GetStringUTFChars(jOperatingSystemVersion, NULL);
         }
-    }
-    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)
+        if (jHardwareVersion)
         {
-            ThrowOcException(result, "Failed to stop presence");
+            hardwareVersion = env->GetStringUTFChars(jHardwareVersion, NULL);
         }
-    }
-    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)
+        if (jFirmwareVersion)
         {
-            ThrowOcException(result, "subscribe presence has failed");
+            firmwareVersion = env->GetStringUTFChars(jFirmwareVersion, NULL);
         }
-    }
-    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)
+        if (jSupportUrl)
         {
-            ThrowOcException(result, "subscribe presence has failed");
+            supportUrl = env->GetStringUTFChars(jSupportUrl, NULL);
+        }
+        if (jSystemTime)
+        {
+            systemTime = env->GetStringUTFChars(jSystemTime, NULL);
         }
-    }
-    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)
+        OCPlatformInfo platformInfo;
+        try
         {
-            ThrowOcException(result, "unsubscribe presence has failed");
-            return;
+            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);
         }
-        jweak jwOnPresenceListener = jniPresenceHandle->getJniOnPresenceListener()->getJWListener();
-        if (jwOnPresenceListener)
+        catch (std::exception &e)
         {
-            RemoveOnPresenceListener(env, jwOnPresenceListener);
+            ThrowOcException(JNI_EXCEPTION, "Failed to construct platform 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:    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);
+       // __android_log_print(ANDROID_LOG_INFO, "Rahul", "platformID  = %s", platformID);
+        try
+        {
+            OCStackResult result = OCPlatform::registerPlatformInfo(platformInfo);
 
-    std::vector<std::string> interfaces;
-    JniUtils::convertJavaStrArrToStrVector(env, jInterfaceArray, interfaces);
+            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;
 
-    std::shared_ptr<OCResource> resource = OCPlatform::constructResourceObject(
-        host,
-        uri,
-        JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
-        static_cast<bool>(jIsObservable),
-        resourceTypes,
-        interfaces);
+            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());
+        }
 
-    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());
-    }
+* 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
+    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
 }
index 62c9938..ca7051e 100644 (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 "JniOcStack.h"
-#include "JniOnResourceFoundListener.h"
-#include "JniOnDeviceInfoListener.h"
+/*\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 "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);
-
+#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
 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;
+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<JniOnPlatformInfoListener*, int>> onPlatformInfoListenerMap;
-std::map<jobject, std::pair<JniOnPresenceListener*, int>> onPresenceListenerMap;
-
-std::mutex resourceFoundMapLock;
-std::mutex deviceInfoMapLock;
+std::map<jobject, std::pair<JniOnPresenceListener*, int>> onPresenceListenerMap;\r
+\r
+std::mutex resourceFoundMapLock;\r
+std::mutex deviceInfoMapLock;\r
 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
+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, jstring);
+\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);
 
     /*
@@ -142,30 +142,30 @@ extern "C" {
      * 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
+        (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;)V
-    */
-    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0
+    */\r
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0\r
         (JNIEnv *, jclass, jstring);
 
     /*
@@ -175,121 +175,121 @@ extern "C" {
     */
     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
+\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
 
diff --git a/android/android_api/base/jni/JniOcSecurity.cpp b/android/android_api/base/jni/JniOcSecurity.cpp
new file mode 100644 (file)
index 0000000..54821ee
--- /dev/null
@@ -0,0 +1,60 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+#include "JniOcSecurity.h"
+#include "JniOcStack.h"
+
+/*
+ * TODO: Persistant Storage Handling should be done by App.
+ * For 0.9.2 , Handling is done at JNI. As of now Plaform Config only
+ * SVR Database fileName(fullpath) is passed.
+ */
+using namespace std;
+namespace PH = std::placeholders;
+namespace OC {
+
+    string& JniOcSecurity::store_path()
+    {
+        static string s_dbPath;
+        return s_dbPath;
+    }
+
+    void JniOcSecurity::StoreDbPath(const string &path)
+    {
+        store_path() = path;
+    }
+
+    OCPersistentStorage* JniOcSecurity::getOCPersistentStorage()
+    {
+        if (store_path().empty())
+        {
+            return nullptr;
+        }
+        static OCPersistentStorage s_ps { &JniOcSecurity::client_open, fread,
+            fwrite, fclose, unlink };
+        return &s_ps;
+    }
+
+    FILE* JniOcSecurity::client_open(const char *path, const char *mode)
+    {
+        LOGI("Opening SVR Database file '%s' with mode '%s'\n", store_path().c_str(), mode);
+        return fopen(store_path().c_str(), mode);
+    }
+}
diff --git a/android/android_api/base/jni/JniOcSecurity.h b/android/android_api/base/jni/JniOcSecurity.h
new file mode 100644 (file)
index 0000000..78293e6
--- /dev/null
@@ -0,0 +1,43 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef __JNIOCSECURITY_H
+#define __JNIOCSECURITY_H
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string>
+#include "octypes.h"
+#include <unistd.h>
+
+namespace OC
+{
+    class JniOcSecurity
+    {
+        private:
+            static FILE* client_open(const char*, const char*);
+        public:
+            static std::string& store_path(void);
+            static void StoreDbPath(const std::string&);
+            static OCPersistentStorage* getOCPersistentStorage(void);
+    };
+}
+#endif //__JNIOCSECURITY_H
index 891d487..46dedf2 100644 (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.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-
-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,
+/*\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(),
+                    platformConfig.getSvrDbPath()
+            );\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,
+                                         String dbPath);
+\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;
 
     /**
@@ -405,83 +407,83 @@ public final class OcPlatform {
             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;
-
-    /**
+            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
      * Register Platform Info
      *
      * @param ocPlatformInfo object containing all the platform specific information
@@ -513,320 +515,320 @@ public final class OcPlatform {
     ) 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);
+     * 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
     }
 
     /**
@@ -835,28 +837,28 @@ public final class OcPlatform {
      */
     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");
-        }
-    }
-}
+    }\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
index 7fd9ac0..70d9df3 100644 (file)
@@ -35,6 +35,8 @@ public class PlatformConfig {
     private String mIpAddress;\r
     private int mPort;\r
     private QualityOfService mQualityOfService;\r
+    private String mSvrDbPath; //TODO: Instead of SVRDB file, it should be Persistent Storage.
+                              //this is only for 0.9.2
 \r
     /**\r
      * @param context          app context\r
@@ -47,19 +49,44 @@ public class PlatformConfig {
      *                         if you specify 5683 : client discovery can work even if they don't\r
      *                         specify port\r
      * @param qualityOfService quality of service\r
+     * @param dbPath           Persistant storage file for SVR Database.
      */\r
     public PlatformConfig(Context context,\r
                           ServiceType serviceType,\r
                           ModeType modeType,\r
                           String ipAddress,\r
                           int port,\r
-                          QualityOfService qualityOfService) {\r
+                          QualityOfService qualityOfService,
+                          String dbPath) {
         this.mContext = context;\r
         this.mServiceType = serviceType;\r
         this.mModeType = modeType;\r
         this.mIpAddress = ipAddress;\r
         this.mPort = port;\r
         this.mQualityOfService = qualityOfService;\r
+        this.mSvrDbPath = dbPath;
+    }
+
+    /**
+     * @param context          app context
+     * @param serviceType      indicate IN_PROC or OUT_OF_PROC
+     * @param modeType         indicate whether we want to do server, client or both
+     * @param ipAddress        ip address of server
+     *                         if you specify 0.0.0.0 : it listens on any interface
+     * @param port             port of server
+     *                         if you specifiy 0 : next available random port is used
+     *                         if you specify 5683 : client discovery can work even if they don't
+     *                         specify port
+     * @param qualityOfService quality of service
+     */
+    //Avoid breaking building java samples due to persistent storage SVR DB changes.
+    public PlatformConfig(Context context,
+                          ServiceType serviceType,
+                          ModeType modeType,
+                          String ipAddress,
+                          int port,
+                          QualityOfService qualityOfService) {
+        this(context,serviceType,modeType,ipAddress,port,qualityOfService, "");
     }\r
 \r
     public Context getContext() {\r
@@ -84,5 +111,9 @@ public class PlatformConfig {
 \r
     public QualityOfService getQualityOfService() {\r
         return mQualityOfService;\r
+    }
+
+    public String getSvrDbPath() {
+        return mSvrDbPath;
     }\r
 }\r
index 0345054..86dd253 100755 (executable)
@@ -4,6 +4,8 @@
     xmlns:tools="http://schemas.android.com/tools">\r
 \r
     <uses-sdk tools:overrideLibrary="org.iotivity.base"></uses-sdk>\r
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 \r
     <application\r
         android:allowBackup="true"\r
diff --git a/android/examples/simpleclient/src/main/assets/oic_svr_db_client.json b/android/examples/simpleclient/src/main/assets/oic_svr_db_client.json
new file mode 100755 (executable)
index 0000000..17dc43f
--- /dev/null
@@ -0,0 +1,49 @@
+{
+    "acl": [
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/res",
+                "/oic/d",
+                "/oic/p",
+                "/oic/res/types/d",
+                "/oic/ad",
+                "/oic/sec/acl"
+                       ],
+                       "perms": 2,
+                       "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+               },
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/sec/doxm",
+                "/oic/sec/pstat"
+             ],
+             "perms": 2,
+             "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+        }
+       ],
+       "pstat":        {
+               "isop": true,
+               "deviceid":     "ZGV2aWNlaWQAAAAAABhanw==",
+               "ch": 0,
+               "cm":   0,
+               "tm":   0,
+               "om":   3,
+               "sm":   [3]
+       },
+       "doxm": {
+               "oxm":  [0],
+               "oxmsel": 0,
+               "owned": true,
+               "deviceid":     "MjIyMjIyMjIyMjIyMjIyMg==",
+               "ownr": "MjIyMjIyMjIyMjIyMjIyMg=="
+       },
+    "cred":    [{
+               "credid": 1,
+               "sub": "MTExMTExMTExMTExMTExMQ==",
+               "credtyp": 1,
+               "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+        "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+       }]
+}
index d2d2620..472d206 100644 (file)
@@ -26,8 +26,11 @@ import android.app.Activity;
 import android.content.BroadcastReceiver;\r
 import android.content.Context;\r
 import android.content.Intent;\r
+import android.content.SharedPreferences;\r
+import android.content.res.AssetManager;\r
 import android.os.Bundle;\r
 import android.os.Message;\r
+import android.preference.PreferenceManager;\r
 import android.text.method.ScrollingMovementMethod;\r
 import android.util.Log;\r
 import android.widget.LinearLayout;\r
@@ -46,6 +49,12 @@ import org.iotivity.base.PlatformConfig;
 import org.iotivity.base.QualityOfService;\r
 import org.iotivity.base.ServiceType;\r
 \r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
 import java.util.HashMap;\r
 import java.util.List;\r
 \r
@@ -61,13 +70,15 @@ import base.iotivity.org.examples.message.IMessageLogger;
  */\r
 public class SimpleClient extends Activity implements OcPlatform.OnResourceFoundListener,\r
         IMessageLogger {\r
-    private static final String TAG = "SimpleClient: ";\r
+    private static final String TAG = "SimpleClient: ";
 \r
+    private static final int BUFFER_SIZE = 1024;
+    private String filePath = "";\r
     private Light myLight;\r
-    private OcResource curResource;\r
+    private OcResource curResource;
 \r
     //for display\r
-    private TextView mEventsTextView;\r
+    private TextView mEventsTextView;
     private static boolean printOnce = true;\r
 \r
     /**\r
@@ -78,10 +89,10 @@ public class SimpleClient extends Activity implements OcPlatform.OnResourceFound
         PlatformConfig cfg = new PlatformConfig(\r
                 this,\r
                 ServiceType.IN_PROC,\r
-                ModeType.CLIENT,\r
+                ModeType.CLIENT_SERVER,\r
                 "0.0.0.0", // bind to all available interfaces\r
                 0,\r
-                QualityOfService.LOW);\r
+                QualityOfService.LOW, filePath + StringConstants.OIC_CLIENT_JSON_DB_FILE);\r
         OcPlatform.Configure(cfg);\r
         try {\r
             /**\r
@@ -111,7 +122,7 @@ public class SimpleClient extends Activity implements OcPlatform.OnResourceFound
             hostAddress = ocResource.getHost();\r
             logMessage(TAG + "Discovered Resource\nUri: " + resourceUri + " \n Host: " + hostAddress);\r
             // get the resource types\r
-            if (resourceUri.equals(StringConstants.RESOURCE_URI0)) {\r
+            if (resourceUri.contains("light")) {\r
                 curResource = ocResource;\r
                 doGetLightRepresentation();\r
             }\r
@@ -416,10 +427,70 @@ public class SimpleClient extends Activity implements OcPlatform.OnResourceFound
                 LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)\r
         );\r
         myLight = new Light();\r
+        filePath = getFilesDir().getPath() + "/"; //  data/data/<package>/files/\r
+        //copy json when application runs first time\r
+        SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);\r
+        boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);\r
+        if (isFirstRun) {\r
+            copyJsonFromAsset();\r
+            SharedPreferences.Editor editor = wmbPreference.edit();\r
+            editor.putBoolean("FIRSTRUN", false);\r
+            editor.commit();\r
+        }\r
+\r
 \r
         initOICStack();\r
     }\r
+/**\r
+     * Copy svr db json file from assets folder to app data files dir\r
+     */\r
+    private void copyJsonFromAsset() {\r
+        AssetManager assetManager = getAssets();\r
+        InputStream in = null;\r
+        OutputStream out = null;\r
+        try {\r
+            in = assetManager.open(StringConstants.OIC_CLIENT_JSON_DB_FILE);\r
+            File file = new File(filePath);\r
+            //check files directory exists\r
+            if (!(file.exists() && file.isDirectory())) {\r
+                file.mkdirs();\r
+            }\r
+            out = new FileOutputStream(filePath + StringConstants.OIC_CLIENT_JSON_DB_FILE);\r
+            copyFile(in, out);\r
+        } catch (NullPointerException e) {\r
+            logMessage(TAG + "Null pointer exception " + e.getMessage());\r
+            Log.e(TAG, e.getMessage());\r
+        } catch (FileNotFoundException e) {\r
+            logMessage(TAG + "Json svr db file not found " + e.getMessage());\r
+            Log.e(TAG, e.getMessage());\r
+        } catch (IOException e) {\r
+            logMessage(TAG + StringConstants.OIC_CLIENT_JSON_DB_FILE+ " file copy failed");\r
+            Log.e(TAG, e.getMessage());\r
+        } finally {\r
+            if (in != null) {\r
+                try {\r
+                    in.close();\r
+                } catch (IOException e) {\r
+                    Log.e(TAG, e.getMessage());\r
+                }\r
+            }\r
+            if (out != null) {\r
+                try {\r
+                    out.close();\r
+                } catch (IOException e) {\r
+                    Log.e(TAG, e.getMessage());\r
+                }\r
+            }\r
+        }\r
+    }\r
 \r
+    private void copyFile(InputStream in, OutputStream out) throws IOException {\r
+        byte[] buffer = new byte[BUFFER_SIZE];\r
+        int read;\r
+        while ((read = in.read(buffer)) != -1) {\r
+            out.write(buffer, 0, read);\r
+        }\r
+    }\r
     @Override\r
     public void logMessage(String text) {\r
         logMsg(text);\r
index f87c387..af163e1 100644 (file)
@@ -1,5 +1,4 @@
 package org.iotivity.base.examples.simpleclient;\r
-\r
 /**\r
  * StringConstant contains the simpleclient specific constant values.  To add another supported\r
  * Resource or Interface type to this app, begin by adding the new strings here, and then\r
@@ -9,6 +8,7 @@ package org.iotivity.base.examples.simpleclient;
 public interface StringConstants {\r
     public static final String RESOURCE_URI0 = "/light0";\r
     public static final String RESOURCE_URI1 = "/light1";\r
+    public static final String OIC_CLIENT_JSON_DB_FILE =  "oic_svr_db_client.json";\r
     public static final String CREATED_URI = "createduri";\r
     public static final String STATE = "state";\r
     public static final String NAME = "name";\r
index 43352f4..0026240 100755 (executable)
@@ -4,6 +4,8 @@
     xmlns:tools="http://schemas.android.com/tools">\r
 \r
     <uses-sdk tools:overrideLibrary="org.iotivity.base"></uses-sdk>\r
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 \r
     <application\r
         android:allowBackup="true"\r
diff --git a/android/examples/simpleserver/src/main/assets/oic_svr_db_server.json b/android/examples/simpleserver/src/main/assets/oic_svr_db_server.json
new file mode 100755 (executable)
index 0000000..6c8c4e4
--- /dev/null
@@ -0,0 +1,55 @@
+{
+    "acl": [
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/res",
+                "/oic/d",
+                "/oic/p",
+                "/oic/res/types/d",
+                "/oic/ad",
+                "/oic/sec/acl"
+                       ],
+                       "perms": 2,
+                       "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+               },
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/sec/doxm",
+                "/oic/sec/pstat"
+             ],
+             "perms": 2,
+             "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+        },
+        {
+            "sub": "Kg==",
+            "rsrc": ["/light0", "/light1", "/a/light"],
+            "perms": 6,
+            "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+        }
+       ],
+       "pstat":        {
+               "isop": true,
+               "deviceid":     "ZGV2aWNlaWQAAAAAABhanw==",
+               "ch": 0,
+               "cm":   0,
+               "tm":   0,
+               "om":   3,
+               "sm":   [3]
+       },
+       "doxm": {
+               "oxm":  [0],
+               "oxmsel": 0,
+               "owned": true,
+               "deviceid":     "MTExMTExMTExMTExMTExMQ==",
+               "ownr": "MjIyMjIyMjIyMjIyMjIyMg=="
+       },
+    "cred":    [{
+               "credid": 1,
+               "sub": "MjIyMjIyMjIyMjIyMjIyMg==",
+               "credtyp": 1,
+               "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+        "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+       }]
+}
index e8414a0..a658663 100644 (file)
@@ -305,4 +305,4 @@ public class LightResource implements IMessageLogger {
         intent.putExtra(StringConstants.MESSAGE, text);\r
         mContext.sendBroadcast(intent);\r
     }\r
-}
\ No newline at end of file
+}\r
index 31b5c6a..b48a9f5 100644 (file)
@@ -36,6 +36,9 @@ import android.view.Menu;
 import android.view.MenuItem;\r
 import android.widget.LinearLayout;\r
 import android.widget.TextView;\r
+import android.content.SharedPreferences;\r
+import android.content.res.AssetManager;\r
+import android.preference.PreferenceManager;\r
 \r
 import org.iotivity.base.ModeType;\r
 import org.iotivity.base.OcPlatform;\r
@@ -44,6 +47,13 @@ import org.iotivity.base.PlatformConfig;
 import org.iotivity.base.QualityOfService;\r
 import org.iotivity.base.ServiceType;\r
 \r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+\r
 import base.iotivity.org.examples.message.IMessageLogger;\r
 \r
 /**\r
@@ -56,6 +66,8 @@ import base.iotivity.org.examples.message.IMessageLogger;
 \r
 public class SimpleServer extends Activity implements IMessageLogger {\r
     private final static String TAG = "SimpleServer: ";\r
+    private static final int BUFFER_SIZE = 1024;
+    private String filePath = "";\r
     private TextView mEventsTextView;\r
     private MessageReceiver mMessageReceiver = new MessageReceiver();\r
 \r
@@ -73,10 +85,72 @@ public class SimpleServer extends Activity implements IMessageLogger {
         OcRepresentation rep = new OcRepresentation();\r
         rep.setValueBool("test", false);\r
         boolean result = rep.getValueBool("test");\r
+        filePath = getFilesDir().getPath() + "/";//  data/data/<package>/files/\r
+        //copy json when application runs first time\r
+        SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);\r
+        boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);\r
+        if (isFirstRun) {\r
+            copyJsonFromAsset();\r
+            SharedPreferences.Editor editor = wmbPreference.edit();\r
+            editor.putBoolean("FIRSTRUN", false);\r
+            editor.commit();\r
+        }
 \r
         initOICStack();\r
     }\r
+
+    /**\r
+     * Copy svr db json file from assets folder to app data files dir\r
+     */\r
+    private void copyJsonFromAsset() {\r
+        AssetManager assetManager = getAssets();\r
+\r
+        InputStream in = null;\r
+        OutputStream out = null;\r
+        try {\r
+\r
+            in = assetManager.open(StringConstants.OIC_SERVER_JSON_DB_FILE);\r
+            File file = new File(filePath);\r
+            //check files directory exists\r
+            if (!(file.exists() && file.isDirectory())) {\r
+                file.mkdirs();\r
+            }\r
+            out = new FileOutputStream(filePath + StringConstants.OIC_SERVER_JSON_DB_FILE);\r
+            copyFile(in, out);\r
+        } catch (NullPointerException e) {\r
+            logMessage(TAG + "Null pointer exception " + e.getMessage());\r
+            Log.e(TAG, e.getMessage());\r
+        } catch (FileNotFoundException e) {\r
+            logMessage(TAG + "Json svr db file not found " + e.getMessage());\r
+            Log.e(TAG, e.getMessage());\r
+        } catch (IOException e) {\r
+            logMessage(TAG + StringConstants.OIC_SERVER_JSON_DB_FILE + " file copy failed");\r
+            Log.e(TAG, e.getMessage());\r
+        } finally {\r
+            if (in != null) {\r
+                try {\r
+                    in.close();\r
+                } catch (IOException e) {\r
+                    Log.e(TAG, e.getMessage());\r
+                }\r
+            }\r
+            if (out != null) {\r
+                try {\r
+                    out.close();\r
+                } catch (IOException e) {\r
+                    Log.e(TAG, e.getMessage());\r
+                }\r
+            }\r
+        }\r
+    }\r
 \r
+    private void copyFile(InputStream in, OutputStream out) throws IOException {\r
+        byte[] buffer = new byte[BUFFER_SIZE];\r
+        int read;\r
+        while ((read = in.read(buffer)) != -1) {\r
+            out.write(buffer, 0, read);\r
+        }\r
+    }\r
     /**\r
      * configure OIC platform and call findResource\r
      */\r
@@ -88,14 +162,15 @@ public class SimpleServer extends Activity implements IMessageLogger {
                 ModeType.SERVER,\r
                 "0.0.0.0", // bind to all available interfaces\r
                 0,\r
-                QualityOfService.LOW);\r
+                QualityOfService.LOW,\r
+                filePath + StringConstants.OIC_SERVER_JSON_DB_FILE);\r
         OcPlatform.Configure(cfg);\r
         // Create instance of lightResource\r
         LightResource myLight = new LightResource(this);\r
         // create and register a resource\r
         myLight.createResource0();\r
     }\r
-\r
+
     public class MessageReceiver extends BroadcastReceiver {\r
         @Override\r
         public void onReceive(Context context, Intent intent) {\r
index 98f33d0..f4836fa 100644 (file)
@@ -11,6 +11,7 @@ public interface StringConstants {
     public static final String RESOURCE_URI0 = "/light0";\r
     public static final String RESOURCE_URI1 = "/light1";\r
     public static final String RESOURCE_TYPENAME = "core.light";\r
+    public static final String OIC_SERVER_JSON_DB_FILE =  "oic_svr_db_server.json";\r
     public static final String RESOURCE_INTERFACE = OcPlatform.DEFAULT_INTERFACE; //resource interface\r
     public static final String CREATED_URI = "createduri";\r
     public static final String STATE = "state";\r
index f07579e..6fc5b42 100644 (file)
@@ -79,6 +79,21 @@ OCStackResult SRMInitPolicyEngine();
  */
 void SRMDeInitPolicyEngine();
 
+/**
+ * @brief   Provisioning API response callback.
+ * @param object[IN]       endpoint instance.
+ * @param responseInfo[IN] instance of CAResponseInfo_t structure.
+ * @return true if received response is for provisioning API false otherwise.
+ */
+typedef bool (*SPResponseCallback) (const CAEndpoint_t *object,
+                                    const CAResponseInfo_t *responseInfo);
+
+/**
+ * @brief function to register provisoning API's response callback.
+ * @param respHandler response handler callback.
+ */
+void SRMRegisterProvisioningResponseHandler(SPResponseCallback respHandler);
+
 #ifdef __cplusplus
 }
 #endif
index 7b9255c..017eb79 100644 (file)
@@ -73,6 +73,7 @@ extern const char * OIC_JSON_SM_NAME;
 
 extern OicUuid_t WILDCARD_SUBJECT_ID;
 extern size_t WILDCARD_SUBJECT_ID_LEN;
+extern const char * WILDCARD_RESOURCE_URI;
 
 //Ownership Transfer Methods
 extern const char * OXM_JUST_WORKS;
index d093b12..d5cc915 100644 (file)
@@ -86,4 +86,6 @@ provisioningserver = provisioning_env.StaticLibrary('ocspapi', provisioning_src)
 provisioning_env.InstallTarget(provisioningserver, 'libocspapi')
 provisioning_env.UserInstallTargetLib(provisioningserver, 'libocspapi')
 
-SConscript('sample/SConscript')
+if target_os in ['linux']:
+       SConscript('sample/SConscript')
+
index 14eed5f..a91df2a 100644 (file)
@@ -43,7 +43,6 @@
 #include "oic_malloc.h"
 #include "logger.h"
 #include "cacommon.h"
-#include "ocpayload.h"
 #include "cainterface.h"
 #include "provisioningmanager.h"
 #include "credentialgenerator.h"
@@ -54,6 +53,9 @@
 #include "pstatresource.h"
 #include "srmresourcestrings.h"
 #include "credresource.h"
+#include "oic_string.h"
+#include "secureresourcemanager.h"
+
 
 typedef enum
 {
@@ -91,7 +93,7 @@ typedef enum
 #define COAPS_QUERY "coaps://%s:%d%s"
 #define CA_SECURE_PORT   5684
 
-void (*handler)(const CAEndpoint_t *, const CAResponseInfo_t *);
+bool (*handler)(const CAEndpoint_t *, const CAResponseInfo_t *);
 
 /**
  * CA token to keep track of response.
@@ -311,11 +313,18 @@ static CAResult_t sendCARequest(CAMethod_t method,
                                 const char *resourceUri,
                                 char *payload, int payloadLen)
 {
+    if (payload && '\0' != (*(payload + payloadLen)))
+    {
+        OC_LOG(ERROR, TAG, "Payload not properly terminated.");
+        return CA_STATUS_INVALID_PARAM;
+    }
+
     if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN))
     {
         OC_LOG(ERROR, TAG, "Error while generating token");
         return CA_MEMORY_ALLOC_FAILED;
     }
+
     CAEndpoint_t *endpoint = NULL;
     if (CA_STATUS_OK != CACreateEndpoint((CATransportFlags_t)secure,
                                          devAddr->adapter, devAddr->addr,
@@ -325,27 +334,22 @@ static CAResult_t sendCARequest(CAMethod_t method,
         CADestroyEndpoint(endpoint);
         return CA_STATUS_FAILED;
     }
-    CAMessageType_t msgType = CA_MSG_CONFIRM;
-    if (payload && '\0' != (*(payload + payloadLen)))
-    {
-        OC_LOG(ERROR, TAG, "Payload not properly terminated.");
-        CADestroyEndpoint(endpoint);
-        return CA_STATUS_INVALID_PARAM;
-    }
-    OCSecurityPayload secPayload;
+
+    OCSecurityPayload secPayload = {};
     secPayload.securityData = payload;
     secPayload.base.type = PAYLOAD_TYPE_SECURITY;
-    CARequestInfo_t requestInfo = { 0 };
+
+    CARequestInfo_t requestInfo = {};
     requestInfo.method = method;
     requestInfo.isMulticast = false;
     OCConvertPayload((OCPayload*)(&secPayload), &requestInfo.info.payload,
             &requestInfo.info.payloadSize);
-    requestInfo.info.type = msgType;
+
+    requestInfo.info.type = CA_MSG_CONFIRM;
     requestInfo.info.token = gToken;
     requestInfo.info.tokenLength  = CA_MAX_TOKEN_LEN;
-    requestInfo.info.resourceUri  = resourceUri;
+    requestInfo.info.resourceUri  = (CAURI_t)resourceUri;
 
-    requestInfo.isMulticast = false;
     CAResult_t caResult = CA_STATUS_OK;
     caResult = CASendRequest(endpoint, &requestInfo);
     if (CA_STATUS_OK != caResult)
@@ -359,15 +363,13 @@ static CAResult_t sendCARequest(CAMethod_t method,
 /**
  * addDevice to list.
  *
- * @param[in] ip                    IP of target device.
- * @param[in] port                  port of remote server.
- * @param[in] adapter              adapter type of endpoint.
- * @param[in] doxm                  pointer to doxm instance.
+ * @param[in] endpoint   Endpoint information
+ * @param[in] doxm   pointer to doxm instance.
  * @return SP_RESULT_SUCCESS for success and errorcode otherwise.
  */
-static SPResult addDevice(const char *ip, int port, OCTransportAdapter adapter, OicSecDoxm_t *doxm)
+static SPResult addDevice(const CAEndpoint_t *endpoint, OicSecDoxm_t* doxm)
 {
-    if (NULL == ip || 0 >= port)
+    if (NULL == endpoint)
     {
         return SP_RESULT_INVALID_PARAM;
     }
@@ -378,10 +380,7 @@ static SPResult addDevice(const char *ip, int port, OCTransportAdapter adapter,
         return SP_RESULT_MEM_ALLOCATION_FAIL;
     }
 
-    SPStringCopy(ptr->endpoint.addr, ip, MAX_ADDR_STR_SIZE);
-    ptr->endpoint.port = port;
-    ptr->endpoint.adapter = adapter;
-
+    memcpy(&(ptr->endpoint), endpoint, sizeof(CAEndpoint_t));
     ptr->doxm = doxm;
 
     ptr->next = NULL;
@@ -428,14 +427,14 @@ static SPResult selectProvisioningMethod(OicSecOxm_t *supportedMethods, size_t n
     return SP_RESULT_SUCCESS;
 }
 
-OCStackResult OCParsePayload(OCPayload** outPayload, const uint8_t* payload, size_t payloadSize);
 /**
  * Response handler for discovery.
  *
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
+ * @return true is CA token matches request token, false otherwise.
  */
-static void ProvisionDiscoveryHandler(const CAEndpoint_t *object,
+static bool ProvisionDiscoveryHandler(const CAEndpoint_t *object,
                                       const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_DISCOVERY_STARTED) && gToken)
@@ -469,20 +468,22 @@ static void ProvisionDiscoveryHandler(const CAEndpoint_t *object,
                 {
                     OC_LOG(DEBUG, TAG, "Successfully converted doxm json to bin.");
 
-                    SPResult res = addDevice(object->addr, object->port, object->adapter, ptrDoxm);
+                    SPResult res = addDevice(object, ptrDoxm);
                     if (SP_RESULT_SUCCESS != res)
                     {
                         OC_LOG(ERROR, TAG, "Error while adding data to linkedlist.");
                         gStateManager = gStateManager | SP_DISCOVERY_ERROR;
                         DeleteDoxmBinData(ptrDoxm);
-                        return;
+                        return true;
                     }
                     OC_LOG(INFO, TAG, "Exiting ProvisionDiscoveryHandler.");
                     gStateManager |= SP_DISCOVERY_DONE;
                 }
             }
+            return true;
         }
     }
+    return false;
 }
 
 /**
@@ -490,8 +491,9 @@ static void ProvisionDiscoveryHandler(const CAEndpoint_t *object,
  *
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
+ * @return true is CA token matches request token, false otherwise.
  */
-static void OwnerShipTransferModeHandler(const CAEndpoint_t *object,
+static bool OwnerShipTransferModeHandler(const CAEndpoint_t *object,
         const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_UP_OWN_TR_METH_STARTED) && gToken)
@@ -511,8 +513,10 @@ static void OwnerShipTransferModeHandler(const CAEndpoint_t *object,
                 gStateManager |= SP_UP_OWN_TR_METH_ERROR;
                 OC_LOG(ERROR, TAG, "Error in OwnerShipTransferModeHandler.");
             }
+            return true;
         }
     }
+    return false;
 }
 
 /**
@@ -520,8 +524,9 @@ static void OwnerShipTransferModeHandler(const CAEndpoint_t *object,
  *
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
+ * @return true is CA token matches request token, false otherwise.
  */
-static void ListMethodsHandler(const CAEndpoint_t *object,
+static bool ListMethodsHandler(const CAEndpoint_t *object,
                                const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_LIST_METHODS_STARTED) && gToken)
@@ -539,7 +544,7 @@ static void ListMethodsHandler(const CAEndpoint_t *object,
                 {
                     OC_LOG(ERROR, TAG, "response payload is null.");
                     gStateManager |= SP_LIST_METHODS_ERROR;
-                    return;
+                    return true;
                 }
 
                 OCPayload* payload;
@@ -557,7 +562,7 @@ static void ListMethodsHandler(const CAEndpoint_t *object,
                 {
                     OC_LOG(ERROR, TAG, "Error while converting json to pstat bin");
                     gStateManager |= SP_LIST_METHODS_ERROR;
-                    return;
+                    return true;
                 }
                 DeletePstatBinData(gPstat);
 
@@ -566,8 +571,10 @@ static void ListMethodsHandler(const CAEndpoint_t *object,
 
                 OC_LOG(INFO, TAG, "Exiting ListMethodsHandler.");
             }
+            return true;
         }
     }
+    return false;
 }
 
 /**
@@ -575,8 +582,9 @@ static void ListMethodsHandler(const CAEndpoint_t *object,
  *
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
+ * @return true is CA token matches request token, false otherwise.
  */
-static void OperationModeUpdateHandler(const CAEndpoint_t *object,
+static bool OperationModeUpdateHandler(const CAEndpoint_t *object,
                                        const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_UPDATE_OP_MODE_STARTED) && gToken)
@@ -595,8 +603,10 @@ static void OperationModeUpdateHandler(const CAEndpoint_t *object,
                 gStateManager |= SP_UPDATE_OP_MODE_ERROR;
                 OC_LOG(ERROR, TAG, "Error in OperationModeUpdateHandler.");
             }
+            return true;
         }
     }
+    return false;
 }
 
 /**
@@ -604,8 +614,9 @@ static void OperationModeUpdateHandler(const CAEndpoint_t *object,
  *
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
+ * @return true is CA token matches request token, false otherwise.
  */
-static void OwnerShipUpdateHandler(const CAEndpoint_t *object,
+static bool OwnerShipUpdateHandler(const CAEndpoint_t *object,
                                    const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_UPDATE_OWNER_STARTED) && gToken)
@@ -625,8 +636,10 @@ static void OwnerShipUpdateHandler(const CAEndpoint_t *object,
                 gStateManager |= SP_UPDATE_OWNER_ERROR;
                 OC_LOG(ERROR, TAG, "Error in OwnerShipUpdateHandler.");
             }
+            return true;
         }
     }
+    return false;
 }
 
 /**
@@ -634,8 +647,9 @@ static void OwnerShipUpdateHandler(const CAEndpoint_t *object,
  *
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
+ * @return true is CA token matches request token, false otherwise.
  */
-static void ACLProvisioningHandler(const CAEndpoint_t *object,
+static bool ACLProvisioningHandler(const CAEndpoint_t *object,
                                    const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_PROV_ACL_STARTED) && gToken)
@@ -656,8 +670,10 @@ static void ACLProvisioningHandler(const CAEndpoint_t *object,
                 OC_LOG(ERROR, TAG, "Error in ACLProvisioningHandler.");
                 gStateManager |= SP_PROV_ACL_ERROR;
             }
+            return true;
         }
     }
+    return false;
 }
 
 /**
@@ -665,8 +681,9 @@ static void ACLProvisioningHandler(const CAEndpoint_t *object,
  *
  * @param[in] object       Remote endpoint object
  * @param[in] requestInfo  Datastructure containing request information.
+ * @return true is CA token matches request token, false otherwise.
  */
-static void FinalizeProvisioningHandler(const CAEndpoint_t *object,
+static bool FinalizeProvisioningHandler(const CAEndpoint_t *object,
                                         const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_UP_HASH_STARTED) && gToken)
@@ -686,8 +703,10 @@ static void FinalizeProvisioningHandler(const CAEndpoint_t *object,
                 gStateManager |= SP_UP_HASH_ERROR;
                 OC_LOG(ERROR, TAG, "Error in FinalizeProvisioningHandler.");
             }
+            return true;
         }
     }
+    return false;
 }
 
 /**
@@ -695,8 +714,9 @@ static void FinalizeProvisioningHandler(const CAEndpoint_t *object,
  *
  * @param[in] object        Remote endpoint object
  * @param[in] requestInfo   Datastructure containing request information.
+ * @return true is CA token matches request token, false otherwise.
  */
-static void CredProvisioningHandler(const CAEndpoint_t *object,
+static bool CredProvisioningHandler(const CAEndpoint_t *object,
                                     const CAResponseInfo_t *responseInfo)
 {
     if ((gStateManager & SP_PROV_CRED_STARTED) && gToken)
@@ -716,8 +736,10 @@ static void CredProvisioningHandler(const CAEndpoint_t *object,
                 gStateManager |= SP_PROV_CRED_ERROR;
                 OC_LOG(ERROR, TAG, "Error in CredProvisioningHandler.");
             }
+            return true;
         }
     }
+    return false;
 }
 
 /**
@@ -725,37 +747,17 @@ static void CredProvisioningHandler(const CAEndpoint_t *object,
  *
  * @param[in] object        Remote endpoint object
  * @param[in] responseInfo  Datastructure containing response information.
+ * @return true if received response is for provisioning API false otherwise.
  */
-static void SPResponseHandler(const CAEndpoint_t *object,
+static bool SPResponseHandler(const CAEndpoint_t *object,
                               const CAResponseInfo_t *responseInfo)
 {
+    bool isProvResponse = false;
     if ((NULL != responseInfo) && (NULL != responseInfo->info.token))
     {
-        handler(object, responseInfo);
+        isProvResponse = handler(object, responseInfo);
     }
-}
-
-/**
- * Error Handler
- *
- * @param[in] object     Remote endpoint object
- * @param[in] errorInfo  Datastructure containing error information.
- */
-static void SPErrorHandler(const CAEndpoint_t *object,
-                           const CAErrorInfo_t *errorInfo)
-{
-    OC_LOG(INFO, TAG, "Error Handler.");
-}
-
-/**
- * Request Handler
- *
- * @param[in] object       Remote endpoint object
- * @param[in] requestInfo  Datastructure containing request information.
- */
-static void SPRequestHandler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
-{
-    OC_LOG(INFO, TAG, "Request Handler.");
+    return isProvResponse;
 }
 
 /**
@@ -959,17 +961,9 @@ static SPResult updateOperationMode(unsigned short timeout,
  * @param[in]  deviceInfo  Provisioning context
  * @return SP_SUCCESS on success
  */
-static SPResult initiateDtlsHandshake(SPTargetDeviceInfo_t *deviceInfo)
+static SPResult initiateDtlsHandshake(const CAEndpoint_t *endpoint)
 {
-    CAResult_t caresult = CASelectCipherSuite(TLS_ECDH_anon_WITH_AES_128_CBC_SHA);
-
-    if (CA_STATUS_OK != caresult)
-    {
-        OC_LOG(ERROR, TAG, "Unable to select cipher suite");
-        return SP_RESULT_INTERNAL_ERROR;
-    }
-    OC_LOG(INFO, TAG, "Anonymous cipher suite selected. ");
-    caresult = CAEnableAnonECDHCipherSuite(true);
+    CAResult_t caresult = CAEnableAnonECDHCipherSuite(true);
     if (CA_STATUS_OK != caresult)
     {
         OC_LOG_V(ERROR, TAG, "Unable to enable anon cipher suite");
@@ -977,9 +971,7 @@ static SPResult initiateDtlsHandshake(SPTargetDeviceInfo_t *deviceInfo)
     }
     OC_LOG(INFO, TAG, "Anonymous cipher suite Enabled.");
 
-    //TODO: It is a temporary fix. Revisit it.
-    deviceInfo->endpoint.port = CA_SECURE_PORT;
-    caresult = CAInitiateHandshake((CAEndpoint_t *)&deviceInfo->endpoint);
+    caresult = CAInitiateHandshake(endpoint);
     if (CA_STATUS_OK != caresult)
     {
         OC_LOG_V(ERROR, TAG, "DTLS handshake failure.");
@@ -1023,7 +1015,7 @@ static SPResult sendOwnershipInfo(unsigned short timeout,
 
     CAResult_t result = sendCARequest(CA_PUT,
                                       &selectedDeviceInfo->endpoint,
-                                      OC_SECURE,
+                                      OC_FLAG_SECURE,
                                       OIC_RSRC_DOXM_URI,
                                       payloadBuffer, payloadLen);
     if (CA_STATUS_OK != result)
@@ -1055,9 +1047,8 @@ static SPResult saveOwnerPSK(SPTargetDeviceInfo_t *selectedDeviceInfo)
 {
     SPResult result = SP_RESULT_INTERNAL_ERROR;
 
-    CAEndpoint_t endpoint = {0};
-    strncpy(endpoint.addr, selectedDeviceInfo->endpoint.addr, MAX_ADDR_STR_SIZE_CA);
-    endpoint.addr[MAX_ADDR_STR_SIZE_CA - 1] = '\0';
+    CAEndpoint_t endpoint = {};
+    OICStrcpy(endpoint.addr, MAX_ADDR_STR_SIZE_CA, selectedDeviceInfo->endpoint.addr);
     endpoint.port = CA_SECURE_PORT;
 
     OicUuid_t provTooldeviceID = {};
@@ -1172,23 +1163,39 @@ static SPResult doOwnerShipTransfer(unsigned short timeout,
     }
     if (*selectedOperationMode == SINGLE_SERVICE_CLIENT_DRIVEN)
     {
-        res = initiateDtlsHandshake(selectedDeviceInfo);
-        if (SP_RESULT_SUCCESS != res)
+        CAEndpoint_t endpoint = {0};
+        OICStrcpy(endpoint.addr, MAX_ADDR_STR_SIZE_CA, selectedDeviceInfo->endpoint.addr);
+        endpoint.port = CA_SECURE_PORT;
+
+        res = initiateDtlsHandshake(&endpoint);
+        if (SP_RESULT_SUCCESS == res)
         {
-            OC_LOG(ERROR, TAG, "Error while DTLS handshake.");
-            return SP_RESULT_INTERNAL_ERROR;
-        }
+            selectedDeviceInfo->endpoint.port = CA_SECURE_PORT;
+            res = sendOwnershipInfo(timeout, selectedDeviceInfo);
+            if (SP_RESULT_SUCCESS != res)
+            {
+                OC_LOG(ERROR, TAG, "Error while updating ownership information.");
+            }
+            res = saveOwnerPSK(selectedDeviceInfo);
 
-        res = sendOwnershipInfo(timeout, selectedDeviceInfo);
-        if (SP_RESULT_SUCCESS != res)
+            //Close temporal DTLS session
+            if(CA_STATUS_OK != CACloseDtlsSession(&endpoint))
+            {
+                OC_LOG(WARNING, TAG, "doOwnerShipTransfer() : failed to close the dtls session");
+            }
+        }
+        else
         {
-            OC_LOG(ERROR, TAG, "Error while updating ownership information.");
-            return SP_RESULT_INTERNAL_ERROR;
+            OC_LOG(ERROR, TAG, "Error during initiating DTLS handshake.");
         }
 
-        saveOwnerPSK(selectedDeviceInfo);
+        //Disable Anonymous ECDH cipher suite before leaving this method
+        if(CA_STATUS_OK != CAEnableAnonECDHCipherSuite(false))
+        {
+            OC_LOG(WARNING, TAG, "doOwnerShipTransfer() : failed to disable Anon ECDH cipher suite");
+        }
     }
-    return SP_RESULT_SUCCESS;
+    return (res != SP_RESULT_SUCCESS) ? SP_RESULT_INTERNAL_ERROR : SP_RESULT_SUCCESS;
 
 }
 
@@ -1219,7 +1226,7 @@ SPResult provisionCredentials(unsigned short timeout, const OicSecCred_t *cred,
 
     CAResult_t result = sendCARequest(CA_POST,
                                       &deviceInfo->endpoint,
-                                      OC_SECURE,
+                                      OC_FLAG_SECURE,
                                       OIC_RSRC_CRED_URI,
                                       credJson, payloadLen);
     OICFree(credJson);
@@ -1238,6 +1245,7 @@ SPResult provisionCredentials(unsigned short timeout, const OicSecCred_t *cred,
         return SP_RESULT_TIMEOUT;
     }
     CADestroyToken(gToken);
+    gStateManager = 0;
     return res;
 }
 
@@ -1249,8 +1257,7 @@ SPResult SPProvisioningDiscovery(unsigned short timeout,
         OC_LOG(ERROR, TAG, "List is not null can cause memory leak");
         return SP_RESULT_INVALID_PARAM;
     }
-
-    CARegisterHandler(SPRequestHandler, SPResponseHandler, SPErrorHandler);
+    SRMRegisterProvisioningResponseHandler(SPResponseHandler);
     SPResult smResponse = SP_RESULT_SUCCESS;
     smResponse = findResource(timeout);
     if (SP_RESULT_SUCCESS != smResponse)
@@ -1324,7 +1331,7 @@ SPResult SPProvisionACL(unsigned short timeout, const SPTargetDeviceInfo_t *sele
 
     CAResult_t result = sendCARequest(CA_POST,
                                       &selectedDeviceInfo->endpoint,
-                                      OC_SECURE,
+                                      OC_FLAG_SECURE,
                                       OIC_RSRC_ACL_URI,
                                       aclString, payloadLen);
     OICFree(aclString);
@@ -1440,7 +1447,7 @@ SPResult SPFinalizeProvisioning(unsigned short timeout,
 
     CAResult_t result = sendCARequest(CA_PUT,
                                       &selectedDeviceInfo->endpoint,
-                                      OC_SECURE,
+                                      OC_FLAG_SECURE,
                                       OIC_RSRC_PSTAT_URI,
                                       payloadBuffer, payloadLen);
     OICFree(payloadBuffer);
@@ -1459,15 +1466,14 @@ SPResult SPFinalizeProvisioning(unsigned short timeout,
         return SP_RESULT_TIMEOUT;
     }
 
-    CAEndpoint_t endpoint = {0};
-    strncpy(endpoint.addr, selectedDeviceInfo->endpoint.addr, MAX_ADDR_STR_SIZE_CA);
-    endpoint.addr[DEV_ADDR_SIZE_MAX - 1] = '\0';
+    CAEndpoint_t endpoint = {};
+    OICStrcpy(endpoint.addr, MAX_ADDR_STR_SIZE_CA, selectedDeviceInfo->endpoint.addr);
     endpoint.port = CA_SECURE_PORT;
 
     result = CACloseDtlsSession(&endpoint);
     if (CA_STATUS_OK != result)
     {
-        OC_LOG_V(ERROR, TAG, "DTLS handshake failure.");
+        OC_LOG(WARNING, TAG, "Failed to close the DTLS session.");
     }
 
     CADestroyToken(gToken);
index dfc4422..c39814d 100644 (file)
@@ -196,7 +196,8 @@ exit:
  {
     for(size_t n = 0; n < acl->resourcesLen; n++)
     {
-        if(0 == strcmp(resource, acl->resources[n])) // TODO null terms?
+        if(0 == strcmp(resource, acl->resources[n]) || // TODO null terms?
+         0 == strcmp(WILDCARD_RESOURCE_URI, acl->resources[n]))
         {
             return true;
         }
index f83481d..8dee8b1 100644 (file)
@@ -37,6 +37,8 @@ static CAResponseCallback gResponseHandler = NULL;
 static CAErrorCallback gErrorHandler = NULL;
 //Persistent Storage callback handler for open/read/write/close/unlink
 static OCPersistentStorage *gPersistentStorageHandler =  NULL;
+//Provisioning response callback
+static SPResponseCallback gSPResponseHandler = NULL;
 
 /**
  * A single global Policy Engine context will suffice as long
@@ -45,6 +47,14 @@ static OCPersistentStorage *gPersistentStorageHandler =  NULL;
 PEContext_t g_policyEngineContext;
 
 /**
+ * @brief function to register provisoning API's response callback.
+ * @param respHandler response handler callback.
+ */
+void SRMRegisterProvisioningResponseHandler(SPResponseCallback respHandler)
+{
+    gSPResponseHandler = respHandler;
+}
+/**
  * @brief   Handle the request from the SRM.
  * @param   endPoint       [IN] Endpoint object from which the response is received.
  * @param   requestInfo    [IN] Information for the request.
@@ -132,7 +142,19 @@ void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requ
 void SRMResponseHandler(const CAEndpoint_t *endPoint, const CAResponseInfo_t *responseInfo)
 {
     OC_LOG(INFO, TAG, PCF("Received response from remote device"));
-    if (gResponseHandler)
+
+    // isProvResponse flag is to check whether response is catered by provisioning APIs or not.
+    // When token sent by CA response matches with token generated by provisioning request,
+    // gSPResponseHandler returns true and response is not sent to RI layer. In case
+    // gSPResponseHandler is null and isProvResponse is false response then the response is for
+    // RI layer.
+    bool isProvResponse = false;
+
+    if (gSPResponseHandler)
+    {
+        isProvResponse = gSPResponseHandler(endPoint, responseInfo);
+    }
+    if (!isProvResponse && gResponseHandler)
     {
         gResponseHandler(endPoint, responseInfo);
     }
index e8aee9e..02a5f0e 100644 (file)
@@ -70,7 +70,8 @@ const char * OIC_JSON_PRIVATEDATA_NAME = "pvdata";
 const char * OIC_JSON_PERIOD_NAME = "period";
 
 OicUuid_t WILDCARD_SUBJECT_ID = {"*"};
-size_t WILDCARD_SUBJECT_ID_LEN = 1 ;
+size_t WILDCARD_SUBJECT_ID_LEN = 1;
+const char * WILDCARD_RESOURCE_URI = "*";
 
 //Ownership Transfer Methods
 const char * OXM_JUST_WORKS = "oic.sec.doxm.jw";
index 914a5ee..731b203 100644 (file)
@@ -100,4 +100,10 @@ Alias("examples", [simpleserver, simpleclient,
      ])
 env.AppendTarget('examples')
 
-
+src_dir = examples_env.get('SRC_DIR')
+svr_db_src_dir = src_dir + '/resource/examples/'
+svr_db_build_dir = env.get('BUILD_DIR') +'/resource/examples/'
+examples_env.Alias("install", examples_env.Install( svr_db_build_dir,
+                svr_db_src_dir + 'oic_svr_db_client.json'))
+examples_env.Alias("install", examples_env.Install( svr_db_build_dir,
+                svr_db_src_dir + 'oic_svr_db_server.json'))
diff --git a/resource/examples/oic_svr_db_client.json b/resource/examples/oic_svr_db_client.json
new file mode 100755 (executable)
index 0000000..17dc43f
--- /dev/null
@@ -0,0 +1,49 @@
+{
+    "acl": [
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/res",
+                "/oic/d",
+                "/oic/p",
+                "/oic/res/types/d",
+                "/oic/ad",
+                "/oic/sec/acl"
+                       ],
+                       "perms": 2,
+                       "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+               },
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/sec/doxm",
+                "/oic/sec/pstat"
+             ],
+             "perms": 2,
+             "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+        }
+       ],
+       "pstat":        {
+               "isop": true,
+               "deviceid":     "ZGV2aWNlaWQAAAAAABhanw==",
+               "ch": 0,
+               "cm":   0,
+               "tm":   0,
+               "om":   3,
+               "sm":   [3]
+       },
+       "doxm": {
+               "oxm":  [0],
+               "oxmsel": 0,
+               "owned": true,
+               "deviceid":     "MjIyMjIyMjIyMjIyMjIyMg==",
+               "ownr": "MjIyMjIyMjIyMjIyMjIyMg=="
+       },
+    "cred":    [{
+               "credid": 1,
+               "sub": "MTExMTExMTExMTExMTExMQ==",
+               "credtyp": 1,
+               "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+        "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+       }]
+}
diff --git a/resource/examples/oic_svr_db_server.json b/resource/examples/oic_svr_db_server.json
new file mode 100755 (executable)
index 0000000..0a8cebe
--- /dev/null
@@ -0,0 +1,55 @@
+{
+    "acl": [
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/res",
+                "/oic/d",
+                "/oic/p",
+                "/oic/res/types/d",
+                "/oic/ad",
+                "/oic/sec/acl"
+                       ],
+                       "perms": 2,
+                       "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+               },
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/sec/doxm",
+                "/oic/sec/pstat"
+             ],
+             "perms": 2,
+             "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+        },
+        {
+            "sub": "Kg==",
+            "rsrc": ["/a/light"],
+            "perms": 6,
+            "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+        }
+       ],
+       "pstat":        {
+               "isop": true,
+               "deviceid":     "ZGV2aWNlaWQAAAAAABhanw==",
+               "ch": 0,
+               "cm":   0,
+               "tm":   0,
+               "om":   3,
+               "sm":   [3]
+       },
+       "doxm": {
+               "oxm":  [0],
+               "oxmsel": 0,
+               "owned": true,
+               "deviceid":     "MTExMTExMTExMTExMTExMQ==",
+               "ownr": "MjIyMjIyMjIyMjIyMjIyMg=="
+       },
+    "cred":    [{
+               "credid": 1,
+               "sub": "MjIyMjIyMjIyMjIyMjIyMg==",
+               "credtyp": 1,
+               "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+        "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+       }]
+}
index b241116..bb7620c 100644 (file)
@@ -412,10 +412,15 @@ void checkObserverValue(int value)
     }
 }
 
+static FILE* client_open(const char *path, const char *mode)
+{
+    return fopen("./oic_svr_db_client.json", mode);
+}
+
 int main(int argc, char* argv[]) {
 
     std::ostringstream requestURI;
-
+    OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
     try
     {
         printUsage();
@@ -442,10 +447,11 @@ int main(int argc, char* argv[]) {
     // Create PlatformConfig object
     PlatformConfig cfg {
         OC::ServiceType::InProc,
-        OC::ModeType::Client,
+        OC::ModeType::Both,
         "0.0.0.0",
         0,
-        OC::QualityOfService::LowQos
+        OC::QualityOfService::LowQos,
+        &ps
     };
 
     OCPlatform::Configure(cfg);
index f52588b..d89faf2 100644 (file)
@@ -482,10 +482,15 @@ void PrintUsage()
     std::cout << "    4 - Non-secure resource, GET slow response, notify all observers\n";
 }
 
+static FILE* client_open(const char *path, const char *mode)
+{
+    return fopen("./oic_svr_db_server.json", mode);
+}
 
 int main(int argc, char* argv[])
 {
     PrintUsage();
+    OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
 
     if (argc == 1)
     {
@@ -527,7 +532,8 @@ int main(int argc, char* argv[])
         OC::ModeType::Server,
         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
         0,         // Uses randomly available port
-        OC::QualityOfService::LowQos
+        OC::QualityOfService::LowQos,
+        &ps
     };
 
     OCPlatform::Configure(cfg);
index d3431ba..d38eb47 100755 (executable)
@@ -21,7 +21,6 @@
 #ifndef __INTEL_OCAPI_H_2014_07_10
 #define __INTEL_OCAPI_H_2014_07_10
 
-
 #include <string>
 #include <sstream>
 #include <vector>
@@ -112,7 +111,8 @@ namespace OC
     *  ModeType   : indicate whether we want to do server, client or both
     *  ServerConnectivity : default flags for server
     *  ClientConnectivity : default flags for client
-    *  QoS       : indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined).
+    *  QoS        : indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined).
+    *  ps         : persistant storage Handler structure (open/read/write/close/unlink)
     */
     struct PlatformConfig
     {
@@ -123,6 +123,7 @@ namespace OC
         std::string                ipAddress;   // not used
         uint16_t                   port;        // not used
         QualityOfService           QoS;
+        OCPersistentStorage        *ps;
 
         public:
             PlatformConfig()
@@ -132,34 +133,39 @@ namespace OC
                 clientConnectivity(CT_DEFAULT),
                 ipAddress("0.0.0.0"),
                 port(0),
-                QoS(QualityOfService::NaQos)
+                QoS(QualityOfService::NaQos),
+                ps(nullptr)
         {}
             PlatformConfig(const ServiceType serviceType_,
             const ModeType mode_,
             OCConnectivityType serverConnectivity_,
             OCConnectivityType clientConnectivity_,
-            const QualityOfService QoS_)
+            const QualityOfService QoS_,
+            OCPersistentStorage *ps_ = nullptr)
                 : serviceType(serviceType_),
                 mode(mode_),
                 serverConnectivity(serverConnectivity_),
                 clientConnectivity(clientConnectivity_),
                 ipAddress(""),
                 port(0),
-                QoS(QoS_)
+                QoS(QoS_),
+                ps(ps_)
         {}
             // for backward compatibility
             PlatformConfig(const ServiceType serviceType_,
             const ModeType mode_,
             const std::string& ipAddress_,
             const uint16_t port_,
-            const QualityOfService QoS_)
+            const QualityOfService QoS_,
+            OCPersistentStorage *ps_ = nullptr)
                 : serviceType(serviceType_),
                 mode(mode_),
                 serverConnectivity(CT_DEFAULT),
                 clientConnectivity(CT_DEFAULT),
                 ipAddress(ipAddress_),
                 port(port_),
-                QoS(QoS_)
+                QoS(QoS_),
+                ps(ps_)
         {}
     };
 
index 41cea2c..63668d5 100644 (file)
@@ -40,7 +40,7 @@ namespace OC
 
         public:
             ListenOCContainer(std::weak_ptr<IClientWrapper> cw,
-                    const OCDevAddr& devAddr, OCDiscoveryPayload* payload)
+                    OCDevAddr& devAddr, OCDiscoveryPayload* payload)
                     : m_clientWrapper(cw), m_devAddr(devAddr)
             {
                 OCResourcePayload* res = payload->resources;
@@ -53,6 +53,17 @@ namespace OC
                         uuidString[0]= '\0';
                     }
 
+                    if (res->secure)
+                    {
+                        m_devAddr.flags =
+                              (OCTransportFlags)(OC_FLAG_SECURE | m_devAddr.flags);
+                    }
+                    if (res->port != 0)
+                    {
+                         m_devAddr.port = res->port;
+                    }
+
                     m_resources.push_back(std::shared_ptr<OC::OCResource>(
                                 new OC::OCResource(m_clientWrapper, m_devAddr,
                                     std::string(res->uri),
@@ -73,7 +84,7 @@ namespace OC
         private:
             std::vector<std::shared_ptr<OC::OCResource>> m_resources;
             std::weak_ptr<IClientWrapper> m_clientWrapper;
-            const OCDevAddr& m_devAddr;
+            OCDevAddr& m_devAddr;
     };
     /*
     class ListenOCContainer
index 04d2673..2a612a6 100644 (file)
@@ -57,6 +57,7 @@ namespace OC
 
     void OCPlatform_impl::Configure(const PlatformConfig& config)
     {
+        OCRegisterPersistentStorageHandler(config.ps);
         globalConfig() = config;
     }
 
index 489f149..f526585 100644 (file)
@@ -31,7 +31,13 @@ namespace OCPlatformTest
     const std::string gResourceInterface = DEFAULT_INTERFACE;
     const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
     OCResourceHandle resourceHandle;
+  //OCPersistent Storage Handlers
 
+   static FILE* client_open(const char *path, const char *mode)
+   {
+       std::cout << "<===Opening SVR DB file = './oic_svr_db_client.json' with mode = '"<< mode<<"' "<<std::endl;
+               return fopen("./oic_svr_db_client.json", mode);
+   }
     // Callbacks
     OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
     {
@@ -214,6 +220,67 @@ namespace OCPlatformTest
                  resourceHandle, uri, type,
                  gResourceInterface, entityHandler, gResourceProperty));
     }
+    //PersistentStorageTest
+    TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
+    {
+        PlatformConfig cfg {
+             OC::ServiceType::InProc,
+             OC::ModeType::Both,
+             "0.0.0.0",
+             0,
+             OC::QualityOfService::LowQos
+         };
+         OCPlatform::Configure(cfg);
+         EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
+     }
+
+    //PersistentStorageTest
+    TEST(ConfigureTest, ConfigureNULLPersistentStorage)
+    {
+        PlatformConfig cfg {
+             OC::ServiceType::InProc,
+             OC::ModeType::Both,
+             "0.0.0.0",
+             0,
+             OC::QualityOfService::LowQos,
+             nullptr
+         };
+         OCPlatform::Configure(cfg);
+         EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
+     }
+
+    //PersistentStorageTest
+    TEST(ConfigureTest, ConfigurePersistentStorage)
+    {
+        OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
+        PlatformConfig cfg {
+             OC::ServiceType::InProc,
+             OC::ModeType::Both,
+             "0.0.0.0",
+             0,
+             OC::QualityOfService::LowQos,
+             &ps
+         };
+         OCPlatform::Configure(cfg);
+         EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
+     }
+
+    //PersistentStorageTest
+    TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
+    {
+        OCPersistentStorage ps {client_open, nullptr, nullptr, nullptr, nullptr };
+        PlatformConfig cfg {
+             OC::ServiceType::InProc,
+             OC::ModeType::Both,
+             "0.0.0.0",
+             0,
+             OC::QualityOfService::LowQos,
+             &ps
+         };
+         OCPlatform::Configure(cfg);
+         EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
+     }
+
 
     //RegisterResourceTest
     TEST(RegisterResourceTest, RegisterSingleResource)
@@ -699,5 +766,4 @@ namespace OCPlatformTest
                 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
     }
-
 }
index 3050b78..45c152d 100644 (file)
@@ -90,3 +90,9 @@ if env.get('TEST') == '1':
                ut = unittests_env.Command ('ut', None,
                 [ 'valgrind --leak-check=full --xml=yes --xml-file=resource_unittests_unittests.memcheck ' + out_dir + 'resource/unittests/unittests'])
                AlwaysBuild ('ut')
+
+src_dir = unittests_env.get('SRC_DIR')
+svr_db_src_dir = src_dir + '/resource/examples/'
+svr_db_build_dir = env.get('BUILD_DIR') +'/resource/unittests/'
+unittests_env.Alias("install", unittests_env.Install( svr_db_build_dir,
+                                svr_db_src_dir + 'oic_svr_db_client.json'))