Implementation of JNI for new resource model schema classes.
authorHarish Kumara Marappa <h.marappa@samsung.com>
Thu, 11 Feb 2016 14:13:26 +0000 (19:43 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 15 Feb 2016 01:42:55 +0000 (01:42 +0000)
Modified JNI code for SimulatorResourceModel and AttributeProperty classes
for converting from Java to C++ and vice versa.

Change-Id: Ie40c4dc17d5712fcdb373dd5e23837baff3b6171
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4953
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
30 files changed:
service/simulator/SConscript
service/simulator/java/jni/jni_listener_holder.h
service/simulator/java/jni/jni_map.cpp [new file with mode: 0644]
service/simulator/java/jni/jni_map.h [new file with mode: 0644]
service/simulator/java/jni/jni_queryparam.h
service/simulator/java/jni/jni_string.cpp
service/simulator/java/jni/jni_vector.cpp
service/simulator/java/jni/jni_vector.h
service/simulator/java/jni/simulator_collection_resource_jni.cpp
service/simulator/java/jni/simulator_device_info_jni.cpp
service/simulator/java/jni/simulator_device_info_jni.h
service/simulator/java/jni/simulator_exceptions_jni.cpp
service/simulator/java/jni/simulator_exceptions_jni.h
service/simulator/java/jni/simulator_init_jni.cpp
service/simulator/java/jni/simulator_manager_jni.cpp
service/simulator/java/jni/simulator_platform_info_jni.cpp
service/simulator/java/jni/simulator_platform_info_jni.h
service/simulator/java/jni/simulator_remote_resource_jni.cpp
service/simulator/java/jni/simulator_resource_attribute_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_resource_attribute_jni.h [new file with mode: 0644]
service/simulator/java/jni/simulator_resource_jni.cpp
service/simulator/java/jni/simulator_resource_model_jni.cpp
service/simulator/java/jni/simulator_resource_model_jni.h
service/simulator/java/jni/simulator_resource_model_schema_jni.cpp [new file with mode: 0644]
service/simulator/java/jni/simulator_resource_model_schema_jni.h [new file with mode: 0644]
service/simulator/java/jni/simulator_resource_utils_jni.cpp
service/simulator/java/jni/simulator_resource_utils_jni.h
service/simulator/java/jni/simulator_single_resource_jni.cpp
service/simulator/java/jni/simulator_utils_jni.cpp
service/simulator/java/jni/simulator_utils_jni.h

index a155b40..2f262a5 100755 (executable)
@@ -71,7 +71,7 @@ simulator_env.AppendUnique(CPPPATH = ['../../extlibs/cjson'])
 simulator_env.PrependUnique(LIBS = ['octbstack', 'oc', 'RamlParser'])
 simulator_env.AppendUnique(LIBS = ['pthread'])
 
-simulator_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+simulator_env.AppendUnique(CXXFLAGS = ['-O2', '-Wall', '-fmessage-length=0', '-std=c++0x'])
 
 ######################################################################
 # Source files and Targets
@@ -86,4 +86,4 @@ simulator_env.InstallTarget(simulatorsdk, 'libSimulator')
 
 #Build sample application
 SConscript('examples/server/SConscript')
-SConscript('examples/client/SConscript')
\ No newline at end of file
+SConscript('examples/client/SConscript')
index 254aa68..092dfe7 100644 (file)
@@ -26,11 +26,11 @@ class JniListenerHolder
     public:
         ~JniListenerHolder()
         {
-            JNIEnv *env = getEnv();
+            JNIEnv *env = GetEnv();
             if (!env)
                 return;
             env->DeleteGlobalRef(m_listener);
-            releaseEnv();
+            ReleaseEnv();
         }
 
         jobject get()
@@ -51,4 +51,3 @@ class JniListenerHolder
 };
 
 #endif
-
diff --git a/service/simulator/java/jni/jni_map.cpp b/service/simulator/java/jni/jni_map.cpp
new file mode 100644 (file)
index 0000000..6d1daee
--- /dev/null
@@ -0,0 +1,43 @@
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "jni_map.h"
+#include "simulator_utils_jni.h"
+
+JniMap::JniMap(JNIEnv *env)
+{
+    m_env = env;
+
+    static jmethodID mapCtor = env->GetMethodID(
+                                       gSimulatorClassRefs.hashMapCls, "<init>", "()V");
+    m_hashMap = env->NewObject(gSimulatorClassRefs.hashMapCls, mapCtor);
+}
+
+void JniMap::put(jobject jKey, jobject jValue)
+{
+    static jmethodID putMethod = m_env->GetMethodID(gSimulatorClassRefs.hashMapCls,
+                                        "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+    m_env->CallObjectMethod(m_hashMap, putMethod, jKey, jValue);
+}
+
+jobject JniMap::get()
+{
+    return m_hashMap;
+}
diff --git a/service/simulator/java/jni/jni_map.h b/service/simulator/java/jni/jni_map.h
new file mode 100644 (file)
index 0000000..a94db78
--- /dev/null
@@ -0,0 +1,38 @@
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef JNI_MAP_H_
+#define JNI_MAP_H_
+
+#include <jni.h>
+
+class JniMap
+{
+    public:
+        JniMap(JNIEnv *env);
+        void put(jobject jKey, jobject jValue);
+        jobject get();
+
+    private:
+        JNIEnv *m_env;
+        jobject m_hashMap;
+};
+
+#endif
index 7b63171..dcdc44b 100644 (file)
@@ -29,7 +29,7 @@ class JniQueryParameter
 {
     public:
         JniQueryParameter(JNIEnv *env);
-        std::map<std::string, std::string> toCpp(jobject queryParams);
+        std::map<std::string, std::string> toCpp(jobject jQueryParams);
 
     private:
         JNIEnv *m_env;
index 95e77de..1c7ba83 100644 (file)
@@ -43,4 +43,3 @@ std::string JniString::get()
 {
     return std::string(m_cStr);
 }
-
index 5f2135f..10b8bd0 100644 (file)
 #include "jni_string.h"
 #include "simulator_utils_jni.h"
 
-JniVector::JniVector(JNIEnv *env) : m_env(env)
-{
-    m_vectorCls = gSimulatorClassRefs.vectorCls;
-}
+JniVector::JniVector(JNIEnv *env) : m_env(env) {}
 
 jobject JniVector::toJava()
 {
-    static jmethodID vectorCtor = m_env->GetMethodID(m_vectorCls, "<init>", "()V");
-    return m_env->NewObject(m_vectorCls, vectorCtor);
+    static jmethodID vectorCtor = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
+        "<init>", "()V");
+    return m_env->NewObject(gSimulatorClassRefs.vectorCls, vectorCtor);
 }
 
 jobject JniVector::toJava(std::vector<std::string> &cppVector)
 {
-    static jmethodID addMethod = m_env->GetMethodID(m_vectorCls, "add", "(Ljava/lang/Object;)Z");
+    static jmethodID addMethod = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
+        "add", "(Ljava/lang/Object;)Z");
 
     jobject vectorObject = toJava();
     if (!vectorObject)
@@ -51,11 +50,19 @@ jobject JniVector::toJava(std::vector<std::string> &cppVector)
     return vectorObject;
 }
 
+int JniVector::getSize(jobject jVector)
+{
+    static jmethodID sizeMethodID = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
+        "size", "()I");
+    return m_env->CallIntMethod(jVector, sizeMethodID);
+}
+
 void JniVector::addElementsCpp(jobject vector, int size, std::vector<int> &result)
 {
-    static jmethodID getMethod = m_env->GetMethodID(m_vectorCls, "get", "(I)Ljava/lang/Object;");
-    static jmethodID intValueMethod = m_env->GetMethodID(gSimulatorClassRefs.integerCls, "intValue",
-                                      "()I");
+    static jmethodID getMethod = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
+        "get", "(I)Ljava/lang/Object;");
+    static jmethodID intValueMethod = m_env->GetMethodID(gSimulatorClassRefs.integerCls,
+        "intValue", "()I");
 
     for (int index = 0; index < size; index++)
     {
@@ -67,9 +74,10 @@ void JniVector::addElementsCpp(jobject vector, int size, std::vector<int> &resul
 
 void JniVector::addElementsCpp(jobject vector, int size, std::vector<double> &result)
 {
-    static jmethodID getMethod = m_env->GetMethodID(m_vectorCls, "get", "(I)Ljava/lang/Object;");
+    static jmethodID getMethod = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
+        "get", "(I)Ljava/lang/Object;");
     static jmethodID doubleValueMethod = m_env->GetMethodID(gSimulatorClassRefs.doubleCls,
-                                         "doubleValue", "()D");
+        "doubleValue", "()D");
 
     for (int index = 0; index < size; index++)
     {
@@ -81,7 +89,8 @@ void JniVector::addElementsCpp(jobject vector, int size, std::vector<double> &re
 
 void JniVector::addElementsCpp(jobject vector, int size, std::vector<std::string> &result)
 {
-    static jmethodID getMethodID = m_env->GetMethodID(m_vectorCls, "get", "(I)Ljava/lang/Object;");
+    static jmethodID getMethodID = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
+        "get", "(I)Ljava/lang/Object;");
 
     for (int index = 0; index < size; index++)
     {
index 860c082..9e1903d 100644 (file)
@@ -31,13 +31,10 @@ class JniVector
         JniVector(JNIEnv *env);
 
         template <typename TYPE>
-        std::vector<TYPE> toCpp(jobject vector)
+        std::vector<TYPE> toCpp(jobject jVector)
         {
             std::vector<TYPE> result;
-            jmethodID sizeMethodID = m_env->GetMethodID(m_vectorCls, "size", "()I");
-
-            int size = m_env->CallIntMethod(vector, sizeMethodID);
-            addElementsCpp(vector, size, result);
+            addElementsCpp(jVector, getSize(jVector), result);
             return result;
         }
 
@@ -45,12 +42,12 @@ class JniVector
         jobject toJava();
 
     private:
+        int getSize(jobject jVector);
         void addElementsCpp(jobject vector, int size, std::vector<int> &result);
         void addElementsCpp(jobject vector, int size, std::vector<double> &result);
         void addElementsCpp(jobject vector, int size, std::vector<std::string> &result);
 
         JNIEnv *m_env;
-        jclass m_vectorCls;
 };
 
 #endif
index 1b9c2dc..36e7a68 100644 (file)
 
 #include "simulator_collection_resource.h"
 
-#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return;}
-#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return RET;}
+#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){ThrowBadObjectException(ENV, "No corresponsing native object!"); return;}
+#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){ThrowBadObjectException(ENV, "No corresponsing native object!"); return RET;}
 
 extern SimulatorResourceSP SimulatorResourceToCpp(JNIEnv *env, jobject object);
 
-SimulatorCollectionResourceSP SimulatorCollectionResourceToCpp(JNIEnv *env, jobject object)
+static SimulatorCollectionResourceSP simulatorCollectionResourceToCpp(JNIEnv *env, jobject object)
 {
     JniSharedObjectHolder<SimulatorCollectionResource> *jniResource =
-        GetHandle<JniSharedObjectHolder<SimulatorCollectionResource>>(env, object);
+        getHandle<JniSharedObjectHolder<SimulatorCollectionResource>>(env, object);
     if (jniResource)
         return jniResource->get();
     return nullptr;
@@ -46,10 +46,10 @@ extern "C" {
 #endif
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_server_SimulatorCollectionResource_getSupportedResources
+Java_org_oic_simulator_server_SimulatorCollectionResource_nativeGetSupportedResources
 (JNIEnv *env, jobject object)
 {
-    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    auto collectionResource = simulatorCollectionResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, collectionResource, nullptr)
 
     std::vector<std::string> supportedTypes = collectionResource->getSupportedResources();
@@ -57,15 +57,15 @@ Java_org_oic_simulator_server_SimulatorCollectionResource_getSupportedResources
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorCollectionResource_addChildResource
+Java_org_oic_simulator_server_SimulatorCollectionResource_nativeAddChildResource
 (JNIEnv *env, jobject object, jobject resource)
 {
     VALIDATE_INPUT(env, !resource, "Child resource is null!")
 
-    SimulatorResourceSP childResource = SimulatorResourceToCpp(env, resource);
+    auto childResource = SimulatorResourceToCpp(env, resource);
     VALIDATE_INPUT(env, !childResource, "No corresponding native object of child resource!")
 
-    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    auto collectionResource = simulatorCollectionResourceToCpp(env, object);
     VALIDATE_OBJECT(env, collectionResource)
 
     try
@@ -74,24 +74,24 @@ Java_org_oic_simulator_server_SimulatorCollectionResource_addChildResource
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorCollectionResource_removeChildResource
+Java_org_oic_simulator_server_SimulatorCollectionResource_nativeRemoveChildResource
 (JNIEnv *env, jobject object, jobject resource)
 {
     VALIDATE_INPUT(env, !resource, "Child resource is null!")
 
-    SimulatorResourceSP childResource = SimulatorResourceToCpp(env, resource);
+    auto childResource = SimulatorResourceToCpp(env, resource);
     VALIDATE_INPUT(env, !childResource, "No corresponding native object of child resource!")
 
-    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    auto collectionResource = simulatorCollectionResourceToCpp(env, object);
     VALIDATE_OBJECT(env, collectionResource)
 
     try
@@ -100,19 +100,19 @@ Java_org_oic_simulator_server_SimulatorCollectionResource_removeChildResource
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorCollectionResource_removeChildResourceByUri
+Java_org_oic_simulator_server_SimulatorCollectionResource_nativeRemoveChildResourceByUri
 (JNIEnv *env, jobject object, jstring uri)
 {
-    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    auto collectionResource = simulatorCollectionResourceToCpp(env, object);
     VALIDATE_OBJECT(env, collectionResource)
 
     try
@@ -122,30 +122,30 @@ Java_org_oic_simulator_server_SimulatorCollectionResource_removeChildResourceByU
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_server_SimulatorCollectionResource_getChildResource
+Java_org_oic_simulator_server_SimulatorCollectionResource_nativeGetChildResources
 (JNIEnv *env, jobject object)
 {
-    SimulatorCollectionResourceSP collectionResource = SimulatorCollectionResourceToCpp(env, object);
+    auto collectionResource = simulatorCollectionResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, collectionResource, nullptr)
 
     std::vector<SimulatorResourceSP> childResources = collectionResource->getChildResources();
-    return createSimulatorResourceVector(env,  childResources);
+    return CreateSimulatorResourceVector(env,  childResources);
 }
 
-JNIEXPORT void JNICALL Java_org_oic_simulator_server_SimulatorCollectionResource_dispose
+JNIEXPORT void JNICALL Java_org_oic_simulator_server_SimulatorCollectionResource_nativeDispose
 (JNIEnv *env, jobject object)
 {
     JniSharedObjectHolder<SimulatorCollectionResource> *resource =
-        GetHandle<JniSharedObjectHolder<SimulatorCollectionResource>>(env, object);
+        getHandle<JniSharedObjectHolder<SimulatorCollectionResource>>(env, object);
     delete resource;
 }
 
index 4ee9baa..1eb4cb0 100644 (file)
@@ -47,33 +47,3 @@ void JniDeviceInfo::setFieldValue(jobject jDeviceInfo, const std::string &fieldN
     jstring valueStr = m_env->NewStringUTF(value.c_str());
     m_env->SetObjectField(jDeviceInfo, fieldID, valueStr);
 }
-
-void onDeviceInfoReceived(jobject listener, const std::string &hostUri, DeviceInfo &deviceInfo)
-{
-    JNIEnv *env = getEnv();
-    if (!env)
-        return;
-
-    jclass listenerCls = env->GetObjectClass(listener);
-    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onDeviceFound",
-                                 "(Ljava/lang/String;Lorg/oic/simulator/DeviceInfo;)V");
-
-
-    jstring jHostUri = env->NewStringUTF(hostUri.c_str());
-    jobject jDeviceInfo = JniDeviceInfo(env).toJava(deviceInfo);
-    if (!jDeviceInfo)
-    {
-        releaseEnv();
-        return;
-    }
-
-    env->CallVoidMethod(listener, listenerMethodId, jHostUri, jDeviceInfo);
-    if (env->ExceptionCheck())
-    {
-        releaseEnv();
-        return;
-    }
-
-    releaseEnv();
-}
-
index c64f825..acb1495 100644 (file)
 #ifndef SIMULATOR_DEVICE_INFO_JNI_H_
 #define SIMULATOR_DEVICE_INFO_JNI_H_
 
-#include "simulator_device_info.h"
 #include <jni.h>
 
+#include "simulator_device_info.h"
+
 class JniDeviceInfo
 {
     public:
@@ -41,6 +42,4 @@ class JniDeviceInfo
         JNIEnv *m_env;
 };
 
-void onDeviceInfoReceived(jobject listener, const std::string &host, DeviceInfo &deviceInfo);
-
 #endif
index 041b844..5739364 100644 (file)
@@ -23,7 +23,7 @@
 
 extern SimulatorClassRefs gSimulatorClassRefs;
 
-void throwSimulatorException(JNIEnv *env, SimulatorResult code, const char *message)
+void ThrowSimulatorException(JNIEnv *env, SimulatorResult code, const char *message)
 {
     static jmethodID simulatorExceptionCtor = env->GetMethodID(
                 gSimulatorClassRefs.simulatorExceptionCls, "<init>", "(ILjava/lang/String;)V");
@@ -36,7 +36,7 @@ void throwSimulatorException(JNIEnv *env, SimulatorResult code, const char *mess
     }
 }
 
-void throwInvalidArgsException(JNIEnv *env, SimulatorResult code, const char *message)
+void ThrowInvalidArgsException(JNIEnv *env, SimulatorResult code, const char *message)
 {
     static jmethodID invalidArgsExceptionCtor = env->GetMethodID(
                 gSimulatorClassRefs.invalidArgsExceptionCls, "<init>", "(ILjava/lang/String;)V");
@@ -49,7 +49,7 @@ void throwInvalidArgsException(JNIEnv *env, SimulatorResult code, const char *me
     }
 }
 
-void throwNoSupportException(JNIEnv *env, const char *message)
+void ThrowNoSupportException(JNIEnv *env, const char *message)
 {
     static jmethodID noSupportExceptionCtor = env->GetMethodID(
                 gSimulatorClassRefs.noSupportExceptionCls, "<init>", "(Ljava/lang/String;)V");
@@ -62,7 +62,7 @@ void throwNoSupportException(JNIEnv *env, const char *message)
     }
 }
 
-void throwOperationInProgressException(JNIEnv *env, const char *message)
+void ThrowOperationInProgressException(JNIEnv *env, const char *message)
 {
     static jmethodID operationInProgressExceptionCtor = env->GetMethodID(
                 gSimulatorClassRefs.operationInProgressExceptionCls, "<init>", "(Ljava/lang/String;)V");
@@ -75,7 +75,7 @@ void throwOperationInProgressException(JNIEnv *env, const char *message)
     }
 }
 
-void throwBadObjectException(JNIEnv *env, const char *message)
+void ThrowBadObjectException(JNIEnv *env, const char *message)
 {
     static jmethodID simulatorExceptionCtor = env->GetMethodID(
                 gSimulatorClassRefs.simulatorExceptionCls, "<init>", "(ILjava/lang/String;)V");
index f7cc9d9..4add306 100644 (file)
 #define SIMULATOR_EXCEPTIONS_JNI_H_
 
 #include <jni.h>
+
 #include "simulator_error_codes.h"
 
-void throwSimulatorException(JNIEnv *env, SimulatorResult code, const char *message);
+void ThrowSimulatorException(JNIEnv *env, SimulatorResult code, const char *message);
 
-void throwInvalidArgsException(JNIEnv *env, SimulatorResult code, const char *message);
+void ThrowInvalidArgsException(JNIEnv *env, SimulatorResult code, const char *message);
 
-void throwNoSupportException(JNIEnv *env, const char *message);
+void ThrowNoSupportException(JNIEnv *env, const char *message);
 
-void throwOperationInProgressException(JNIEnv *env, const char *message);
+void ThrowOperationInProgressException(JNIEnv *env, const char *message);
 
-void throwBadObjectException(JNIEnv *env, const char *message);
+void ThrowBadObjectException(JNIEnv *env, const char *message);
 
 #endif
index 63178ae..2f0406a 100644 (file)
 #define ATTRIBUTE_TYPE_INFO_CLS "org/oic/simulator/AttributeValue$TypeInfo"
 #define ATTRIBUTE_PROPERTY_CLS "org/oic/simulator/AttributeProperty"
 #define ATTRIBUTE_PROPERTY_TYPE_CLS "org/oic/simulator/AttributeProperty$Type"
-#define AUTOMATION_TYPE_CLS "org/oic/simulator/server/SimulatorResource$AutoUpdateType"
+#define AUTO_UPDATE_TYPE_CLS "org/oic/simulator/server/SimulatorResource$AutoUpdateType"
 
 #define SIMULATOR_REMOTE_RESOURCE_CLS "org/oic/simulator/client/SimulatorRemoteResource"
+#define REQUEST_TYPE_CLS "org/oic/simulator/client/SimulatorRemoteResource$RequestType"
 #define OBSERVER_CLS "org/oic/simulator/server/Observer"
 #define DEVICE_INFO_CLS "org/oic/simulator/DeviceInfo"
 #define PLATFORM_INFO_CLS "org/oic/simulator/PlatformInfo"
+#define SIMULATOR_REQUEST_MODEL_CLS "org/oic/simulator/client/SimulatorRequestModel"
+
 #define SIMULATOR_EXCEPTION_CLS "org/oic/simulator/SimulatorException"
 #define INVALID_ARGS_EXCEPTION_CLS "org/oic/simulator/InvalidArgsException"
 #define NO_SUPPORT_EXCEPTION_CLS "org/oic/simulator/NoSupportException"
 #define OPERATION_IN_PROGRESS_EXCEPTION_CLS "org/oic/simulator/OperationInProgressException"
 #define SIMULATOR_RESULT_CLS "org/oic/simulator/SimulatorResult"
 
+#define INTEGER_PROPERTY "org/oic/simulator/IntegerProperty"
+#define INTEGER_PROPERTY_BUILDER "org/oic/simulator/IntegerProperty$Builder"
+#define DOUBLE_PROPERTY "org/oic/simulator/DoubleProperty"
+#define DOUBLE_PROPERTY_BUILDER "org/oic/simulator/DoubleProperty$Builder"
+#define BOOLEAN_PROPERTY "org/oic/simulator/BooleanProperty"
+#define BOOLEAN_PROPERTY_BUILDER "org/oic/simulator/BooleanProperty$Builder"
+#define STRING_PROPERTY "org/oic/simulator/StringProperty"
+#define STRING_PROPERTY_BUILDER "org/oic/simulator/StringProperty$Builder"
+#define ARRAY_PROPERTY "org/oic/simulator/ArrayProperty"
+#define ARRAY_PROPERTY_BUILDER "org/oic/simulator/ArrayProperty$Builder"
+#define MODEL_PROPERTY "org/oic/simulator/ModelProperty"
+
 #define INTEGER_1D_ARRAY "[Ljava/lang/Integer;"
 #define INTEGER_2D_ARRAY "[[Ljava/lang/Integer;"
 #define INTEGER_3D_ARRAY "[[Ljava/lang/Integer;"
@@ -76,7 +91,7 @@ SimulatorClassRefs gSimulatorClassRefs;
 static std::mutex gJvmMutex;
 static JavaVM *gJavaVM;
 
-JNIEnv *getEnv()
+JNIEnv *GetEnv()
 {
     std::unique_lock<std::mutex> lock(gJvmMutex);
     if (!gJavaVM)
@@ -96,7 +111,7 @@ JNIEnv *getEnv()
     return nullptr;
 }
 
-void releaseEnv()
+void ReleaseEnv()
 {
     std::unique_lock<std::mutex> lock(gJvmMutex);
     if (!gJavaVM)
@@ -118,7 +133,7 @@ static void getClassRef(JNIEnv *env, const char *className, jclass &classRef)
 extern "C" {
 #endif
 
-JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
 {
     if (!vm)
         return JNI_ERR;
@@ -139,30 +154,48 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     getClassRef(env, MAP_ENTRY_CLS, gSimulatorClassRefs.mapEntryCls);
     getClassRef(env, SET_CLS, gSimulatorClassRefs.setCls);
     getClassRef(env, ITERATOR_CLS, gSimulatorClassRefs.iteratorCls);
+
     getClassRef(env, SIMULATOR_RESOURCE_CLS, gSimulatorClassRefs.simulatorResourceCls);
     getClassRef(env, SIMULATOR_RESOURCE_TYPE_CLS, gSimulatorClassRefs.simulatorResourceTypeCls);
     getClassRef(env, SIMULATOR_SINGLE_RESOURCE_CLS, gSimulatorClassRefs.simulatorSingleResourceCls);
     getClassRef(env, SIMULATOR_COLLECTION_RESOURCE_CLS,
-                gSimulatorClassRefs.simulatorCollectionResourceCls);
-    getClassRef(env, SIMULATOR_REMOTE_RESOURCE_CLS, gSimulatorClassRefs.simulatorRemoteResourceCls);
+        gSimulatorClassRefs.simulatorCollectionResourceCls);
     getClassRef(env, SIMULATOR_RESOURCE_MODEL_CLS, gSimulatorClassRefs.simulatorResourceModelCls);
     getClassRef(env, SIMULATOR_RESOURCE_ATTRIBUTE_CLS,
-                gSimulatorClassRefs.simulatorResourceAttributeCls);
+        gSimulatorClassRefs.simulatorResourceAttributeCls);
     getClassRef(env, ATTRIBUTE_VALUE_CLS, gSimulatorClassRefs.attributeValueCls);
     getClassRef(env, ATTRIBUTE_VALUE_TYPE_CLS, gSimulatorClassRefs.attributeValueTypeCls);
     getClassRef(env, ATTRIBUTE_TYPE_INFO_CLS, gSimulatorClassRefs.attributeTypeInfoCls);
     getClassRef(env, ATTRIBUTE_PROPERTY_CLS, gSimulatorClassRefs.attributePropertyCls);
     getClassRef(env, ATTRIBUTE_PROPERTY_TYPE_CLS, gSimulatorClassRefs.attributePropertyTypeCls);
-    getClassRef(env, AUTOMATION_TYPE_CLS, gSimulatorClassRefs.automationTypeCls);
+    getClassRef(env, INTEGER_PROPERTY, gSimulatorClassRefs.integerPropertyCls);
+    getClassRef(env, INTEGER_PROPERTY_BUILDER, gSimulatorClassRefs.integerPropertyBuilderCls);
+    getClassRef(env, DOUBLE_PROPERTY, gSimulatorClassRefs.doublePropertyCls);
+    getClassRef(env, DOUBLE_PROPERTY_BUILDER, gSimulatorClassRefs.doublePropertyBuilderCls);
+    getClassRef(env, BOOLEAN_PROPERTY, gSimulatorClassRefs.booleanPropertyCls);
+    getClassRef(env, BOOLEAN_PROPERTY_BUILDER, gSimulatorClassRefs.booleanPropertyBuilderCls);
+    getClassRef(env, STRING_PROPERTY, gSimulatorClassRefs.stringPropertyCls);
+    getClassRef(env, STRING_PROPERTY_BUILDER, gSimulatorClassRefs.stringPropertyBuilderCls);
+    getClassRef(env, ARRAY_PROPERTY, gSimulatorClassRefs.arrayPropertyCls);
+    getClassRef(env, ARRAY_PROPERTY_BUILDER, gSimulatorClassRefs.arrayPropertyBuilderCls);
+    getClassRef(env, MODEL_PROPERTY, gSimulatorClassRefs.modelPropertyCls);
+    getClassRef(env, AUTO_UPDATE_TYPE_CLS, gSimulatorClassRefs.autoUpdateTypeCls);
+
+    getClassRef(env, SIMULATOR_REMOTE_RESOURCE_CLS,
+        gSimulatorClassRefs.simulatorRemoteResourceCls);
+    getClassRef(env, REQUEST_TYPE_CLS, gSimulatorClassRefs.requestTypeCls);
     getClassRef(env, OBSERVER_CLS, gSimulatorClassRefs.observerCls);
     getClassRef(env, DEVICE_INFO_CLS, gSimulatorClassRefs.deviceInfoCls);
     getClassRef(env, PLATFORM_INFO_CLS, gSimulatorClassRefs.platformInfoCls);
+    getClassRef(env, SIMULATOR_REQUEST_MODEL_CLS, gSimulatorClassRefs.simulatorRequestModelCls);
+
     getClassRef(env, SIMULATOR_EXCEPTION_CLS, gSimulatorClassRefs.simulatorExceptionCls);
     getClassRef(env, INVALID_ARGS_EXCEPTION_CLS, gSimulatorClassRefs.invalidArgsExceptionCls);
     getClassRef(env, NO_SUPPORT_EXCEPTION_CLS, gSimulatorClassRefs.noSupportExceptionCls);
     getClassRef(env, OPERATION_IN_PROGRESS_EXCEPTION_CLS,
-                gSimulatorClassRefs.operationInProgressExceptionCls);
+        gSimulatorClassRefs.operationInProgressExceptionCls);
     getClassRef(env, SIMULATOR_RESULT_CLS, gSimulatorClassRefs.simulatorResultCls);
+
     getClassRef(env, INTEGER_1D_ARRAY, gSimulatorClassRefs.integer1DArrayCls);
     getClassRef(env, INTEGER_2D_ARRAY, gSimulatorClassRefs.integer2DArrayCls);
     getClassRef(env, INTEGER_3D_ARRAY, gSimulatorClassRefs.integer3DArrayCls);
@@ -176,17 +209,17 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     getClassRef(env, STRING_2D_ARRAY, gSimulatorClassRefs.string2DArrayCls);
     getClassRef(env, STRING_3D_ARRAY, gSimulatorClassRefs.string3DArrayCls);
     getClassRef(env, SIMULATOR_RESOURCE_MODEL_1D_ARRAY,
-                gSimulatorClassRefs.simulatorResModel1DArrayCls);
+        gSimulatorClassRefs.simulatorResModel1DArrayCls);
     getClassRef(env, SIMULATOR_RESOURCE_MODEL_2D_ARRAY,
-                gSimulatorClassRefs.simulatorResModel2DArrayCls);
+        gSimulatorClassRefs.simulatorResModel2DArrayCls);
     getClassRef(env, SIMULATOR_RESOURCE_MODEL_3D_ARRAY,
-                gSimulatorClassRefs.simulatorResModel3DArrayCls);
+        gSimulatorClassRefs.simulatorResModel3DArrayCls);
 
     gJavaVM = vm;
     return JNI_VERSION_1_6;
 }
 
-JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void * /*reserved*/)
 {
     if (!vm)
         return;
@@ -207,6 +240,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
     env->DeleteGlobalRef(gSimulatorClassRefs.mapEntryCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.setCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.iteratorCls);
+
     env->DeleteGlobalRef(gSimulatorClassRefs.simulatorResourceCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.simulatorSingleResourceCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.simulatorCollectionResourceCls);
@@ -217,18 +251,49 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
     env->DeleteGlobalRef(gSimulatorClassRefs.attributeTypeInfoCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.attributePropertyCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.attributePropertyTypeCls);
-    env->DeleteGlobalRef(gSimulatorClassRefs.automationTypeCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.integerPropertyCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.integerPropertyBuilderCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.doublePropertyCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.doublePropertyBuilderCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.booleanPropertyCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.booleanPropertyBuilderCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.stringPropertyCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.stringPropertyBuilderCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.arrayPropertyCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.arrayPropertyBuilderCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.modelPropertyCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.autoUpdateTypeCls);
+
     env->DeleteGlobalRef(gSimulatorClassRefs.simulatorRemoteResourceCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.requestTypeCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.observerCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.deviceInfoCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.platformInfoCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorRequestModelCls);
+
     env->DeleteGlobalRef(gSimulatorClassRefs.simulatorExceptionCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.invalidArgsExceptionCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.noSupportExceptionCls);
     env->DeleteGlobalRef(gSimulatorClassRefs.operationInProgressExceptionCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorResultCls);
+
+    env->DeleteGlobalRef(gSimulatorClassRefs.integer1DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.integer2DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.integer3DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.double1DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.double2DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.double3DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.boolean1DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.boolean2DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.boolean3DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.string1DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.string2DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.string3DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorResModel1DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorResModel2DArrayCls);
+    env->DeleteGlobalRef(gSimulatorClassRefs.simulatorResModel3DArrayCls);
 }
 
 #ifdef __cplusplus
 }
 #endif
-
index 4a38aea..eb45d3d 100644 (file)
@@ -40,21 +40,21 @@ class JNILogger : public ILogger
 
         void write(std::string time, ILogger::Level level, std::string message)
         {
-            JNIEnv *env = getEnv();
+            JNIEnv *env = GetEnv();
             if (nullptr == env)
                 return;
 
             jobject logger = env->NewLocalRef(m_logger);
             if (!logger)
             {
-                releaseEnv();
+                ReleaseEnv();
                 return;
             }
 
             jclass loggerCls = env->GetObjectClass(logger);
             if (!loggerCls)
             {
-                releaseEnv();
+                ReleaseEnv();
                 return;
             }
 
@@ -62,7 +62,7 @@ class JNILogger : public ILogger
                                                   "(Ljava/lang/String;ILjava/lang/String;)V");
             if (!writeMId)
             {
-                releaseEnv();
+                ReleaseEnv();
                 return;
             }
 
@@ -71,16 +71,16 @@ class JNILogger : public ILogger
             env->CallVoidMethod(logger, writeMId, timeStr, static_cast<jint>(level), msg);
             env->DeleteLocalRef(msg);
             env->DeleteLocalRef(timeStr);
-            releaseEnv();
+            ReleaseEnv();
         }
 
     private:
         jweak m_logger;
 };
 
-void onResourceFound(jobject listener, std::shared_ptr<SimulatorRemoteResource> remoteResource)
+static void onResourceFound(jobject listener, SimulatorRemoteResourceSP remoteResource)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -88,12 +88,70 @@ void onResourceFound(jobject listener, std::shared_ptr<SimulatorRemoteResource>
     jmethodID callbackMethod = env->GetMethodID(listenerCls, "onResourceFound",
                                "(Lorg/oic/simulator/client/SimulatorRemoteResource;)V");
 
-    jobject resource = createSimulatorRemoteResource(env, remoteResource);
+    jobject resource = CreateSimulatorRemoteResource(env, remoteResource);
     if (!resource)
         return;
 
     env->CallVoidMethod(listener, callbackMethod, resource);
-    releaseEnv();
+    ReleaseEnv();
+}
+
+static void onDeviceInfoReceived(jobject listener, const std::string &hostUri, DeviceInfo &deviceInfo)
+{
+    JNIEnv *env = GetEnv();
+    if (!env)
+        return;
+
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onDeviceFound",
+                                 "(Ljava/lang/String;Lorg/oic/simulator/DeviceInfo;)V");
+
+
+    jstring jHostUri = env->NewStringUTF(hostUri.c_str());
+    jobject jDeviceInfo = JniDeviceInfo(env).toJava(deviceInfo);
+    if (!jDeviceInfo)
+    {
+        ReleaseEnv();
+        return;
+    }
+
+    env->CallVoidMethod(listener, listenerMethodId, jHostUri, jDeviceInfo);
+    if (env->ExceptionCheck())
+    {
+        ReleaseEnv();
+        return;
+    }
+
+    ReleaseEnv();
+}
+
+static void onPlatformInfoReceived(jobject listener, const std::string &hostUri,
+                            PlatformInfo &platformInfo)
+{
+    JNIEnv *env = GetEnv();
+    if (!env)
+        return;
+
+    jclass listenerCls = env->GetObjectClass(listener);
+    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPlatformFound",
+                                 "(Ljava/lang/String;Lorg/oic/simulator/PlatformInfo;)V");
+
+    jstring jHostUri = env->NewStringUTF(hostUri.c_str());
+    jobject jPlatformInfo = JniPlatformInfo(env).toJava(platformInfo);
+    if (!jPlatformInfo)
+    {
+        ReleaseEnv();
+        return;
+    }
+
+    env->CallVoidMethod(listener, listenerMethodId, jHostUri, jPlatformInfo);
+    if (env->ExceptionCheck())
+    {
+        ReleaseEnv();
+        return;
+    }
+
+    ReleaseEnv();
 }
 
 #ifdef __cplusplus
@@ -101,251 +159,251 @@ extern "C" {
 #endif
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorManager_createResource
-(JNIEnv *env, jclass object, jstring configPath)
+Java_org_oic_simulator_SimulatorManager_nativeCreateResource
+(JNIEnv *env, jobject /*object*/, jstring jConfigPath)
 {
-    VALIDATE_INPUT_RET(env, !configPath, "Path is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jConfigPath, "Path is null!", nullptr)
 
     try
     {
-        JniString jniPath(env, configPath);
+        JniString jniPath(env, jConfigPath);
         SimulatorResourceSP resource = SimulatorManager::getInstance()->createResource(
                                            jniPath.get());
-        return createSimulatorResource(env, resource);
+        return CreateSimulatorResource(env, resource);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 
     return nullptr;
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorManager_createResources
-(JNIEnv *env, jclass object, jstring configPath, jint count)
+Java_org_oic_simulator_SimulatorManager_nativeCreateResources
+(JNIEnv *env, jobject /*object*/, jstring jConfigPath, jint jCount)
 {
-    VALIDATE_INPUT_RET(env, !configPath, "Path is null!", nullptr)
-    VALIDATE_INPUT_RET(env, !count || count < 0, "Invalid count value!", nullptr)
+    VALIDATE_INPUT_RET(env, !jConfigPath, "Path is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jConfigPath || jCount < 0, "Invalid count value!", nullptr)
 
     try
     {
-        JniString jniPath(env, configPath);
+        JniString jniPath(env, jConfigPath);
         std::vector<SimulatorResourceSP> resources =
-            SimulatorManager::getInstance()->createResource(jniPath.get(), count);
-        return createSimulatorResourceVector(env, resources);
+            SimulatorManager::getInstance()->createResource(jniPath.get(), jCount);
+        return CreateSimulatorResourceVector(env, resources);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 
     return nullptr;
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorManager_createSingleResource
-(JNIEnv *env, jclass object, jstring name, jstring uri, jstring resourceType)
+Java_org_oic_simulator_SimulatorManager_nativeCreateSingleResource
+(JNIEnv *env, jobject /*object*/, jstring jName, jstring jUri, jstring jResourceType)
 {
-    VALIDATE_INPUT_RET(env, !name, "Name is null!", nullptr)
-    VALIDATE_INPUT_RET(env, !uri, "URI is null!", nullptr)
-    VALIDATE_INPUT_RET(env, !resourceType, "Resource type is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jName, "Name is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jUri, "URI is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jResourceType, "Resource type is null!", nullptr)
 
     try
     {
-        JniString jniName(env, name);
-        JniString jniUri(env, uri);
-        JniString jniResourceType(env, resourceType);
+        JniString jniName(env, jName);
+        JniString jniUri(env, jUri);
+        JniString jniResourceType(env, jResourceType);
 
         SimulatorSingleResourceSP resource = SimulatorManager::getInstance()->createSingleResource(
                 jniName.get(), jniUri.get(), jniResourceType.get());
-        return createSimulatorResource(env, std::dynamic_pointer_cast<SimulatorResource>(resource));
+        return CreateSimulatorResource(env, std::dynamic_pointer_cast<SimulatorResource>(resource));
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 
     return nullptr;
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_SimulatorManager_createCollectionResource
-(JNIEnv *env, jclass object, jstring name, jstring uri, jstring resourceType)
+Java_org_oic_simulator_SimulatorManager_nativeCreateCollectionResource
+(JNIEnv *env, jobject /*object*/, jstring jName, jstring jUri, jstring jResourceType)
 {
-    VALIDATE_INPUT_RET(env, !name, "Name is null!", nullptr)
-    VALIDATE_INPUT_RET(env, !uri, "URI is null!", nullptr)
-    VALIDATE_INPUT_RET(env, !resourceType, "Resource type is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jName, "Name is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jUri, "URI is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jResourceType, "Resource type is null!", nullptr)
 
     try
     {
-        JniString jniName(env, name);
-        JniString jniUri(env, uri);
-        JniString jniResourceType(env, resourceType);
+        JniString jniName(env, jName);
+        JniString jniUri(env, jUri);
+        JniString jniResourceType(env, jResourceType);
 
         SimulatorCollectionResourceSP resource = SimulatorManager::getInstance()->createCollectionResource(
                     jniName.get(), jniUri.get(), jniResourceType.get());
-        return createSimulatorResource(env, std::dynamic_pointer_cast<SimulatorResource>(resource));
+        return CreateSimulatorResource(env, std::dynamic_pointer_cast<SimulatorResource>(resource));
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 
     return nullptr;
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManager_searchResource
-(JNIEnv *env, jobject object, jstring resourceType, jobject listener)
+Java_org_oic_simulator_SimulatorManager_nativeSearchResource
+(JNIEnv *env, jobject /*object*/, jstring jResourceType, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
     ResourceFindCallback callback =  std::bind([](
                                          std::shared_ptr<SimulatorRemoteResource> resource,
                                          const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
         onResourceFound(listenerRef->get(), resource);
-    }, std::placeholders::_1, JniListenerHolder::create(env, listener));
+    }, std::placeholders::_1, JniListenerHolder::create(env, jListener));
 
     try
     {
-        if (!resourceType)
+        if (!jResourceType)
         {
             SimulatorManager::getInstance()->findResource(callback);
         }
         else
         {
-            JniString type(env, resourceType);
+            JniString type(env, jResourceType);
             SimulatorManager::getInstance()->findResource(type.get(), callback);
         }
 
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManager_setDeviceInfo
-(JNIEnv *env, jobject object, jstring deviceName)
+Java_org_oic_simulator_SimulatorManager_nativeSetDeviceInfo
+(JNIEnv *env, jobject /*object*/, jstring jDeviceName)
 {
-    VALIDATE_INPUT(env, !deviceName, "Device name is null!")
+    VALIDATE_INPUT(env, !jDeviceName, "Device name is null!")
 
     try
     {
-        JniString jniDeviceName(env, deviceName);
+        JniString jniDeviceName(env, jDeviceName);
         SimulatorManager::getInstance()->setDeviceInfo(jniDeviceName.get());
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManager_findDevices
-(JNIEnv *env, jobject object, jstring hostUri, jobject listener)
+Java_org_oic_simulator_SimulatorManager_nativeFindDevices
+(JNIEnv *env, jobject /*object*/, jstring jHostUri, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
     DeviceInfoCallback callback =  std::bind([](const std::string & host, DeviceInfo & deviceInfo,
                                    const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
         onDeviceInfoReceived(listenerRef->get(), host, deviceInfo);
-    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
+    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, jListener));
 
     try
     {
-        JniString jniHostUri(env, hostUri);
+        JniString jniHostUri(env, jHostUri);
         SimulatorManager::getInstance()->getDeviceInfo(jniHostUri.get(), callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManager_setPlatformInfo
-(JNIEnv *env, jobject object, jobject platformInfo)
+Java_org_oic_simulator_SimulatorManager_nativeSetPlatformInfo
+(JNIEnv *env, jobject /*object*/, jobject jPlatformInfo)
 {
-    VALIDATE_INPUT(env, !platformInfo, "Platform info is null!")
+    VALIDATE_INPUT(env, !jPlatformInfo, "Platform info is null!")
 
     try
     {
-        JniPlatformInfo jniPlatformInfo(env);
-        PlatformInfo info = jniPlatformInfo.toCpp(platformInfo);
+        PlatformInfo info = JniPlatformInfo(env).toCpp(jPlatformInfo);
         SimulatorManager::getInstance()->setPlatformInfo(info);
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManager_getPlatformInformation
-(JNIEnv *env, jobject object, jstring hostUri, jobject listener)
+Java_org_oic_simulator_SimulatorManager_nativeGetPlatformInformation
+(JNIEnv *env, jobject /*object*/, jstring jHostUri, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
-    PlatformInfoCallback callback =  std::bind([](const std::string & host, PlatformInfo & platformInfo,
+    PlatformInfoCallback callback =  std::bind([](const std::string & host,
+                                     PlatformInfo & platformInfo,
                                      const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
         onPlatformInfoReceived(listenerRef->get(), host, platformInfo);
-    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
+    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, jListener));
 
     try
     {
-        JniString jniHostUri(env, hostUri);
+        JniString jniHostUri(env, jHostUri);
         SimulatorManager::getInstance()->getPlatformInfo(jniHostUri.get(), callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManager_setLogger
-(JNIEnv *env, jobject object, jobject logger)
+Java_org_oic_simulator_SimulatorManager_nativeSetLogger
+(JNIEnv *env, jobject /*object*/, jobject jLogger)
 {
     static std::shared_ptr<JNILogger> target(new JNILogger());
-    target->setJavaLogger(env, logger);
+    target->setJavaLogger(env, jLogger);
     SimulatorManager::getInstance()->setLogger(target);
 }
 
index 8a27507..05b3383 100644 (file)
@@ -86,32 +86,3 @@ std::string JniPlatformInfo::getFieldValue(jobject jPlatformInfo, const std::str
     JniString value(m_env, jvalue);
     return value.get();
 }
-
-void onPlatformInfoReceived(jobject listener, const std::string &hostUri, PlatformInfo &platformInfo)
-{
-    JNIEnv *env = getEnv();
-    if (!env)
-        return;
-
-    jclass listenerCls = env->GetObjectClass(listener);
-    jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPlatformFound",
-                                 "(Ljava/lang/String;Lorg/oic/simulator/PlatformInfo;)V");
-
-    jstring jHostUri = env->NewStringUTF(hostUri.c_str());
-    jobject jPlatformInfo = JniPlatformInfo(env).toJava(platformInfo);
-    if (!jPlatformInfo)
-    {
-        releaseEnv();
-        return;
-    }
-
-    env->CallVoidMethod(listener, listenerMethodId, jHostUri, jPlatformInfo);
-    if (env->ExceptionCheck())
-    {
-        releaseEnv();
-        return;
-    }
-
-    releaseEnv();
-}
-
index 52196f4..b8398fd 100644 (file)
@@ -43,6 +43,4 @@ class JniPlatformInfo
         JNIEnv *m_env;
 };
 
-void onPlatformInfoReceived(jobject listener, const std::string &host, PlatformInfo &platformInfo);
-
 #endif
index f413696..104541f 100644 (file)
@@ -19,6 +19,7 @@
  ******************************************************************/
 
 #include "simulator_resource_model_jni.h"
+#include "simulator_resource_model_schema_jni.h"
 #include "simulator_exceptions_jni.h"
 #include "simulator_utils_jni.h"
 #include "jni_sharedobject_holder.h"
 #include "jni_queryparam.h"
 #include "jni_string.h"
 #include "jni_vector.h"
+#include "jni_map.h"
 
 #include "simulator_remote_resource.h"
 
-#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return;}
-#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return RET;}
+#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){ThrowBadObjectException(ENV, "No corresponsing native object!"); return;}
+#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){ThrowBadObjectException(ENV, "No corresponsing native object!"); return RET;}
 
-SimulatorRemoteResourceSP SimulatorRemoteResourceToCpp(JNIEnv *env, jobject object)
+static SimulatorRemoteResourceSP simulatorRemoteResourceToCpp(
+    JNIEnv *env, jobject object)
 {
     JniSharedObjectHolder<SimulatorRemoteResource> *jniResource =
-        GetHandle<JniSharedObjectHolder<SimulatorRemoteResource>>(env, object);
+        getHandle<JniSharedObjectHolder<SimulatorRemoteResource>>(env, object);
     if (jniResource)
         return jniResource->get();
     return nullptr;
 }
 
-void onObserveCallback(jobject listener, const std::string &uid, const int errorCode,
-                       SimulatorResourceModelSP representation, const int seq)
+static void onObserveCallback(jobject listener, const std::string &uid, SimulatorResult /*result*/,
+                       const SimulatorResourceModel &representation, const int seq)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -52,17 +55,16 @@ void onObserveCallback(jobject listener, const std::string &uid, const int error
     jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onObserveNotification",
                                  "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;I)V");
 
-    SimulatorResourceModel *resModel = representation.get();
-    jobject jResModel = simulatorResourceModelToJava(env, *resModel);
+    jobject jResModel = SimulatorResourceModelToJava(env, representation);
     jstring jUid = env->NewStringUTF(uid.c_str());
     env->CallVoidMethod(listener, listenerMethodId, jUid, jResModel, seq);
-    releaseEnv();
+    ReleaseEnv();
 }
 
-void onGetCallback(jobject listener, const std::string &uid, int errorCode,
-                   SimulatorResourceModelSP representation)
+static void onGetCallback(jobject listener, const std::string &uid, SimulatorResult result,
+                   const SimulatorResourceModel &representation)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -70,19 +72,18 @@ void onGetCallback(jobject listener, const std::string &uid, int errorCode,
     jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onGetResponse",
                                  "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResult;Lorg/oic/simulator/SimulatorResourceModel;)V");
 
-    SimulatorResourceModel *resModel = representation.get();
-    jobject jResModel = simulatorResourceModelToJava(env, *resModel);
+    jobject jResModel = SimulatorResourceModelToJava(env, representation);
     jstring jUid = env->NewStringUTF(uid.c_str());
     env->CallVoidMethod(listener, listenerMethodId, jUid,
-                        simulatorResultToJava(env, static_cast<SimulatorResult>(errorCode)), jResModel);
+                        SimulatorResultToJava(env, result), jResModel);
 
-    releaseEnv();
+    ReleaseEnv();
 }
 
-void onPutCallback(jobject listener, const std::string &uid, int errorCode,
-                   SimulatorResourceModelSP representation)
+static void onPutCallback(jobject listener, const std::string &uid, SimulatorResult result,
+                   const SimulatorResourceModel &representation)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -90,19 +91,18 @@ void onPutCallback(jobject listener, const std::string &uid, int errorCode,
     jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPutResponse",
                                  "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResult;Lorg/oic/simulator/SimulatorResourceModel;)V");
 
-    SimulatorResourceModel *resModel = representation.get();
-    jobject jResModel = simulatorResourceModelToJava(env, *resModel);
+    jobject jResModel = SimulatorResourceModelToJava(env, representation);
     jstring jUid = env->NewStringUTF(uid.c_str());
     env->CallVoidMethod(listener, listenerMethodId, jUid,
-                        simulatorResultToJava(env, static_cast<SimulatorResult>(errorCode)), jResModel);
+                        SimulatorResultToJava(env, result), jResModel);
 
-    releaseEnv();
+    ReleaseEnv();
 }
 
-void onPostCallback(jobject listener, const std::string &uid, int errorCode,
-                    SimulatorResourceModelSP representation)
+static void onPostCallback(jobject listener, const std::string &uid, SimulatorResult result,
+                    const SimulatorResourceModel &representation)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -110,19 +110,18 @@ void onPostCallback(jobject listener, const std::string &uid, int errorCode,
     jmethodID listenerMethodId = env->GetMethodID(listenerCls, "onPostResponse",
                                  "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResult;Lorg/oic/simulator/SimulatorResourceModel;)V");
 
-    SimulatorResourceModel *resModel = representation.get();
-    jobject jResModel = simulatorResourceModelToJava(env, *resModel);
+    jobject jResModel = SimulatorResourceModelToJava(env, representation);
     jstring jUid = env->NewStringUTF(uid.c_str());
     env->CallVoidMethod(listener, listenerMethodId, jUid,
-                        simulatorResultToJava(env, static_cast<SimulatorResult>(errorCode)), jResModel);
+                        SimulatorResultToJava(env, result), jResModel);
 
-    releaseEnv();
+    ReleaseEnv();
 }
 
-void onVerificationCallback(jobject listener, const std::string &uid, int id,
+static void onVerificationCallback(jobject listener, const std::string &uid, int id,
                             OperationState opState)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -147,203 +146,309 @@ void onVerificationCallback(jobject listener, const std::string &uid, int id,
 
     if (OP_COMPLETE == opState || OP_ABORT == opState)
         env->DeleteGlobalRef(listener);
-    releaseEnv();
+    ReleaseEnv();
 }
 
+class JniRequestType
+{
+    public:
+        static jobject toJava(JNIEnv *env, RequestType requestType)
+        {
+            switch (requestType)
+            {
+                case RequestType::RQ_TYPE_GET:
+                    {
+                        static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.requestTypeCls,
+                                                  "GET",
+                                                  "Lorg/oic/simulator/client/SimulatorRemoteResource$RequestType;");
+                        return env->GetStaticObjectField(gSimulatorClassRefs.requestTypeCls, fieldID);
+                    }
+
+                case RequestType::RQ_TYPE_PUT:
+                    {
+                        static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.requestTypeCls,
+                                                  "PUT",
+                                                  "Lorg/oic/simulator/client/SimulatorRemoteResource$RequestType;");
+                        return env->GetStaticObjectField(gSimulatorClassRefs.requestTypeCls, fieldID);
+                    }
+
+                case RequestType::RQ_TYPE_POST:
+                    {
+                        static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.requestTypeCls,
+                                                  "POST",
+                                                  "Lorg/oic/simulator/client/SimulatorRemoteResource$RequestType;");
+                        return env->GetStaticObjectField(gSimulatorClassRefs.requestTypeCls, fieldID);
+                    }
+
+                case RequestType::RQ_TYPE_DELETE:
+                    {
+                        static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.requestTypeCls,
+                                                  "DELETE",
+                                                  "Lorg/oic/simulator/client/SimulatorRemoteResource$RequestType;");
+                        return env->GetStaticObjectField(gSimulatorClassRefs.requestTypeCls, fieldID);
+                    }
+
+                default:
+                    break;
+            }
+
+            static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.requestTypeCls,
+                                      "UKNOWN",
+                                      "Lorg/oic/simulator/client/SimulatorRemoteResource$RequestType;");
+            return env->GetStaticObjectField(gSimulatorClassRefs.requestTypeCls, fieldID);
+        }
+
+        static RequestType toCpp(JNIEnv *env, jobject jRequestType)
+        {
+            static jmethodID ordinalMID = env->GetMethodID(
+                                    gSimulatorClassRefs.requestTypeCls, "ordinal", "()I");
+            int ordinal = env->CallIntMethod(jRequestType, ordinalMID);
+            return RequestType(ordinal);
+        }
+};
+
+class JniSimulatorRequestModel
+{
+    public:
+        static jobject toJava(JNIEnv *env, const SimulatorRequestModel &requestModel)
+        {
+            // Convert RequestType
+            jobject jRequestType = JniRequestType::toJava(env, requestModel.getType());
+
+            // Convert Query Parameters
+            JniMap jQueryParams(env);
+            for (auto &qpEntry : requestModel.getQueryParams())
+            {
+                jstring jQueryParamName = env->NewStringUTF((qpEntry.first).c_str());
+                jobject jQueryParamValues = JniVector(env).toJava(qpEntry.second);
+
+                jQueryParams.put(jQueryParamName, jQueryParamValues);
+            }
+
+            // Convert Request body model
+            jobject jRequestBodyModel  =
+                AttributePropertyToJava(env, requestModel.getRequestBodySchema());
+
+            // Create Java SimulatorResourceModel object
+            static jmethodID simulatorRequestModelCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorRequestModelCls, "<init>",
+                "(Lorg/oic/simulator/client/SimulatorRemoteResource$RequestType;"
+                "Ljava/util/Map;Lorg/oic/simulator/ModelProperty;)V");
+
+            return env->NewObject(gSimulatorClassRefs.simulatorRequestModelCls,
+                simulatorRequestModelCtor, jRequestType,
+                jQueryParams.get(), jRequestBodyModel);
+        }
+};
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 JNIEXPORT void JNICALL
 Java_org_oic_simulator_client_SimulatorRemoteResource_nativeGet
-(JNIEnv *env, jobject object, jstring resInterface, jobject queryParamsMap, jobject listener)
+(JNIEnv *env, jobject object, jstring jResInterface, jobject jQueryParams, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
-    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    SimulatorRemoteResourceSP resource = simulatorRemoteResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        JniString jniInterface(env, resInterface);
+        JniString jniInterface(env, jResInterface);
         std::map<std::string, std::string> queryParams =
-            JniQueryParameter(env).toCpp(queryParamsMap);
+            JniQueryParameter(env).toCpp(jQueryParams);
 
         SimulatorRemoteResource::ResponseCallback callback =  std::bind([](
-                    const std::string & uid, int errorCode, SimulatorResourceModelSP representation,
+                    const std::string & uid, SimulatorResult result,
+                    const SimulatorResourceModel & resModel,
                     const std::shared_ptr<JniListenerHolder> &listenerRef)
         {
-            onGetCallback(listenerRef->get(), uid, errorCode, representation);
+            onGetCallback(listenerRef->get(), uid, result, resModel);
         }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
-        JniListenerHolder::create(env, listener));
+        JniListenerHolder::create(env, jListener));
 
         resource->get(jniInterface.get(), queryParams, callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.what());
+        ThrowNoSupportException(env, e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
 Java_org_oic_simulator_client_SimulatorRemoteResource_nativePut
-(JNIEnv *env, jobject object, jstring resInterface, jobject queryParamsMap,
- jobject representation, jobject listener)
+(JNIEnv *env, jobject object, jstring jResInterface, jobject jQueryParams,
+ jobject jRepresentation, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
-    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    SimulatorRemoteResourceSP resource = simulatorRemoteResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        JniString jniInterface(env, resInterface);
+        JniString jniInterface(env, jResInterface);
         std::map<std::string, std::string> queryParams =
-            JniQueryParameter(env).toCpp(queryParamsMap);
+            JniQueryParameter(env).toCpp(jQueryParams);
 
         SimulatorResourceModel resModel;
-        simulatorResourceModelToCpp(env, representation, resModel);
-        SimulatorResourceModelSP resModelSP(new SimulatorResourceModel(resModel));
+        SimulatorResourceModelToCpp(env, jRepresentation, resModel);
 
         SimulatorRemoteResource::ResponseCallback callback =  std::bind([](
-                    const std::string & uid, int errorCode, SimulatorResourceModelSP representation,
+                    const std::string & uid, SimulatorResult result,
+                    const SimulatorResourceModel & resModel,
                     const std::shared_ptr<JniListenerHolder> &listenerRef)
         {
-            onPutCallback(listenerRef->get(), uid, errorCode, representation);
+            onPutCallback(listenerRef->get(), uid, result, resModel);
         }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
-        JniListenerHolder::create(env, listener));
+        JniListenerHolder::create(env, jListener));
 
-        resource->put(jniInterface.get(), queryParams, resModelSP, callback);
+        resource->put(jniInterface.get(), queryParams, resModel, callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.what());
+        ThrowNoSupportException(env, e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
 Java_org_oic_simulator_client_SimulatorRemoteResource_nativePost
-(JNIEnv *env, jobject object, jstring resInterface, jobject queryParamsMap,
- jobject representation, jobject listener)
+(JNIEnv *env, jobject object, jstring jResInterface, jobject jQueryParams,
+ jobject jRepresentation, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
-    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    SimulatorRemoteResourceSP resource = simulatorRemoteResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        JniString jniInterface(env, resInterface);
+        JniString jniInterface(env, jResInterface);
         std::map<std::string, std::string> queryParams =
-            JniQueryParameter(env).toCpp(queryParamsMap);
+            JniQueryParameter(env).toCpp(jQueryParams);
 
         SimulatorResourceModel resModel;
-        simulatorResourceModelToCpp(env, representation, resModel);
-        SimulatorResourceModelSP resModelSP(new SimulatorResourceModel(resModel));
+        SimulatorResourceModelToCpp(env, jRepresentation, resModel);
 
         SimulatorRemoteResource::ResponseCallback callback =  std::bind([](
-                    const std::string & uid, int errorCode, SimulatorResourceModelSP representation,
+                    const std::string & uid, SimulatorResult result,
+                    const SimulatorResourceModel & resModel,
                     const std::shared_ptr<JniListenerHolder> &listenerRef)
         {
-            onPostCallback(listenerRef->get(), uid, errorCode, representation);
+            onPostCallback(listenerRef->get(), uid, result, resModel);
         }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
-        JniListenerHolder::create(env, listener));
+        JniListenerHolder::create(env, jListener));
 
-        resource->post(jniInterface.get(), queryParams, resModelSP, callback);
+        resource->post(jniInterface.get(), queryParams, resModel, callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.what());
+        ThrowNoSupportException(env, e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_client_SimulatorRemoteResource_setConfigInfo
-(JNIEnv *env, jobject object, jstring configPath)
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativeSetConfigInfo
+(JNIEnv *env, jobject object, jstring jConfigPath)
 {
-    VALIDATE_INPUT_RET(env, !configPath, "Path is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jConfigPath, "Path is null!", nullptr)
 
-    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    SimulatorRemoteResourceSP resource = simulatorRemoteResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, resource, nullptr)
 
     try
     {
-        JniString jniConfigPath(env, configPath);
-        SimulatorResourceModelSP repSchema = resource->configure(jniConfigPath.get());
-        return simulatorResourceModelToJava(env, *(repSchema.get()));
+        JniString jniConfigPath(env, jConfigPath);
+        std::map<RequestType, SimulatorRequestModel> requestModels =
+            resource->configure(jniConfigPath.get());
+
+        JniMap jRequestModelsMap(env);
+
+        // Add entry to map
+        for (auto &requestModelEntry : requestModels)
+        {
+            jobject jRequestType = JniRequestType::toJava(env, requestModelEntry.first);
+            jobject jRequestModel = JniSimulatorRequestModel::toJava(env, requestModelEntry.second);
+
+            jRequestModelsMap.put(jRequestType, jRequestModel);
+        }
+
+        return jRequestModelsMap.get();
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
 
     return nullptr;
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_client_SimulatorRemoteResource_startObserve
-(JNIEnv *env, jobject object, jobject queryParamsMap, jobject listener)
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativeStartObserve
+(JNIEnv *env, jobject object, jobject jQueryParams, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
-    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    SimulatorRemoteResourceSP resource = simulatorRemoteResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
         std::map<std::string, std::string> queryParams =
-            JniQueryParameter(env).toCpp(queryParamsMap);
+            JniQueryParameter(env).toCpp(jQueryParams);
 
         SimulatorRemoteResource::ObserveNotificationCallback callback =  std::bind([](
-                    const std::string & uid, const int errorCode,
-                    SimulatorResourceModelSP representation, const int seq,
+                    const std::string & uid, SimulatorResult result,
+                    const SimulatorResourceModel & representation, const int seq,
                     const std::shared_ptr<JniListenerHolder> &listenerRef)
         {
-            onObserveCallback(listenerRef->get(), uid, errorCode, representation, seq);
+            onObserveCallback(listenerRef->get(), uid, result, representation, seq);
         }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
-        std::placeholders::_4, JniListenerHolder::create(env, listener));
+        std::placeholders::_4, JniListenerHolder::create(env, jListener));
 
         resource->observe(ObserveType::OBSERVE, callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_client_SimulatorRemoteResource_stopObserve
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativeStopObserve
 (JNIEnv *env, jobject object)
 {
-    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    SimulatorRemoteResourceSP resource = simulatorRemoteResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
@@ -352,89 +457,79 @@ Java_org_oic_simulator_client_SimulatorRemoteResource_stopObserve
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT jint JNICALL
-Java_org_oic_simulator_client_SimulatorRemoteResource_startVerification
-(JNIEnv *env, jobject object, jint reqType, jobject listener)
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativeStartAutoRequesting
+(JNIEnv *env, jobject object, jobject jRequestType, jobject jListener)
 {
-    VALIDATE_CALLBACK_RET(env, listener, -1)
+    VALIDATE_CALLBACK_RET(env, jListener, -1)
 
-    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    SimulatorRemoteResourceSP resource = simulatorRemoteResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, resource, -1)
 
-    // Convert RequestType
-    RequestType type;
-    switch (reqType)
-    {
-        case 0: type = RequestType::RQ_TYPE_GET; break;
-        case 1: type = RequestType::RQ_TYPE_PUT; break;
-        case 2: type = RequestType::RQ_TYPE_POST; break;
-        case 3: type = RequestType::RQ_TYPE_DELETE; break;
-        default: return -1;
-    }
-
     try
     {
-        SimulatorRemoteResource::StateCallback callback =  std::bind([](
+        RequestType type = JniRequestType::toCpp(env, jRequestType);
+        SimulatorRemoteResource::AutoRequestGenerationCallback callback =  std::bind([](
                     const std::string & uid, int id, OperationState opState,
                     const std::shared_ptr<JniListenerHolder> &listenerRef)
         {
             onVerificationCallback(listenerRef->get(), uid, id, opState);
         }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
-        JniListenerHolder::create(env, listener));
+        JniListenerHolder::create(env, jListener));
 
-        return resource->startVerification(type, callback);
+        return resource->startAutoRequesting(type, callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.what());
+        ThrowNoSupportException(env, e.what());
     }
     catch (OperationInProgressException &e)
     {
-        throwOperationInProgressException(env, e.what());
+        ThrowOperationInProgressException(env, e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 
     return -1;
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_client_SimulatorRemoteResource_stopVerification
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativeStopAutoRequesting
 (JNIEnv *env, jobject object, jint id)
 {
-    SimulatorRemoteResourceSP resource = SimulatorRemoteResourceToCpp(env, object);
+    SimulatorRemoteResourceSP resource = simulatorRemoteResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        resource->stopVerification(id);
+        resource->stopAutoRequesting(id);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.what());
+        ThrowNoSupportException(env, e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_client_SimulatorRemoteResource_dispose
+Java_org_oic_simulator_client_SimulatorRemoteResource_nativeDispose
 (JNIEnv *env, jobject object)
 {
     JniSharedObjectHolder<SimulatorRemoteResource> *resource =
-        GetHandle<JniSharedObjectHolder<SimulatorRemoteResource>>(env, object);
+        getHandle<JniSharedObjectHolder<SimulatorRemoteResource>>(env, object);
     delete resource;
 }
 
diff --git a/service/simulator/java/jni/simulator_resource_attribute_jni.cpp b/service/simulator/java/jni/simulator_resource_attribute_jni.cpp
new file mode 100644 (file)
index 0000000..49c2188
--- /dev/null
@@ -0,0 +1,93 @@
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "simulator_resource_attribute_jni.h"
+#include "simulator_resource_model_jni.h"
+#include "simulator_resource_model_schema_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_string.h"
+#include "jni_map.h"
+
+jobject SimulatorResourceAttributeToJava(JNIEnv *env,
+        const SimulatorResourceAttribute &attribute)
+{
+    static jmethodID simulatorResAttributeCtor = env->GetMethodID(
+                gSimulatorClassRefs.simulatorResourceAttributeCls, "<init>",
+                "(Ljava/lang/String;Lorg/oic/simulator/AttributeValue;Lorg/oic/simulator/AttributeProperty;)V");
+
+    jstring jAttrName = env->NewStringUTF(attribute.getName().c_str());
+    jobject jAttrValue = AttributeValueToJava(env, attribute.getValue());
+    jobject jAttrProperty = AttributePropertyToJava(env, attribute.getProperty());
+
+    return env->NewObject(gSimulatorClassRefs.simulatorResourceAttributeCls,
+                          simulatorResAttributeCtor, jAttrName, jAttrValue, jAttrProperty);
+}
+
+bool SimulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
+                                     SimulatorResourceAttribute &attribute)
+{
+    if (!jAttribute)
+        return false;
+
+    static jfieldID nameFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
+                              "mName", "Ljava/lang/String;");
+    static jfieldID valueFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
+                               "mValue", "Lorg/oic/simulator/AttributeValue;");
+    static jfieldID propertyFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
+                                  "mProperty", "Lorg/oic/simulator/AttributeProperty;");
+
+    jstring jAttrName = (jstring) env->GetObjectField(jAttribute, nameFID);
+    jobject jAttrValue = env->GetObjectField(jAttribute, valueFID);
+    jobject jAttrProperty = env->GetObjectField(jAttribute, propertyFID);
+
+    if (!jAttrName || !jAttrValue)
+        return false;
+
+    JniString attrName(env, jAttrName);
+    AttributeValueVariant value;
+    AttributeValueToCpp(env, jAttrValue, value);
+
+    attribute.setName(attrName.get());
+    attribute.setValue(value);
+    if (jAttrProperty)
+    {
+        std::shared_ptr<AttributeProperty> property = AttributePropertyToCpp(env, jAttrProperty);
+        attribute.setProperty(property);
+    }
+
+    return true;
+}
+
+jobject SimulatorResourceAttributesToJava(JNIEnv *env,
+        const std::map<std::string, SimulatorResourceAttribute> &attributes)
+{
+    JniMap jAttributesMap(env);
+
+    // Add attribute values for Attributes table
+    for (auto &attributeEntry : attributes)
+    {
+        jstring jAttrName = env->NewStringUTF((attributeEntry.first).c_str());
+        jobject jAttribute = SimulatorResourceAttributeToJava(env, attributeEntry.second);
+
+        jAttributesMap.put(jAttrName, jAttribute);
+    }
+
+    return jAttributesMap.get();
+}
\ No newline at end of file
diff --git a/service/simulator/java/jni/simulator_resource_attribute_jni.h b/service/simulator/java/jni/simulator_resource_attribute_jni.h
new file mode 100644 (file)
index 0000000..f4f4659
--- /dev/null
@@ -0,0 +1,36 @@
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef SIMULATOR_RESOURCE_ATTRIBUTE_JNI_H_
+#define SIMULATOR_RESOURCE_ATTRIBUTE_JNI_H_
+
+#include <jni.h>
+#include "simulator_resource_model.h"
+
+jobject SimulatorResourceAttributeToJava(JNIEnv *env,
+        const SimulatorResourceAttribute &attribute);
+
+bool SimulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
+        SimulatorResourceAttribute &attribute);
+
+jobject SimulatorResourceAttributesToJava(JNIEnv *env,
+        const std::map<std::string, SimulatorResourceAttribute> &attributes);
+
+#endif
index 6af4cc7..ca6094f 100644 (file)
 
 #include "simulator_resource.h"
 
-#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return;}
-#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return RET;}
+#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){ThrowBadObjectException(ENV, "No corresponsing native object!"); return;}
+#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){ThrowBadObjectException(ENV, "No corresponsing native object!"); return RET;}
 
 SimulatorResourceSP SimulatorResourceToCpp(JNIEnv *env, jobject object)
 {
     JniSharedObjectHolder<SimulatorResource> *jniResource =
-        GetHandle<JniSharedObjectHolder<SimulatorResource>>(env, object);
+        getHandle<JniSharedObjectHolder<SimulatorResource>>(env, object);
     if (jniResource)
         return jniResource->get();
     return nullptr;
 }
 
-static jobject resourceTypeToJava(JNIEnv *env, SimulatorResource::Type type)
-{
-    static jfieldID single = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResourceTypeCls,
-                             "SINGLE", "Lorg/oic/simulator/server/SimulatorResource$Type;");
-    static jfieldID collection = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResourceTypeCls,
-                                 "COLLECTION", "Lorg/oic/simulator/server/SimulatorResource$Type;");
-
-    switch (type)
-    {
-        case SimulatorResource::Type::SINGLE_RESOURCE:
-            return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResourceTypeCls, single);
-        case SimulatorResource::Type::COLLECTION_RESOURCE:
-            return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResourceTypeCls, collection);
-    }
-
-    return nullptr;
-}
-
 static jobject createObserverInfo(JNIEnv *env, const ObserverInfo &observerInfo)
 {
     static jmethodID observerInfoCtor = env->GetMethodID(gSimulatorClassRefs.observerCls,
@@ -90,7 +72,7 @@ static jobject createObserverInfoVector(JNIEnv *env,
 static void onObserverChange(jobject listener, const std::string &uri,
                              ObservationStatus state, const ObserverInfo &observerInfo)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -111,13 +93,13 @@ static void onObserverChange(jobject listener, const std::string &uri,
     jobject jobserver = createObserverInfo(env, observerInfo);
 
     env->CallVoidMethod(listener, listenerMethod, jUri, jobserver);
-    releaseEnv();
+    ReleaseEnv();
 }
 
 static void onResourceModelChange(jobject listener, const std::string &uri,
-                                  SimulatorResourceModel &resModel)
+                                  const SimulatorResourceModel &resModel)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -125,10 +107,10 @@ static void onResourceModelChange(jobject listener, const std::string &uri,
     jmethodID listenerMethod = env->GetMethodID(listenerCls, "onResourceModelChanged",
                                "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
 
-    jobject jResModel = simulatorResourceModelToJava(env, resModel);
+    jobject jResModel = SimulatorResourceModelToJava(env, resModel);
     jstring jUri = env->NewStringUTF(uri.c_str());
     env->CallVoidMethod(listener, listenerMethod, jUri, jResModel);
-    releaseEnv();
+    ReleaseEnv();
 }
 
 #ifdef __cplusplus
@@ -136,7 +118,7 @@ extern "C" {
 #endif
 
 JNIEXPORT jstring JNICALL
-Java_org_oic_simulator_server_SimulatorResource_getName
+Java_org_oic_simulator_server_SimulatorResource_nativeGetName
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -145,18 +127,8 @@ Java_org_oic_simulator_server_SimulatorResource_getName
     return env->NewStringUTF(resource->getName().c_str());
 }
 
-JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_server_SimulatorResource_getType
-(JNIEnv *env, jobject object)
-{
-    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
-    VALIDATE_OBJECT_RET(env, resource, nullptr)
-
-    return resourceTypeToJava(env, resource->getType());
-}
-
 JNIEXPORT jstring JNICALL
-Java_org_oic_simulator_server_SimulatorResource_getURI
+Java_org_oic_simulator_server_SimulatorResource_nativeGetURI
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -166,7 +138,7 @@ Java_org_oic_simulator_server_SimulatorResource_getURI
 }
 
 JNIEXPORT jstring JNICALL
-Java_org_oic_simulator_server_SimulatorResource_getResourceType
+Java_org_oic_simulator_server_SimulatorResource_nativeGetResourceType
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -176,7 +148,7 @@ Java_org_oic_simulator_server_SimulatorResource_getResourceType
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_server_SimulatorResource_getInterface
+Java_org_oic_simulator_server_SimulatorResource_nativeGetInterface
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -187,7 +159,7 @@ Java_org_oic_simulator_server_SimulatorResource_getInterface
 }
 
 JNIEXPORT jboolean JNICALL
-Java_org_oic_simulator_server_SimulatorResource_isObservable
+Java_org_oic_simulator_server_SimulatorResource_nativeIsObservable
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -197,7 +169,17 @@ Java_org_oic_simulator_server_SimulatorResource_isObservable
 }
 
 JNIEXPORT jboolean JNICALL
-Java_org_oic_simulator_server_SimulatorResource_isStarted
+Java_org_oic_simulator_server_SimulatorResource_nativeIsDiscoverable
+(JNIEnv *env, jobject object)
+{
+    SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, resource, false)
+
+    return resource->isDiscoverable();
+}
+
+JNIEXPORT jboolean JNICALL
+Java_org_oic_simulator_server_SimulatorResource_nativeIsStarted
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -207,190 +189,204 @@ Java_org_oic_simulator_server_SimulatorResource_isStarted
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_server_SimulatorResource_getResourceModel
+Java_org_oic_simulator_server_SimulatorResource_nativeGetResourceModel
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, resource, nullptr)
 
     SimulatorResourceModel resModel = resource->getResourceModel();
-    return simulatorResourceModelToJava(env, resModel);
+    return SimulatorResourceModelToJava(env, resModel);
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_setName
-(JNIEnv *env, jobject object, jstring name)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetName
+(JNIEnv *env, jobject object, jstring jName)
 {
-    VALIDATE_INPUT(env, !name, "Name is null!")
+    VALIDATE_INPUT(env, !jName, "Name is null!")
 
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        JniString jniName(env, name);
+        JniString jniName(env, jName);
         resource->setName(jniName.get());
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_setURI
-(JNIEnv *env, jobject object, jstring uri)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetURI
+(JNIEnv *env, jobject object, jstring jUri)
 {
-    VALIDATE_INPUT(env, !uri, "Uri is null!")
+    VALIDATE_INPUT(env, !jUri, "Uri is null!")
 
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        JniString jniUri(env, uri);
+        JniString jniUri(env, jUri);
         resource->setURI(jniUri.get());
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_setResourceType
-(JNIEnv *env, jobject object, jstring resourceType)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetResourceType
+(JNIEnv *env, jobject object, jstring jResourceType)
 {
-    VALIDATE_INPUT(env, !resourceType, "Resource type is null!")
+    VALIDATE_INPUT(env, !jResourceType, "Resource type is null!")
 
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        JniString jniType(env, resourceType);
+        JniString jniType(env, jResourceType);
         resource->setResourceType(jniType.get());
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_addInterface
-(JNIEnv *env, jobject object, jstring interfaceType)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetInterface
+(JNIEnv *env, jobject object, jstring jInterfaceType)
 {
-    VALIDATE_INPUT(env, !interfaceType, "Interface type is null!")
+    VALIDATE_INPUT(env, !jInterfaceType, "Interface type is null!")
 
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        JniString jniInterfaceType(env, interfaceType);
-        resource->addInterface(jniInterfaceType.get());
+        JniString jniInterfaceType(env, jInterfaceType);
+        resource->setInterface(jniInterfaceType.get());
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
-    }
-    catch (NoSupportException &e)
-    {
-        throwNoSupportException(env, e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_removeInterface
-(JNIEnv *env, jobject object, jstring interfaceType)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetInterfaces
+(JNIEnv *env, jobject object, jobject jInterfaceTypes)
 {
-    VALIDATE_INPUT(env, !interfaceType, "Interface type is null!")
+    VALIDATE_INPUT(env, !jInterfaceTypes, "Interface type is null!")
 
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
-    JniString jniInterfaceType(env, interfaceType);
-    resource->removeInterface(jniInterfaceType.get());
+    std::vector<std::string> interfaceList = JniVector(env).toCpp<std::string>(jInterfaceTypes);
+
+    try
+    {
+        resource->setInterface(interfaceList);
+    }
+    catch (InvalidArgsException &e)
+    {
+        ThrowInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (SimulatorException &e)
+    {
+        ThrowSimulatorException(env, e.code(), e.what());
+    }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_addInterfaces
-(JNIEnv *env, jobject object, jobject interfaceType)
+Java_org_oic_simulator_server_SimulatorResource_nativeAddInterface
+(JNIEnv *env, jobject object, jstring jInterfaceType)
 {
-    VALIDATE_INPUT(env, !interfaceType, "Interface type is null!")
+    VALIDATE_INPUT(env, !jInterfaceType, "Interface type is null!")
 
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
-    std::vector<std::string> interfaceList = JniVector(env).toCpp<std::string>(interfaceType);
-
     try
     {
-        resource->addInterface(interfaceList);
+        JniString jniInterfaceType(env, jInterfaceType);
+        resource->addInterface(jniInterfaceType.get());
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (NoSupportException &e)
     {
-        throwNoSupportException(env, e.what());
+        ThrowNoSupportException(env, e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_removeInterfaces
-(JNIEnv *env, jobject object, jobject interfaceType)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetObservable
+(JNIEnv *env, jobject object, jboolean jState)
 {
-    VALIDATE_INPUT(env, !interfaceType, "Interface type is null!")
-
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
-    std::vector<std::string> interfaceList = JniVector(env).toCpp<std::string>(interfaceType);
-
-    resource->removeInterface(interfaceList);
+    try
+    {
+        resource->setObservable(static_cast<bool>(jState));
+    }
+    catch (SimulatorException &e)
+    {
+        ThrowSimulatorException(env, e.code(), e.what());
+    }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_setObservable
-(JNIEnv *env, jobject object, jboolean state)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetDiscoverable
+(JNIEnv *env, jobject object, jboolean jState)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
     try
     {
-        resource->setObservable(static_cast<bool>(state));
+        resource->setDiscoverable(static_cast<bool>(jState));
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_setObserverListener
-(JNIEnv *env, jobject object, jobject listener)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetObserverListener
+(JNIEnv *env, jobject object, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
@@ -401,7 +397,7 @@ Java_org_oic_simulator_server_SimulatorResource_setObserverListener
     {
         onObserverChange(listenerRef->get(), uri, state, observerInfo);
     }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
-    JniListenerHolder::create(env, listener));
+    JniListenerHolder::create(env, jListener));
 
     try
     {
@@ -409,25 +405,25 @@ Java_org_oic_simulator_server_SimulatorResource_setObserverListener
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_setResourceModelChangeListener
-(JNIEnv *env, jobject object, jobject listener)
+Java_org_oic_simulator_server_SimulatorResource_nativeSetResourceModelChangeListener
+(JNIEnv *env, jobject object, jobject jListener)
 {
-    VALIDATE_CALLBACK(env, listener)
+    VALIDATE_CALLBACK(env, jListener)
 
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT(env, resource)
 
-    SimulatorResource::ResourceModelChangedCallback callback =  std::bind(
-                [](const std::string & uri, SimulatorResourceModel & resModel,
+    SimulatorResource::ResourceModelUpdateCallback callback =  std::bind(
+                [](const std::string & uri, const SimulatorResourceModel & resModel,
                    const std::shared_ptr<JniListenerHolder> &listenerRef)
     {
         onResourceModelChange(listenerRef->get(), uri, resModel);
-    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, listener));
+    }, std::placeholders::_1, std::placeholders::_2, JniListenerHolder::create(env, jListener));
 
     try
     {
@@ -435,12 +431,12 @@ Java_org_oic_simulator_server_SimulatorResource_setResourceModelChangeListener
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_start
+Java_org_oic_simulator_server_SimulatorResource_nativeStart
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -452,12 +448,12 @@ Java_org_oic_simulator_server_SimulatorResource_start
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_stop
+Java_org_oic_simulator_server_SimulatorResource_nativeStop
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -469,22 +465,22 @@ Java_org_oic_simulator_server_SimulatorResource_stop
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_server_SimulatorResource_getObservers
+Java_org_oic_simulator_server_SimulatorResource_nativeGetObservers
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, resource, nullptr)
 
-    return createObserverInfoVector(env, resource->getObserversList());
+    return createObserverInfoVector(env, resource->getObservers());
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_notifyObserver
+Java_org_oic_simulator_server_SimulatorResource_nativeNotify
 (JNIEnv *env, jobject object, jint id)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -496,12 +492,12 @@ Java_org_oic_simulator_server_SimulatorResource_notifyObserver
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorResource_notifyAllObservers
+Java_org_oic_simulator_server_SimulatorResource_nativeNotifyAll
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceSP resource = SimulatorResourceToCpp(env, object);
@@ -513,10 +509,10 @@ Java_org_oic_simulator_server_SimulatorResource_notifyAllObservers
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 }
 
 #ifdef __cplusplus
 }
-#endif
\ No newline at end of file
+#endif
index 63babf1..a186d76 100644 (file)
  ******************************************************************/
 
 #include "simulator_resource_model_jni.h"
-#include "simulator_error_codes.h"
-#include "simulator_exceptions_jni.h"
 #include "simulator_utils_jni.h"
 #include "jni_string.h"
+#include "jni_map.h"
 
 class JniTypeInfo
 {
@@ -50,13 +49,13 @@ class JniTypeInfo
         }
 
     private:
-        SimulatorResourceModel::ValueType getValueType(jobject jValueType)
+        AttributeValueType getValueType(jobject jValueType)
         {
             static jmethodID ordinalMID = m_env->GetMethodID(
                                               gSimulatorClassRefs.attributeValueTypeCls, "ordinal", "()I");
 
             int ordinal = m_env->CallIntMethod(jValueType, ordinalMID);
-            return SimulatorResourceModel::ValueType(ordinal);
+            return AttributeValueType(ordinal);
         }
 
         JNIEnv *m_env;
@@ -99,7 +98,7 @@ class ValueConverterJava : public boost::static_visitor<jobject>
 
         jobject operator ()(const SimulatorResourceModel &value)
         {
-            return simulatorResourceModelToJava(m_env, const_cast<SimulatorResourceModel &>(value));
+            return SimulatorResourceModelToJava(m_env, const_cast<SimulatorResourceModel &>(value));
         }
 
         template <typename T>
@@ -239,23 +238,23 @@ class ValueConverterCpp
         {
             switch (m_typeInfo.baseType())
             {
-                case SimulatorResourceModel::ValueType::INTEGER:
+                case AttributeValueType::INTEGER:
                     return handleByDepth<int>();
-                case SimulatorResourceModel::ValueType::DOUBLE:
+                case AttributeValueType::DOUBLE:
                     return handleByDepth<double>();
-                case SimulatorResourceModel::ValueType::BOOLEAN:
+                case AttributeValueType::BOOLEAN:
                     return handleByDepth<bool>();
-                case SimulatorResourceModel::ValueType::STRING:
+                case AttributeValueType::STRING:
                     return handleByDepth<std::string>();
-                case SimulatorResourceModel::ValueType::RESOURCE_MODEL:
+                case AttributeValueType::RESOURCE_MODEL:
                     return handleByDepth<SimulatorResourceModel>();
-                case SimulatorResourceModel::ValueType::VECTOR:
-                case SimulatorResourceModel::ValueType::UNKNOWN:
+                case AttributeValueType::VECTOR:
+                case AttributeValueType::UNKNOWN:
                     break;
             }
         }
 
-        SimulatorResourceModel::ValueVariant get()
+        AttributeValueVariant get()
         {
             return std::move(m_result);
         }
@@ -492,7 +491,7 @@ class ValueConverterCpp
 
         void getValue(jobject &jValue, SimulatorResourceModel &value)
         {
-            simulatorResourceModelToCpp(m_env, jValue, value);
+            SimulatorResourceModelToCpp(m_env, jValue, value);
         }
 
         void getValue(jobject &jValue, std::vector<SimulatorResourceModel> &value)
@@ -549,19 +548,18 @@ class ValueConverterCpp
         JNIEnv *m_env;
         SimulatorResourceModel::TypeInfo &m_typeInfo;
         jobject &m_value;
-        SimulatorResourceModel::ValueVariant m_result;
+        AttributeValueVariant m_result;
 };
 
 class JniAttributeValue
 {
     public:
-        static jobject toJava(JNIEnv *env, SimulatorResourceModel::Attribute &attribute)
+        static jobject toJava(JNIEnv *env, const SimulatorResourceAttribute &attribute)
         {
-            auto value = attribute.getValue();
-            return toJava(env, value);
+            return toJava(env, attribute.getValue());
         }
 
-        static jobject toJava(JNIEnv *env, SimulatorResourceModel::ValueVariant &value)
+        static jobject toJava(JNIEnv *env, const AttributeValueVariant &value)
         {
             ValueConverterJava converter(env);
             jobject jValue =  boost::apply_visitor(converter, value);
@@ -572,7 +570,7 @@ class JniAttributeValue
             return env->NewObject(gSimulatorClassRefs.attributeValueCls, attrValueCtor, jValue);
         }
 
-        static SimulatorResourceModel::ValueVariant toCpp(JNIEnv *env, jobject &jAttributeValue)
+        static AttributeValueVariant toCpp(JNIEnv *env, jobject &jAttributeValue)
         {
             static jmethodID getMID = env->GetMethodID(gSimulatorClassRefs.attributeValueCls,
                                       "get", "()Ljava/lang/Object;");
@@ -586,182 +584,34 @@ class JniAttributeValue
         }
 };
 
-class JniAttributeProperty
+jobject SimulatorResourceModelToJava(JNIEnv *env, const SimulatorResourceModel &resModel)
 {
-    public:
-        static jobject toJava(JNIEnv *env,
-                              SimulatorResourceModel::AttributeProperty &property)
-        {
-            jobject jAttributeProperty = nullptr;
-            if (SimulatorResourceModel::AttributeProperty::Type::RANGE == property.type())
-            {
-                static jmethodID propertyCtor = env->GetMethodID(
-                                                    gSimulatorClassRefs.attributePropertyCls, "<init>", "(DD)V");
-
-                jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
-                                                    property.min(), property.max());
-            }
-            else if (SimulatorResourceModel::AttributeProperty::Type::VALUE_SET == property.type())
-            {
-                static jmethodID propertyCtor = env->GetMethodID(
-                                                    gSimulatorClassRefs.attributePropertyCls, "<init>", "([Lorg/oic/simulator/AttributeValue;)V");
-
-                jobjectArray jValueSet = env->NewObjectArray(property.valueSetSize(),
-                                         gSimulatorClassRefs.attributeValueCls, nullptr);
-                int index = 0;
-                for (auto &value : property.valueSet())
-                {
-                    jobject jValue = JniAttributeValue::toJava(env, value);
-                    env->SetObjectArrayElement(jValueSet, index++, jValue);
-                }
-
-                jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
-                                                    jValueSet);
-            }
-            else
-            {
-                return jAttributeProperty;
-            }
-
-            // Add child property
-            if (jAttributeProperty && property.getChildProperty())
-            {
-                SimulatorResourceModel::AttributeProperty childProperty = *(property.getChildProperty());
-                jobject jChildProperty = JniAttributeProperty::toJava(env,  property);
-                if (jChildProperty)
-                {
-                    static jfieldID childPropFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
-                                                   "mChildProperty", "Lorg/oic/simulator/AttributeProperty;");
-                    env->SetObjectField(jAttributeProperty, childPropFID, jChildProperty);
-                }
-            }
-
-            return jAttributeProperty;
-        }
-
-        static SimulatorResourceModel::AttributeProperty toCpp(JNIEnv *env, jobject jAttributeProperty)
-        {
-            static jfieldID typeFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
-                                      "mType", "Lorg/oic/simulator/AttributeProperty$Type;");
-            static jfieldID minFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
-                                     "mMin", "D");
-            static jfieldID maxFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
-                                     "mMax", "D");
-            static jfieldID valueSetFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
-                                          "mValueSet", "[Lorg/oic/simulator/AttributeValue;");
-            static jfieldID childPropFID = env->GetFieldID(gSimulatorClassRefs.attributePropertyCls,
-                                           "mChildProperty", "Lorg/oic/simulator/AttributeProperty;");
-            static jmethodID ordinalMID = env->GetMethodID(
-                                              gSimulatorClassRefs.attributePropertyTypeCls, "ordinal", "()I");
-
-            SimulatorResourceModel::AttributeProperty attributeProperty;
-            jobject jType = env->GetObjectField(jAttributeProperty, typeFID);
-            jdouble jMin = env->GetDoubleField(jAttributeProperty, minFID);
-            jdouble jMax = env->GetDoubleField(jAttributeProperty, maxFID);
-            jobjectArray jValueSet = (jobjectArray) env->GetObjectField(jAttributeProperty, valueSetFID);
-            jobject jChildProperty = env->GetObjectField(jAttributeProperty, childPropFID);
-
-            int ordinal = env->CallIntMethod(jType, ordinalMID);
-            switch (SimulatorResourceModel::AttributeProperty::Type(ordinal))
-            {
-                case SimulatorResourceModel::AttributeProperty::Type::RANGE:
-                    {
-                        attributeProperty = SimulatorResourceModel::AttributeProperty(jMin, jMax);
-                    }
-                    break;
-
-                case SimulatorResourceModel::AttributeProperty::Type::VALUE_SET:
-                    {
-                        std::vector<SimulatorResourceModel::ValueVariant> valueSet;
-                        size_t length = env->GetArrayLength(jValueSet);
-                        for (size_t i = 0; i < length; i++)
-                        {
-                            jobject jAttributeValue = env->GetObjectArrayElement(jValueSet, i);
-                            valueSet.push_back(JniAttributeValue::toCpp(env, jAttributeValue));
-                        }
-
-                        attributeProperty = SimulatorResourceModel::AttributeProperty(valueSet);
-                    }
-                    break;
-            }
+    JniMap jAttributesMap(env);
 
-            // Set child property
-            if (jChildProperty)
-            {
-                SimulatorResourceModel::AttributeProperty childProperty =
-                    JniAttributeProperty::toCpp(env, jAttributeProperty);
-                attributeProperty.setChildProperty(childProperty);
-            }
-
-            return attributeProperty;
-        }
-};
-
-static jobject createHashMap(JNIEnv *env)
-{
-    static jmethodID hashMapCtor = env->GetMethodID(
-                                       gSimulatorClassRefs.hashMapCls, "<init>", "()V");
-    return env->NewObject(gSimulatorClassRefs.hashMapCls, hashMapCtor);
-}
-
-static void addEntryToHashMap(JNIEnv *env, jobject mapobj, jobject key, jobject value)
-{
-    if (!mapobj || !key || !value)
-        return;
-
-    static jmethodID hashMapPutMethod = env->GetMethodID(gSimulatorClassRefs.hashMapCls,
-                                        "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-    env->CallObjectMethod(mapobj, hashMapPutMethod, key, value);
-}
-
-jobject simulatorResourceModelToJava(JNIEnv *env, SimulatorResourceModel &resModel)
-{
-    jobject attributesMap = createHashMap(env);
-    jobject propertiesMap = createHashMap(env);
-    if (!attributesMap || !propertiesMap)
-        return nullptr;
-
-    for (auto &attributeEntry : resModel.getAttributes())
+    // Add attribute values for HashMap
+    for (auto &attributeEntry : resModel.getAttributeValues())
     {
         jstring jAttrName = env->NewStringUTF((attributeEntry.first).c_str());
         jobject jAttributeValue = JniAttributeValue::toJava(env, attributeEntry.second);
-        addEntryToHashMap(env, attributesMap, jAttrName, jAttributeValue);
 
-        jobject jAttributeProperty = JniAttributeProperty::toJava(env, attributeEntry.second.getProperty());
-        if (jAttributeProperty)
-            addEntryToHashMap(env, propertiesMap, jAttrName, jAttributeProperty);
+        jAttributesMap.put(jAttrName, jAttributeValue);
     }
 
+    // Create Java SimulatorResourceModel object
     static jmethodID simulatorResourceModelCtor = env->GetMethodID(
-                gSimulatorClassRefs.simulatorResourceModelCls, "<init>", "(Ljava/util/Map;Ljava/util/Map;)V");
+                gSimulatorClassRefs.simulatorResourceModelCls, "<init>", "(Ljava/util/Map;)V");
 
     return env->NewObject(gSimulatorClassRefs.simulatorResourceModelCls,
-                          simulatorResourceModelCtor, attributesMap, propertiesMap);
+                          simulatorResourceModelCtor, jAttributesMap.get());
 }
 
-jobject simulatorResourceAttributeToJava(JNIEnv *env, SimulatorResourceModel::Attribute &attribute)
-{
-    static jmethodID simulatorResAttributeCtor = env->GetMethodID(
-                gSimulatorClassRefs.simulatorResourceAttributeCls, "<init>",
-                "(Ljava/lang/String;Lorg/oic/simulator/AttributeValue;Lorg/oic/simulator/AttributeProperty;)V");
-
-    jstring jAttrName = env->NewStringUTF(attribute.getName().c_str());
-    jobject jAttributeValue = JniAttributeValue::toJava(env, attribute);
-    jobject jAttributeProperty = JniAttributeProperty::toJava(env, attribute.getProperty());
-
-    return env->NewObject(gSimulatorClassRefs.simulatorResourceAttributeCls,
-                          simulatorResAttributeCtor, jAttrName, jAttributeValue, jAttributeProperty);
-}
-
-bool simulatorResourceModelToCpp(JNIEnv *env, jobject jResModel, SimulatorResourceModel &resModel)
+bool SimulatorResourceModelToCpp(JNIEnv *env, jobject jResModel, SimulatorResourceModel &resModel)
 {
     if (!jResModel)
         return false;
 
     static jfieldID valuesFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceModelCls,
                                 "mValues", "Ljava/util/Map;");
-    static jfieldID propertiesFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceModelCls,
-                                    "mProperties", "Ljava/util/Map;");
     static jmethodID entrySetMID = env->GetMethodID(gSimulatorClassRefs.mapCls, "entrySet",
                                    "()Ljava/util/Set;");
     static jmethodID iteratorMID = env->GetMethodID(gSimulatorClassRefs.setCls, "iterator",
@@ -776,8 +626,6 @@ bool simulatorResourceModelToCpp(JNIEnv *env, jobject jResModel, SimulatorResour
                                    "()Ljava/lang/Object;");
 
     jobject jValues = env->GetObjectField(jResModel, valuesFID);
-    jobject jProperties = env->GetObjectField(jResModel, propertiesFID);
-
     if (jValues)
     {
         jobject entrySet = env->CallObjectMethod(jValues, entrySetMID);
@@ -798,72 +646,22 @@ bool simulatorResourceModelToCpp(JNIEnv *env, jobject jResModel, SimulatorResour
         }
     }
 
-    if (jProperties)
-    {
-        jobject entrySet = env->CallObjectMethod(jProperties, entrySetMID);
-        jobject iterator = env->CallObjectMethod(entrySet, iteratorMID);
-        if (entrySet && iterator)
-        {
-            while (env->CallBooleanMethod(iterator, hasNextMID))
-            {
-                jobject entry = env->CallObjectMethod(iterator, nextMID);
-                jstring key = (jstring) env->CallObjectMethod(entry, getKeyMID);
-                jobject value = env->CallObjectMethod(entry, getValueMID);
-                resModel.setAttributeProperty(JniString(env, key).get(),
-                                              JniAttributeProperty::toCpp(env, value));
-
-                env->DeleteLocalRef(entry);
-                env->DeleteLocalRef(key);
-                env->DeleteLocalRef(value);
-            }
-        }
-    }
-
     return true;
 }
 
-bool simulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
-                                     SimulatorResourceModel::Attribute &attribute)
+jobject AttributeValueToJava(JNIEnv *env,
+                             const AttributeValueVariant &value)
 {
-    if (!jAttribute)
-        return false;
-
-    static jfieldID nameFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
-                              "mName", "Ljava/lang/String;");
-    static jfieldID valueFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
-                               "mValue", "Lorg/oic/simulator/AttributeValue;");
-    static jfieldID propertyFID = env->GetFieldID(gSimulatorClassRefs.simulatorResourceAttributeCls,
-                                  "mProperty", "Lorg/oic/simulator/AttributeProperty;");
-
-    jstring jAttributeName = (jstring) env->GetObjectField(jAttribute, nameFID);
-    jobject jAttributeValue = env->GetObjectField(jAttribute, valueFID);
-    jobject jAttributeProperty = env->GetObjectField(jAttribute, propertyFID);
-
-    if (!jAttributeName || !jAttributeValue)
-        return false;
-
-    JniString attrName(env, jAttributeName);
-    SimulatorResourceModel::ValueVariant value = JniAttributeValue::toCpp(env, jAttributeValue);
-
-    attribute.setName(attrName.get());
-    attribute.setValue(value);
-    if (jAttributeProperty)
-    {
-        SimulatorResourceModel::AttributeProperty property = JniAttributeProperty::toCpp(env,
-                jAttributeProperty);
-        attribute.setProperty(property);
-    }
-
-    return true;
+    return JniAttributeValue::toJava(env, value);
 }
 
 bool AttributeValueToCpp(JNIEnv *env, jobject jAttributeValue,
-                         SimulatorResourceModel::ValueVariant &value)
+                         AttributeValueVariant &jValue)
 {
     if (!jAttributeValue)
         return false;
 
-    value = JniAttributeValue::toCpp(env, jAttributeValue);
+    jValue = JniAttributeValue::toCpp(env, jAttributeValue);
     return true;
 }
 
index ca23b3b..e77dfe3 100644 (file)
 #define SIMULATOR_RESOURCE_MODEL_JNI_H_
 
 #include <jni.h>
+
 #include "simulator_resource_model.h"
 
-jobject simulatorResourceModelToJava(JNIEnv *env, SimulatorResourceModel &resModel);
-jobject simulatorResourceAttributeToJava(JNIEnv *env, SimulatorResourceModel::Attribute &attribute);
-bool simulatorResourceModelToCpp(JNIEnv *env, jobject jResModel, SimulatorResourceModel &resModel);
-bool simulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
-                                     SimulatorResourceModel::Attribute &attribute);
+jobject SimulatorResourceModelToJava(JNIEnv *env,
+        const SimulatorResourceModel &resModel);
+
+bool SimulatorResourceModelToCpp(JNIEnv *env, jobject jResModel,
+        SimulatorResourceModel &resModel);
+
+jobject AttributeValueToJava(JNIEnv *env, const AttributeValueVariant &value);
+
 bool AttributeValueToCpp(JNIEnv *env, jobject jAttributeValue,
-                         SimulatorResourceModel::ValueVariant &value);
+        AttributeValueVariant &jValue);
 
 #endif
diff --git a/service/simulator/java/jni/simulator_resource_model_schema_jni.cpp b/service/simulator/java/jni/simulator_resource_model_schema_jni.cpp
new file mode 100644 (file)
index 0000000..96b2dfb
--- /dev/null
@@ -0,0 +1,606 @@
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "simulator_resource_model_schema_jni.h"
+#include "simulator_utils_jni.h"
+#include "jni_string.h"
+
+static AttributeProperty::Type getType(JNIEnv *env, jobject &jProperty)
+{
+    static jmethodID getTypeMID = env->GetMethodID(
+                                      gSimulatorClassRefs.attributePropertyCls, "getType",
+                                      "()Lorg/oic/simulator/AttributeProperty$Type;");
+
+    static jmethodID ordinalMID = env->GetMethodID(
+                                      gSimulatorClassRefs.attributePropertyTypeCls, "ordinal", "()I");
+
+    jobject jType = env->CallObjectMethod(jProperty, getTypeMID);
+    int ordinal = env->CallIntMethod(jType, ordinalMID);
+    return AttributeProperty::Type(ordinal);
+}
+
+class JniIntegerProperty
+{
+    public:
+        static jobject toJava(JNIEnv *env, const std::shared_ptr<IntegerProperty> &property)
+        {
+            if (!property)
+                return nullptr;
+
+            // Create Java IntegerProperty.Builder object
+            jobject jPropertyBuilder = nullptr;
+            static jmethodID builderCtor = env->GetMethodID(
+                                               gSimulatorClassRefs.integerPropertyBuilderCls, "<init>", "()V");
+            jPropertyBuilder = env->NewObject(gSimulatorClassRefs.integerPropertyBuilderCls, builderCtor);
+
+            // Set default value
+            static jmethodID setDefaultValueMID = env->GetMethodID(
+                    gSimulatorClassRefs.integerPropertyBuilderCls, "setDefaultValue", "(I)V");
+            env->CallVoidMethod(jPropertyBuilder, setDefaultValueMID, property->getDefaultValue());
+
+            // Set Range or enum value set
+            if (property->hasRange())
+            {
+                int min;
+                int max;
+                property->getRange(min, max);
+
+                static jmethodID setRangeMID = env->GetMethodID(
+                                                   gSimulatorClassRefs.integerPropertyBuilderCls, "setRange", "(II)V");
+                env->CallVoidMethod(jPropertyBuilder, setRangeMID, min, max);
+            }
+            else if (property->hasValues())
+            {
+                std::vector<int> values;
+                property->getValues(values);
+                jintArray jIntArray = env->NewIntArray(values.size());
+                env->SetIntArrayRegion(jIntArray, 0, values.size(), reinterpret_cast<const jint *>(&values[0]));
+
+                static jmethodID setValuesMID = env->GetMethodID(
+                                                    gSimulatorClassRefs.integerPropertyBuilderCls, "setValues", "([I)V");
+                env->CallVoidMethod(jPropertyBuilder, setValuesMID, jIntArray);
+            }
+
+            // Create Java IntegerProperty object
+            static jmethodID buildMID = env->GetMethodID(
+                                            gSimulatorClassRefs.integerPropertyBuilderCls, "build", "()Lorg/oic/simulator/IntegerProperty;");
+            return env->CallObjectMethod(jPropertyBuilder, buildMID);
+        }
+
+        static std::shared_ptr<IntegerProperty> toCpp(JNIEnv *env, jobject &jProperty)
+        {
+            static jfieldID defaultValueFID = env->GetFieldID(gSimulatorClassRefs.integerPropertyCls,
+                                              "mDefaultValue", "I");
+            static jfieldID hasRangeFID = env->GetFieldID(gSimulatorClassRefs.integerPropertyCls,
+                                          "mHasRange", "Z");
+
+            jint defaultValue = env->GetIntField(jProperty, defaultValueFID);
+            jboolean hasRange = env->GetBooleanField(jProperty, hasRangeFID);
+
+            std::shared_ptr<IntegerProperty> integerProperty =
+                IntegerProperty::build(defaultValue);
+
+            if (hasRange)
+            {
+                static jfieldID minFID = env->GetFieldID(gSimulatorClassRefs.integerPropertyCls,
+                                         "mMin", "I");
+                static jfieldID maxFID = env->GetFieldID(gSimulatorClassRefs.integerPropertyCls,
+                                         "mMax", "I");
+
+                jint min = env->GetIntField(jProperty, minFID);
+                jint max = env->GetIntField(jProperty, maxFID);
+                integerProperty->setRange(min, max);
+            }
+            else
+            {
+                static jfieldID valuesFID = env->GetFieldID(gSimulatorClassRefs.integerPropertyCls,
+                                            "mValues", "[I");
+                jintArray jValues = (jintArray) env->GetObjectField(jProperty, valuesFID);
+                if (jValues)
+                {
+                    std::vector<int> values;
+                    jint *jIntArray = env->GetIntArrayElements(jValues, NULL);
+                    size_t length = env->GetArrayLength(jValues);
+                    for (size_t index = 0; index < length; index++)
+                    {
+                        values.push_back(jIntArray[index]);
+                    }
+
+                    env->ReleaseIntArrayElements(jValues, jIntArray, 0);
+                }
+            }
+
+            return integerProperty;
+        }
+};
+
+class JniDoubleProperty
+{
+    public:
+        static jobject toJava(JNIEnv *env, const std::shared_ptr<DoubleProperty> &property)
+        {
+            if (!property)
+                return nullptr;
+
+            // Create Java DoubleProperty.Builder object
+            jobject jPropertyBuilder = nullptr;
+            static jmethodID builderCtor = env->GetMethodID(
+                                               gSimulatorClassRefs.doublePropertyBuilderCls, "<init>", "()V");
+            jPropertyBuilder = env->NewObject(gSimulatorClassRefs.doublePropertyBuilderCls, builderCtor);
+
+            // Set default value
+            static jmethodID setDefaultValueMID = env->GetMethodID(
+                    gSimulatorClassRefs.doublePropertyBuilderCls, "setDefaultValue", "(D)V");
+            env->CallVoidMethod(jPropertyBuilder, setDefaultValueMID, property->getDefaultValue());
+
+            // Set Range or enum value set
+            if (property->hasRange())
+            {
+                double min;
+                double max;
+                property->getRange(min, max);
+
+                static jmethodID setRangeMID = env->GetMethodID(
+                                                   gSimulatorClassRefs.doublePropertyBuilderCls, "setRange", "(DD)V");
+                env->CallVoidMethod(jPropertyBuilder, setRangeMID, min, max);
+            }
+            else if (property->hasValues())
+            {
+                std::vector<double> values;
+                property->getValues(values);
+                jdoubleArray jDoubleArray = env->NewDoubleArray(values.size());
+                env->SetDoubleArrayRegion(jDoubleArray, 0, values.size(),
+                                          reinterpret_cast<const jdouble *>(&values[0]));
+
+                static jmethodID setValuesMID = env->GetMethodID(
+                                                    gSimulatorClassRefs.doublePropertyBuilderCls, "setValues", "([D)V");
+                env->CallVoidMethod(jPropertyBuilder, setValuesMID, jDoubleArray);
+            }
+
+            // Create Java DoubleProperty object
+            static jmethodID buildMID = env->GetMethodID(
+                                            gSimulatorClassRefs.doublePropertyBuilderCls, "build", "()Lorg/oic/simulator/DoubleProperty;");
+            return env->CallObjectMethod(jPropertyBuilder, buildMID);
+        }
+
+        static std::shared_ptr<DoubleProperty> toCpp(JNIEnv *env, jobject &jProperty)
+        {
+            static jfieldID defaultValueFID = env->GetFieldID(gSimulatorClassRefs.doublePropertyCls,
+                                              "mDefaultValue", "D");
+            static jfieldID hasRangeFID = env->GetFieldID(gSimulatorClassRefs.doublePropertyCls,
+                                          "mHasRange", "Z");
+
+            jdouble defaultValue = env->GetIntField(jProperty, defaultValueFID);
+            jboolean hasRange = env->GetBooleanField(jProperty, hasRangeFID);
+
+            std::shared_ptr<DoubleProperty> doubleProperty =
+                DoubleProperty::build(defaultValue);
+
+            if (hasRange)
+            {
+                static jfieldID minFID = env->GetFieldID(gSimulatorClassRefs.doublePropertyCls,
+                                         "mMin", "D");
+                static jfieldID maxFID = env->GetFieldID(gSimulatorClassRefs.doublePropertyCls,
+                                         "mMax", "D");
+
+                jdouble min = env->GetDoubleField(jProperty, minFID);
+                jdouble max = env->GetDoubleField(jProperty, maxFID);
+                doubleProperty->setRange(min, max);
+            }
+            else
+            {
+                static jfieldID valuesFID = env->GetFieldID(gSimulatorClassRefs.doublePropertyCls,
+                                            "mValues", "[D");
+                jdoubleArray jValues = (jdoubleArray) env->GetObjectField(jProperty, valuesFID);
+                if (jValues)
+                {
+                    std::vector<double> values;
+                    jdouble *jDoubleArray = env->GetDoubleArrayElements(jValues, NULL);
+                    size_t length = env->GetArrayLength(jValues);
+                    for (size_t index = 0; index < length; index++)
+                    {
+                        values.push_back(jDoubleArray[index]);
+                    }
+
+                    env->ReleaseDoubleArrayElements(jValues, jDoubleArray, 0);
+                }
+            }
+
+            return doubleProperty;
+        }
+};
+
+class JniBooleanProperty
+{
+    public:
+        static jobject toJava(JNIEnv *env, const std::shared_ptr<BooleanProperty> &property)
+        {
+            if (!property)
+                return nullptr;
+
+            // Create Java BooleanProperty.Builder object
+            jobject jPropertyBuilder = nullptr;
+            static jmethodID builderCtor = env->GetMethodID(
+                                               gSimulatorClassRefs.booleanPropertyBuilderCls, "<init>", "()V");
+            jPropertyBuilder = env->NewObject(gSimulatorClassRefs.booleanPropertyBuilderCls, builderCtor);
+
+            // Set default value
+            static jmethodID setDefaultValueMID = env->GetMethodID(
+                    gSimulatorClassRefs.booleanPropertyBuilderCls, "setDefaultValue", "(Z)V");
+            env->CallVoidMethod(jPropertyBuilder, setDefaultValueMID, property->getDefaultValue());
+
+            // Create Java BooleanProperty object
+            static jmethodID buildMID = env->GetMethodID(
+                                            gSimulatorClassRefs.booleanPropertyBuilderCls, "build", "()Lorg/oic/simulator/BooleanProperty;");
+            return env->CallObjectMethod(jPropertyBuilder, buildMID);
+        }
+
+        static std::shared_ptr<BooleanProperty> toCpp(JNIEnv *env, jobject &jProperty)
+        {
+            static jfieldID defaultValueFID = env->GetFieldID(gSimulatorClassRefs.booleanPropertyCls,
+                                              "mDefaultValue", "Z");
+
+            jboolean defaultValue = env->GetBooleanField(jProperty, defaultValueFID);
+            return BooleanProperty::build(defaultValue);
+        }
+};
+
+class JniStringProperty
+{
+    public:
+        static jobject toJava(JNIEnv *env, const std::shared_ptr<StringProperty> &property)
+        {
+            if (!property)
+                return nullptr;
+
+            // Create Java StringProperty.Builder object
+            jobject jPropertyBuilder = nullptr;
+            static jmethodID builderCtor = env->GetMethodID(
+                                               gSimulatorClassRefs.stringPropertyBuilderCls, "<init>", "()V");
+            jPropertyBuilder = env->NewObject(gSimulatorClassRefs.stringPropertyBuilderCls, builderCtor);
+
+            // Set default value
+            static jmethodID setDefaultValueMID = env->GetMethodID(
+                    gSimulatorClassRefs.stringPropertyBuilderCls, "setDefaultValue", "(Ljava/lang/String;)V");
+            jstring jDefaultValue = env->NewStringUTF(property->getDefaultValue().c_str());
+            env->CallVoidMethod(jPropertyBuilder, setDefaultValueMID, jDefaultValue);
+
+            // Set Range or enum value set
+            if (property->hasRange())
+            {
+                size_t min;
+                size_t max;
+                property->getRange(min, max);
+
+                static jmethodID setRangeMID = env->GetMethodID(
+                                                   gSimulatorClassRefs.stringPropertyBuilderCls, "setRange", "(II)V");
+                env->CallVoidMethod(jPropertyBuilder, setRangeMID, static_cast<jint>(min),
+                                    static_cast<jint>(max));
+            }
+            else if (property->hasValues())
+            {
+                std::vector<std::string> values;
+                property->getValues(values);
+                jobjectArray jStringArray = env->NewObjectArray(values.size(), gSimulatorClassRefs.stringCls,
+                                            nullptr);
+
+                for (size_t index = 0; index < values.size(); index++)
+                {
+                    jstring element = env->NewStringUTF(values[index].c_str());
+                    env->SetObjectArrayElement(jStringArray, index, element);
+                }
+
+                static jmethodID setValuesMID = env->GetMethodID(
+                                                    gSimulatorClassRefs.stringPropertyBuilderCls, "setValues", "([Ljava/lang/String;)V");
+                env->CallVoidMethod(jPropertyBuilder, setValuesMID, jStringArray);
+            }
+
+            // Create Java StringProperty object
+            static jmethodID buildMID = env->GetMethodID(
+                                            gSimulatorClassRefs.stringPropertyBuilderCls, "build", "()Lorg/oic/simulator/StringProperty;");
+            return env->CallObjectMethod(jPropertyBuilder, buildMID);
+        }
+
+        static std::shared_ptr<StringProperty> toCpp(JNIEnv *env, jobject &jProperty)
+        {
+            static jfieldID defaultValueFID = env->GetFieldID(gSimulatorClassRefs.stringPropertyCls,
+                                              "mDefaultValue", "Ljava/lang/String;");
+            static jfieldID hasRangeFID = env->GetFieldID(gSimulatorClassRefs.stringPropertyCls,
+                                          "mHasRange", "Z");
+
+            jstring defaultValue = (jstring) env->GetObjectField(jProperty, defaultValueFID);
+            jboolean hasRange = env->GetBooleanField(jProperty, hasRangeFID);
+
+            std::shared_ptr<StringProperty> stringProperty =
+                StringProperty::build(JniString(env, defaultValue).get());
+
+            if (hasRange)
+            {
+                static jfieldID minFID = env->GetFieldID(gSimulatorClassRefs.stringPropertyCls,
+                                         "mMin", "I");
+                static jfieldID maxFID = env->GetFieldID(gSimulatorClassRefs.stringPropertyCls,
+                                         "mMax", "I");
+
+                jint min = env->GetIntField(jProperty, minFID);
+                jint max = env->GetIntField(jProperty, maxFID);
+                if (min >= 0 && max >= 0)
+                    stringProperty->setRange(static_cast<size_t>(min), static_cast<size_t>(max));
+            }
+            else
+            {
+                static jfieldID valuesFID = env->GetFieldID(gSimulatorClassRefs.stringPropertyCls,
+                                            "mValues", "[Ljava/lang/String;");
+                jobjectArray jValues = (jobjectArray) env->GetObjectField(jProperty, valuesFID);
+                if (jValues)
+                {
+                    std::vector<std::string> values;
+                    size_t length = env->GetArrayLength(jValues);
+                    for (size_t index = 0; index < length; index++)
+                    {
+                        jstring jValue = (jstring) env->GetObjectArrayElement(jValues, index);
+                        values.push_back(JniString(env, jValue).get());
+                    }
+                }
+            }
+
+            return stringProperty;
+        }
+};
+
+class JniArrayProperty
+{
+    public:
+        static jobject toJava(JNIEnv *env, const std::shared_ptr<ArrayProperty> &property)
+        {
+            if (!property)
+                return nullptr;
+
+            // Create Java ArrayProperty.Builder object
+            jobject jPropertyBuilder = nullptr;
+            static jmethodID builderCtor = env->GetMethodID(
+                                               gSimulatorClassRefs.arrayPropertyBuilderCls, "<init>", "()V");
+            jPropertyBuilder = env->NewObject(gSimulatorClassRefs.arrayPropertyBuilderCls, builderCtor);
+
+            // Set variable size propety
+            if (property->isVariable())
+            {
+                static jmethodID setVariableMID = env->GetMethodID(
+                                                      gSimulatorClassRefs.arrayPropertyBuilderCls, "setVariableSize", "(Z)V");
+                env->CallVoidMethod(jPropertyBuilder, setVariableMID, property->isVariable());
+            }
+
+            // Set unique propety
+            if (property->isUnique())
+            {
+                static jmethodID setUniqueMID = env->GetMethodID(
+                                                    gSimulatorClassRefs.arrayPropertyBuilderCls, "setUnique", "(Z)V");
+                env->CallVoidMethod(jPropertyBuilder, setUniqueMID, property->isUnique());
+            }
+
+            // Set range property
+            if (property->hasRange())
+            {
+                size_t min = property->getMinItems();
+                size_t max = property->getMaxItems();
+
+                static jmethodID setRangeMID = env->GetMethodID(
+                                                   gSimulatorClassRefs.arrayPropertyBuilderCls, "setRange", "(II)V");
+                env->CallVoidMethod(jPropertyBuilder, setRangeMID, static_cast<jint>(min),
+                                    static_cast<jint>(max));
+            }
+
+            // Set element property
+            jobject jElementProperty = AttributePropertyToJava(env, property->getElementProperty());
+            static jmethodID setElementPropertyMID = env->GetMethodID(
+                        gSimulatorClassRefs.arrayPropertyBuilderCls, "setElementProperty",
+                        "(Lorg/oic/simulator/AttributeProperty;)V");
+            env->CallVoidMethod(jPropertyBuilder, setElementPropertyMID, jElementProperty);
+
+            // Create Java ArrayProperty object
+            static jmethodID buildMID = env->GetMethodID(
+                                            gSimulatorClassRefs.arrayPropertyBuilderCls, "build", "()Lorg/oic/simulator/ArrayProperty;");
+            return env->CallObjectMethod(jPropertyBuilder, buildMID);
+        }
+
+        static std::shared_ptr<ArrayProperty> toCpp(JNIEnv *env, jobject &jProperty)
+        {
+            static jfieldID hasRangeFID = env->GetFieldID(gSimulatorClassRefs.arrayPropertyCls,
+                                          "mHasRange", "Z");
+            static jfieldID variableFID = env->GetFieldID(gSimulatorClassRefs.arrayPropertyCls,
+                                          "mIsVariableSize", "Z");
+            static jfieldID uniqueFID = env->GetFieldID(gSimulatorClassRefs.arrayPropertyCls,
+                                        "mIsUnique", "Z");
+            static jfieldID elementPropertyFID = env->GetFieldID(gSimulatorClassRefs.arrayPropertyCls,
+                                                 "mElementProperty", "Lorg/oic/simulator/AttributeProperty;");
+
+            jboolean hasRange = env->GetBooleanField(jProperty, hasRangeFID);
+            jboolean isVariable = env->GetBooleanField(jProperty, variableFID);
+            jboolean isUnique = env->GetBooleanField(jProperty, uniqueFID);
+            jobject jElementProperty = env->GetObjectField(jProperty, elementPropertyFID);
+
+            std::shared_ptr<ArrayProperty> arrayProperty = ArrayProperty::build();
+
+            arrayProperty->setVariable(isVariable);
+            arrayProperty->setUnique(isUnique);
+
+            if (hasRange)
+            {
+                static jfieldID minFID = env->GetFieldID(gSimulatorClassRefs.arrayPropertyCls,
+                                         "mMin", "I");
+                static jfieldID maxFID = env->GetFieldID(gSimulatorClassRefs.arrayPropertyCls,
+                                         "mMax", "I");
+
+                jint min = env->GetIntField(jProperty, minFID);
+                jint max = env->GetIntField(jProperty, maxFID);
+                if (min >= 0 && max >= 0)
+                    arrayProperty->setRange(static_cast<size_t>(min), static_cast<size_t>(max));
+            }
+
+            if (jElementProperty)
+            {
+                arrayProperty->setElementProperty(AttributePropertyToCpp(env, jElementProperty));
+            }
+
+            return arrayProperty;
+        }
+};
+
+class JniModelProperty
+{
+    public:
+        static jobject toJava(JNIEnv *env, const std::shared_ptr<ModelProperty> &property)
+        {
+            if (!property)
+                return nullptr;
+
+            // Create Java ModelProperty object
+            jobject jModelProperty = nullptr;
+            static jmethodID modelPropertyCtor = env->GetMethodID(
+                    gSimulatorClassRefs.modelPropertyCls, "<init>", "()V");
+            jModelProperty = env->NewObject(gSimulatorClassRefs.modelPropertyCls, modelPropertyCtor);
+
+            // Set child propeties
+            for (auto &propertyEntry : property->getChildProperties())
+            {
+                jstring jAttrName = env->NewStringUTF(propertyEntry.first.c_str());
+                jobject jProperty = AttributePropertyToJava(env, propertyEntry.second);
+                jboolean required = property->isRequired(propertyEntry.first);
+
+                static jmethodID addMID = env->GetMethodID(
+                                              gSimulatorClassRefs.modelPropertyCls, "add",
+                                              "(Ljava/lang/String;Lorg/oic/simulator/AttributeProperty;Z)Z");
+                env->CallBooleanMethod(jModelProperty, addMID, jAttrName, jProperty, required);
+            }
+
+            return jModelProperty;
+        }
+
+        static std::shared_ptr<ModelProperty> toCpp(JNIEnv *env, jobject &jProperty)
+        {
+            static jfieldID childPropertiesFID = env->GetFieldID(gSimulatorClassRefs.modelPropertyCls,
+                                                 "mChildProperties", "Ljava/util/Map;");
+            static jmethodID isRequiredMID = env->GetMethodID(gSimulatorClassRefs.modelPropertyCls,
+                                             "isRequired", "()Z");
+            static jmethodID entrySetMID = env->GetMethodID(gSimulatorClassRefs.mapCls,
+                                           "entrySet", "()Ljava/util/Set;");
+            static jmethodID iteratorMID = env->GetMethodID(gSimulatorClassRefs.setCls,
+                                           "iterator", "()Ljava/util/Iterator;");
+            static jmethodID hasNextMID = env->GetMethodID(gSimulatorClassRefs.iteratorCls,
+                                          "hasNext", "()Z");
+            static jmethodID nextMID = env->GetMethodID(gSimulatorClassRefs.iteratorCls,
+                                       "next", "()Ljava/lang/Object;");
+            static jmethodID getKeyMID = env->GetMethodID(gSimulatorClassRefs.mapEntryCls,
+                                         "getKey", "()Ljava/lang/Object;");
+            static jmethodID getValueMID = env->GetMethodID(gSimulatorClassRefs.mapEntryCls,
+                                           "getValue", "()Ljava/lang/Object;");
+
+            std::shared_ptr<ModelProperty> modelProperty = ModelProperty::build();
+            jobject jChildProperties = env->GetObjectField(jProperty, childPropertiesFID);
+            if (jChildProperties)
+            {
+                jobject entrySet = env->CallObjectMethod(jChildProperties, entrySetMID);
+                jobject iterator = env->CallObjectMethod(entrySet, iteratorMID);
+                if (entrySet && iterator)
+                {
+                    while (env->CallBooleanMethod(iterator, hasNextMID))
+                    {
+                        jobject entry = env->CallObjectMethod(iterator, nextMID);
+                        jstring key = (jstring) env->CallObjectMethod(entry, getKeyMID);
+                        jobject value = env->CallObjectMethod(entry, getValueMID);
+                        jboolean isRequired = env->CallBooleanMethod(jProperty, isRequiredMID, key);
+
+                        modelProperty->add(JniString(env, key).get(),
+                                           AttributePropertyToCpp(env, value), isRequired);
+
+                        env->DeleteLocalRef(entry);
+                        env->DeleteLocalRef(key);
+                        env->DeleteLocalRef(value);
+                    }
+                }
+            }
+
+            return modelProperty;
+        }
+};
+
+jobject AttributePropertyToJava(JNIEnv *env,
+                                const std::shared_ptr<AttributeProperty> &property)
+{
+    if (!property)
+        return nullptr;
+
+    if (property->isInteger())
+    {
+        return JniIntegerProperty::toJava(env, property->asInteger());
+    }
+    else if (property->isDouble())
+    {
+        return JniDoubleProperty::toJava(env, property->asDouble());
+    }
+    else if (property->isBoolean())
+    {
+        return JniBooleanProperty::toJava(env, property->asBoolean());
+    }
+    else if (property->isString())
+    {
+        return JniStringProperty::toJava(env, property->asString());
+    }
+    else if (property->isArray())
+    {
+        return JniArrayProperty::toJava(env, property->asArray());
+    }
+    else if (property->isModel())
+    {
+        return JniModelProperty::toJava(env, property->asModel());
+    }
+
+    return nullptr; // Control should never reach here
+}
+
+std::shared_ptr<AttributeProperty> AttributePropertyToCpp(JNIEnv *env,
+        jobject &jProperty)
+{
+    if (!jProperty)
+        return nullptr;
+
+    switch (getType(env, jProperty))
+    {
+        case AttributeProperty::Type::INTEGER:
+            return JniIntegerProperty::toCpp(env, jProperty);
+
+        case AttributeProperty::Type::DOUBLE:
+            return JniDoubleProperty::toCpp(env, jProperty);
+
+        case AttributeProperty::Type::BOOLEAN:
+            return JniBooleanProperty::toCpp(env, jProperty);
+
+        case AttributeProperty::Type::STRING:
+            return JniStringProperty::toCpp(env, jProperty);
+
+        case AttributeProperty::Type::ARRAY:
+            return JniArrayProperty::toCpp(env, jProperty);
+
+        case AttributeProperty::Type::MODEL:
+            return JniModelProperty::toCpp(env, jProperty);
+    }
+
+    return nullptr; // Control should never reach here
+}
+
diff --git a/service/simulator/java/jni/simulator_resource_model_schema_jni.h b/service/simulator/java/jni/simulator_resource_model_schema_jni.h
new file mode 100644 (file)
index 0000000..cf3e403
--- /dev/null
@@ -0,0 +1,34 @@
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef SIMULATOR_RESOURCE_MODEL_SCHEMA_JNI_H_
+#define SIMULATOR_RESOURCE_MODEL_SCHEMA_JNI_H_
+
+#include <jni.h>
+
+#include "simulator_resource_model_schema.h"
+
+jobject AttributePropertyToJava(JNIEnv *env,
+        const std::shared_ptr<AttributeProperty> &property);
+
+std::shared_ptr<AttributeProperty> AttributePropertyToCpp(JNIEnv *env,
+        jobject &jProperty);
+
+#endif
index 8a23727..10eee4c 100644 (file)
@@ -23,7 +23,7 @@
 #include "jni_sharedobject_holder.h"
 #include "jni_vector.h"
 
-jobject createSingleResource(JNIEnv *env, SimulatorResourceSP singleResource)
+jobject CreateSingleResource(JNIEnv *env, SimulatorResourceSP singleResource)
 {
     if (!singleResource)
         return nullptr;
@@ -46,7 +46,7 @@ jobject createSingleResource(JNIEnv *env, SimulatorResourceSP singleResource)
     return resource;
 }
 
-jobject createCollectionResource(JNIEnv *env, SimulatorResourceSP collectionResource)
+jobject CreateCollectionResource(JNIEnv *env, SimulatorResourceSP collectionResource)
 {
     if (!collectionResource)
         return nullptr;
@@ -68,17 +68,17 @@ jobject createCollectionResource(JNIEnv *env, SimulatorResourceSP collectionReso
     return resource;
 }
 
-jobject createSimulatorResource(JNIEnv *env, SimulatorResourceSP resource)
+jobject CreateSimulatorResource(JNIEnv *env, SimulatorResourceSP resource)
 {
     if (!resource)
         return nullptr;
 
     if (SimulatorResource::Type::COLLECTION_RESOURCE == resource->getType())
-        return createCollectionResource(env, resource);
-    return createSingleResource(env, resource);
+        return CreateCollectionResource(env, resource);
+    return CreateSingleResource(env, resource);
 }
 
-jobject createSimulatorResourceVector(JNIEnv *env, std::vector<SimulatorResourceSP> &resources)
+jobject CreateSimulatorResourceVector(JNIEnv *env, std::vector<SimulatorResourceSP> &resources)
 {
     if (!resources.size())
         return nullptr;
@@ -91,12 +91,12 @@ jobject createSimulatorResourceVector(JNIEnv *env, std::vector<SimulatorResource
                                  "add", "(Ljava/lang/Object;)Z");
 
     for (auto &resource : resources)
-        env->CallBooleanMethod(vectorObject, addMethod, createSimulatorResource(env, resource));
+        env->CallBooleanMethod(vectorObject, addMethod, CreateSimulatorResource(env, resource));
 
     return vectorObject;
 }
 
-jobject createSimulatorRemoteResource(JNIEnv *env, SimulatorRemoteResourceSP &remoteResource)
+jobject CreateSimulatorRemoteResource(JNIEnv *env, SimulatorRemoteResourceSP &remoteResource)
 {
     if (!remoteResource)
         return nullptr;
@@ -148,7 +148,7 @@ jobject createSimulatorRemoteResource(JNIEnv *env, SimulatorRemoteResourceSP &re
     jobject ResTypes = JniVector(env).toJava(resourceTypes);
     env->SetObjectField(resource, resTypesID, ResTypes);
 
-    std::vector<std::string> interfaceTypes = remoteResource->getResourceInterfaces();
+    std::vector<std::string> interfaceTypes = remoteResource->getInterface();
     jobject resInterfaces = JniVector(env).toJava(interfaceTypes);
     env->SetObjectField(resource, interfacesID, resInterfaces);
 
index bfcb1d6..49a2e8d 100644 (file)
 #include "simulator_collection_resource.h"
 #include "simulator_remote_resource.h"
 
-jobject createSingleResource(JNIEnv *env, SimulatorResourceSP singleResource);
-jobject createCollectionResource(JNIEnv *env, SimulatorResourceSP collectionResource);
-jobject createSimulatorResource(JNIEnv *env, SimulatorResourceSP resource);
-jobject createSimulatorResourceVector(JNIEnv *env, std::vector<SimulatorResourceSP> &resources);
-jobject createSimulatorRemoteResource(JNIEnv *env, SimulatorRemoteResourceSP &remoteResource);
+jobject CreateSingleResource(JNIEnv *env, SimulatorResourceSP singleResource);
+jobject CreateCollectionResource(JNIEnv *env, SimulatorResourceSP collectionResource);
+jobject CreateSimulatorResource(JNIEnv *env, SimulatorResourceSP resource);
+jobject CreateSimulatorResourceVector(JNIEnv *env, std::vector<SimulatorResourceSP> &resources);
+jobject CreateSimulatorRemoteResource(JNIEnv *env, SimulatorRemoteResourceSP &remoteResource);
 
 #endif
index 81b113c..22cd6bb 100644 (file)
@@ -19,6 +19,7 @@
  ******************************************************************/
 
 #include "simulator_resource_model_jni.h"
+#include "simulator_resource_attribute_jni.h"
 #include "simulator_exceptions_jni.h"
 #include "simulator_utils_jni.h"
 #include "jni_sharedobject_holder.h"
 
 #include "simulator_single_resource.h"
 
-#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return;}
-#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){throwBadObjectException(ENV, "No corresponsing native object!"); return RET;}
+#define VALIDATE_OBJECT(ENV, OBJECT) if (!OBJECT){ThrowBadObjectException(ENV, "No corresponsing native object!"); return;}
+#define VALIDATE_OBJECT_RET(ENV, OBJECT, RET) if (!OBJECT){ThrowBadObjectException(ENV, "No corresponsing native object!"); return RET;}
 
-SimulatorSingleResourceSP simulatorSingleResourceToCpp(JNIEnv *env, jobject object)
+static SimulatorSingleResourceSP simulatorSingleResourceToCpp(JNIEnv *env, jobject object)
 {
     JniSharedObjectHolder<SimulatorSingleResource> *jniResource =
-        GetHandle<JniSharedObjectHolder<SimulatorSingleResource>>(env, object);
+        getHandle<JniSharedObjectHolder<SimulatorSingleResource>>(env, object);
     if (jniResource)
         return jniResource->get();
     return nullptr;
 }
 
-static AutomationType AutomationTypeToCpp(JNIEnv *env, jobject jType)
+static AutoUpdateType autoUpdateTypeToCpp(JNIEnv *env, jobject jType)
 {
     static jmethodID ordinalMID = env->GetMethodID(
-                                      gSimulatorClassRefs.automationTypeCls, "ordinal", "()I");
+                                      gSimulatorClassRefs.autoUpdateTypeCls, "ordinal", "()I");
 
     int ordinal = env->CallIntMethod(jType, ordinalMID);
-    return AutomationType(ordinal);
+    return AutoUpdateType(ordinal);
 }
 
 static void onAutoUpdationComplete(jobject listener, const std::string &uri, const int id)
 {
-    JNIEnv *env = getEnv();
+    JNIEnv *env = GetEnv();
     if (!env)
         return;
 
@@ -61,7 +62,7 @@ static void onAutoUpdationComplete(jobject listener, const std::string &uri, con
 
     jstring jUri = env->NewStringUTF(uri.c_str());
     env->CallVoidMethod(listener, listenerMethod, jUri, id);
-    releaseEnv();
+    ReleaseEnv();
 }
 
 #ifdef __cplusplus
@@ -69,163 +70,175 @@ extern "C" {
 #endif
 
 JNIEXPORT jobject JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_getAttribute
-(JNIEnv *env, jobject object, jstring attrName)
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeGetAttribute
+(JNIEnv *env, jobject object, jstring jAttrName)
 {
-    VALIDATE_INPUT_RET(env, !attrName, "Attribute name is null!", nullptr)
+    VALIDATE_INPUT_RET(env, !jAttrName, "Attribute name is null!", nullptr)
 
     SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, singleResource, nullptr)
 
-    JniString jniAttrName(env, attrName);
-    SimulatorResourceModel::Attribute attribute;
+    JniString jniAttrName(env, jAttrName);
+    SimulatorResourceAttribute attribute;
     if (singleResource->getAttribute(jniAttrName.get(), attribute))
-        return simulatorResourceAttributeToJava(env, attribute);
+        return SimulatorResourceAttributeToJava(env, attribute);
     return nullptr;
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_addAttribute
-(JNIEnv *env, jobject object, jobject resAttribute)
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeGetAttributes
+(JNIEnv *env, jobject object)
+{
+    SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
+    VALIDATE_OBJECT_RET(env, singleResource, nullptr)
+
+    return SimulatorResourceAttributesToJava(env, singleResource->getAttributes());
+}
+
+JNIEXPORT jboolean JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeAddAttribute
+(JNIEnv *env, jobject object, jobject jResAttribute)
 {
-    VALIDATE_INPUT(env, !resAttribute, "Resource attribute is null!")
+    VALIDATE_INPUT_RET(env, !jResAttribute, "Resource attribute is null!", false)
 
     SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
-    VALIDATE_OBJECT(env, singleResource)
+    VALIDATE_OBJECT_RET(env, singleResource, false)
 
     try
     {
-        SimulatorResourceModel::Attribute attribute;
-        if (!simulatorResourceAttributeToCpp(env, resAttribute, attribute))
+        SimulatorResourceAttribute attribute;
+        if (!SimulatorResourceAttributeToCpp(env, jResAttribute, attribute))
         {
-            throwSimulatorException(env, SIMULATOR_ERROR,
+            ThrowSimulatorException(env, SIMULATOR_ERROR,
                                     "Failed to covnert SimulatorResourceAttribute java object!");
-            return;
+            return false;
         }
-
-        singleResource->addAttribute(attribute);
+        return singleResource->addAttribute(attribute);
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
+
+    return false;
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_updateAttribute
-(JNIEnv *env, jobject object, jstring attrName, jobject attrValue)
+JNIEXPORT jboolean JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeUpdateAttribute
+(JNIEnv *env, jobject object, jstring jAttrName, jobject jAttrValue)
 {
-    VALIDATE_INPUT(env, !attrName, "Attribute name is null!")
-    VALIDATE_INPUT(env, !attrValue, "Attribute value is null!")
+    VALIDATE_INPUT_RET(env, !jAttrName, "Attribute name is null!", false)
+    VALIDATE_INPUT_RET(env, !jAttrValue, "Attribute value is null!", false)
 
     SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
-    VALIDATE_OBJECT(env, singleResource)
+    VALIDATE_OBJECT_RET(env, singleResource, false)
 
-    SimulatorResourceModel::ValueVariant value;
-    if (!AttributeValueToCpp(env, attrValue, value))
+    AttributeValueVariant value;
+    if (!AttributeValueToCpp(env, jAttrValue, value))
     {
-        throwSimulatorException(env, SIMULATOR_ERROR,
+        ThrowSimulatorException(env, SIMULATOR_ERROR,
                                 "Failed to covnert AttributeValue java object!");
-        return;
+        return false;
     }
 
-    SimulatorResourceModel::Attribute attribute(JniString(env, attrName).get());
+    SimulatorResourceAttribute attribute(JniString(env, jAttrName).get());
     attribute.setValue(value);
-    singleResource->updateAttributeValue(attribute);
+    return singleResource->updateAttributeValue(attribute);
 }
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_removeAttribute
-(JNIEnv *env, jobject object, jstring attrName)
+JNIEXPORT jboolean JNICALL
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeRemoveAttribute
+(JNIEnv *env, jobject object, jstring jAttrName)
 {
-    VALIDATE_INPUT(env, !attrName, "Attribute name is null!")
+    VALIDATE_INPUT_RET(env, !jAttrName, "Attribute name is null!", false)
 
     SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
-    VALIDATE_OBJECT(env, singleResource)
+    VALIDATE_OBJECT_RET(env, singleResource, false)
 
     try
     {
-        JniString jniAttrName(env, attrName);
-        singleResource->removeAttribute(jniAttrName.get());
+        JniString jniAttrName(env, jAttrName);
+        return singleResource->removeAttribute(jniAttrName.get());
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
+
+    return false;
 }
 
 JNIEXPORT jint JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_startResourceUpdation
-(JNIEnv *env, jobject object, jobject type, jint interval, jobject listener)
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeStartResourceUpdation
+(JNIEnv *env, jobject object, jobject jType, jint jInterval, jobject jListener)
 {
-    VALIDATE_CALLBACK_RET(env, listener, -1)
+    VALIDATE_CALLBACK_RET(env, jListener, -1)
 
     SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, singleResource, -1)
 
-    jobject listenerRef = env->NewGlobalRef(listener);
-    updateCompleteCallback callback =  [listenerRef](const std::string & uri, const int id)
+    jobject listenerRef = env->NewGlobalRef(jListener);
+    SimulatorSingleResource::AutoUpdateCompleteCallback callback =  [listenerRef](
+                const std::string & uri, const int id)
     {
         onAutoUpdationComplete(listenerRef, uri, id);
     };
 
     try
     {
-        AutomationType automationType = AutomationTypeToCpp(env, type);
-        int id = singleResource->startResourceUpdation(automationType, interval, callback);
-        return id;
+        AutoUpdateType autoUpdateType = autoUpdateTypeToCpp(env, jType);
+        return singleResource->startResourceUpdation(autoUpdateType, jInterval, callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 
     return -1;
 }
 
 JNIEXPORT jint JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_startAttributeUpdation
-(JNIEnv *env, jobject object, jstring attrName, jobject type, jint interval, jobject listener)
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeStartAttributeUpdation
+(JNIEnv *env, jobject object, jstring jAttrName, jobject jType, jint jInterval, jobject jListener)
 {
-    VALIDATE_INPUT_RET(env, !attrName, "Attribute name is null!", -1)
-    VALIDATE_CALLBACK_RET(env, listener, -1)
+    VALIDATE_INPUT_RET(env, !jAttrName, "Attribute name is null!", -1)
+    VALIDATE_CALLBACK_RET(env, jListener, -1)
 
     SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
     VALIDATE_OBJECT_RET(env, singleResource, -1)
 
-    jobject listenerRef = env->NewGlobalRef(listener);
-    updateCompleteCallback callback =  [listenerRef](const std::string & uri, const int id)
+    jobject listenerRef = env->NewGlobalRef(jListener);
+    SimulatorSingleResource::AutoUpdateCompleteCallback callback =
+        [listenerRef](const std::string & uri, const int id)
     {
         onAutoUpdationComplete(listenerRef, uri, id);
     };
 
-    JniString jniAttrName(env, attrName);
-    AutomationType automationType = AutomationTypeToCpp(env, type);
-
     try
     {
-        int id = singleResource->startAttributeUpdation(jniAttrName.get(), automationType,
-                 interval, callback);
-        return id;
+        JniString jniAttrName(env, jAttrName);
+        AutoUpdateType autoUpdateType = autoUpdateTypeToCpp(env, jType);
+        return singleResource->startAttributeUpdation(jniAttrName.get(), autoUpdateType,
+                 jInterval, callback);
     }
     catch (InvalidArgsException &e)
     {
-        throwInvalidArgsException(env, e.code(), e.what());
+        ThrowInvalidArgsException(env, e.code(), e.what());
     }
     catch (SimulatorException &e)
     {
-        throwSimulatorException(env, e.code(), e.what());
+        ThrowSimulatorException(env, e.code(), e.what());
     }
 
     return -1;
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_stopUpdation
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeStopUpdation
 (JNIEnv *env, jobject object, jint id)
 {
     SimulatorSingleResourceSP singleResource = simulatorSingleResourceToCpp(env, object);
@@ -235,11 +248,11 @@ Java_org_oic_simulator_server_SimulatorSingleResource_stopUpdation
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_server_SimulatorSingleResource_dispose
+Java_org_oic_simulator_server_SimulatorSingleResource_nativeDispose
 (JNIEnv *env, jobject object)
 {
     JniSharedObjectHolder<SimulatorSingleResource> *resource =
-        GetHandle<JniSharedObjectHolder<SimulatorSingleResource>>(env, object);
+        getHandle<JniSharedObjectHolder<SimulatorSingleResource>>(env, object);
     delete resource;
 }
 
index 1f971ce..ce154f7 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "simulator_utils_jni.h"
 
-jobject simulatorResultToJava(JNIEnv *env, SimulatorResult errorCode)
+jobject SimulatorResultToJava(JNIEnv *env, SimulatorResult errorCode)
 {
     switch (errorCode)
     {
@@ -284,6 +284,14 @@ jobject simulatorResultToJava(JNIEnv *env, SimulatorResult errorCode)
                                           "SIMULATOR_BAD_OBJECT", "Lorg/oic/simulator/SimulatorResult;");
                 return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
             }
+        case SIMULATOR_BAD_SCHEMA:
+            {
+                static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
+                                          "SIMULATOR_BAD_SCHEMA", "Lorg/oic/simulator/SimulatorResult;");
+                return env->GetStaticObjectField(gSimulatorClassRefs.simulatorResultCls, fieldID);
+            }
+        default:
+            break;
     }
 
     static jfieldID fieldID = env->GetStaticFieldID(gSimulatorClassRefs.simulatorResultCls,
index f3ec682..85aa4a4 100644 (file)
@@ -38,23 +38,37 @@ typedef struct
     jclass setCls;
     jclass iteratorCls;
 
-    jclass interfaceTypeCls;
     jclass simulatorResourceCls;
     jclass simulatorResourceTypeCls;
     jclass simulatorSingleResourceCls;
     jclass simulatorCollectionResourceCls;
     jclass simulatorResourceModelCls;
     jclass simulatorResourceAttributeCls;
-    jclass automationTypeCls;
     jclass attributeValueCls;
     jclass attributeValueTypeCls;
     jclass attributeTypeInfoCls;
     jclass attributePropertyCls;
     jclass attributePropertyTypeCls;
+    jclass integerPropertyCls;
+    jclass integerPropertyBuilderCls;
+    jclass doublePropertyCls;
+    jclass doublePropertyBuilderCls;
+    jclass booleanPropertyCls;
+    jclass booleanPropertyBuilderCls;
+    jclass stringPropertyCls;
+    jclass stringPropertyBuilderCls;
+    jclass arrayPropertyCls;
+    jclass arrayPropertyBuilderCls;
+    jclass modelPropertyCls;
+    jclass autoUpdateTypeCls;
+
     jclass simulatorRemoteResourceCls;
+    jclass requestTypeCls;
     jclass observerCls;
     jclass deviceInfoCls;
     jclass platformInfoCls;
+    jclass simulatorRequestModelCls;
+
     jclass simulatorExceptionCls;
     jclass invalidArgsExceptionCls;
     jclass noSupportExceptionCls;
@@ -78,36 +92,36 @@ typedef struct
     jclass simulatorResModel3DArrayCls;
 } SimulatorClassRefs;
 
-#define VALIDATE_INPUT(ENV, CONDITION, MSG) if (CONDITION) {throwInvalidArgsException(ENV, SIMULATOR_INVALID_PARAM, MSG); return;}
-#define VALIDATE_INPUT_RET(ENV, CONDITION, MSG, RET) if (CONDITION) {throwInvalidArgsException(ENV, SIMULATOR_INVALID_PARAM, MSG); return RET;}
+#define VALIDATE_INPUT(ENV, CONDITION, MSG) if (CONDITION) {ThrowInvalidArgsException(ENV, SIMULATOR_INVALID_PARAM, MSG); return;}
+#define VALIDATE_INPUT_RET(ENV, CONDITION, MSG, RET) if (CONDITION) {ThrowInvalidArgsException(ENV, SIMULATOR_INVALID_PARAM, MSG); return RET;}
 
-#define VALIDATE_CALLBACK(ENV, CALLBACK) if (!CALLBACK){throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!"); return;}
-#define VALIDATE_CALLBACK_RET(ENV, CALLBACK, RET) if (!CALLBACK){throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!"); return RET;}
+#define VALIDATE_CALLBACK(ENV, CALLBACK) if (!CALLBACK){ThrowInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!"); return;}
+#define VALIDATE_CALLBACK_RET(ENV, CALLBACK, RET) if (!CALLBACK){ThrowInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!"); return RET;}
 
-static jfieldID GetHandleField(JNIEnv *env, jobject jobj)
+static jfieldID getHandleField(JNIEnv *env, jobject jobj)
 {
     jclass cls = env->GetObjectClass(jobj);
     return env->GetFieldID(cls, "mNativeHandle", "J");
 }
 
 template <typename T>
-static T *GetHandle(JNIEnv *env, jobject jobj)
+static T *getHandle(JNIEnv *env, jobject jobj)
 {
-    jlong handle = env->GetLongField(jobj, GetHandleField(env, jobj));
+    jlong handle = env->GetLongField(jobj, getHandleField(env, jobj));
     return reinterpret_cast<T *>(handle);
 }
 
 template <typename T>
-static void SetHandle(JNIEnv *env, jobject jobj, T *type)
+static void setHandle(JNIEnv *env, jobject jobj, T *type)
 {
     jlong handle = reinterpret_cast<jlong>(type);
-    env->SetLongField(jobj, GetHandleField(env, jobj), handle);
+    env->SetLongField(jobj, getHandleField(env, jobj), handle);
 }
 
-extern JNIEnv *getEnv();
-extern void releaseEnv();
+extern JNIEnv *GetEnv();
+extern void ReleaseEnv();
 extern SimulatorClassRefs gSimulatorClassRefs;
 
-jobject simulatorResultToJava(JNIEnv *env, SimulatorResult errorCode);
+jobject SimulatorResultToJava(JNIEnv *env, SimulatorResult errorCode);
 
 #endif