Fix for issue of allowed values property of IntegerProperty, DoubleProperty
authorHarish Kumara Marappa <h.marappa@samsung.com>
Thu, 3 Mar 2016 20:32:38 +0000 (02:02 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 4 Mar 2016 05:52:35 +0000 (05:52 +0000)
and StringProperty not converting from Java to C++ objects.

Change-Id: I1a639bbfd52e2c548d7ffad3e8fc000cf7fc982a
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5375
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/simulator/java/jni/jni_map.cpp
service/simulator/java/jni/jni_vector.cpp
service/simulator/java/jni/simulator_init_jni.cpp
service/simulator/java/jni/simulator_manager_jni.cpp
service/simulator/java/jni/simulator_remote_resource_jni.cpp
service/simulator/java/jni/simulator_resource_attribute_jni.h
service/simulator/java/jni/simulator_resource_model_jni.h
service/simulator/java/jni/simulator_resource_model_schema_jni.cpp
service/simulator/java/jni/simulator_resource_model_schema_jni.h
service/simulator/java/jni/simulator_single_resource_jni.cpp

index 6d1daee22851d4100cc9c8d6e570a435f5ac397a..e14ec5fcc22ef8cb0f51fee5a8c36dc53704e791 100644 (file)
@@ -26,14 +26,14 @@ JniMap::JniMap(JNIEnv *env)
     m_env = env;
 
     static jmethodID mapCtor = env->GetMethodID(
-                                       gSimulatorClassRefs.hashMapCls, "<init>", "()V");
+                                   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;");
+                                 "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
     m_env->CallObjectMethod(m_hashMap, putMethod, jKey, jValue);
 }
 
index 10b8bd0d2247efea7bcb4e34f8db65410d6b167a..386a80170934c1f94a20d06ec918ee7504c7572a 100644 (file)
@@ -27,14 +27,14 @@ JniVector::JniVector(JNIEnv *env) : m_env(env) {}
 jobject JniVector::toJava()
 {
     static jmethodID vectorCtor = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
-        "<init>", "()V");
+                                  "<init>", "()V");
     return m_env->NewObject(gSimulatorClassRefs.vectorCls, vectorCtor);
 }
 
 jobject JniVector::toJava(std::vector<std::string> &cppVector)
 {
     static jmethodID addMethod = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
-        "add", "(Ljava/lang/Object;)Z");
+                                 "add", "(Ljava/lang/Object;)Z");
 
     jobject vectorObject = toJava();
     if (!vectorObject)
@@ -53,16 +53,16 @@ jobject JniVector::toJava(std::vector<std::string> &cppVector)
 int JniVector::getSize(jobject jVector)
 {
     static jmethodID sizeMethodID = m_env->GetMethodID(gSimulatorClassRefs.vectorCls,
-        "size", "()I");
+                                    "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(gSimulatorClassRefs.vectorCls,
-        "get", "(I)Ljava/lang/Object;");
+                                 "get", "(I)Ljava/lang/Object;");
     static jmethodID intValueMethod = m_env->GetMethodID(gSimulatorClassRefs.integerCls,
-        "intValue", "()I");
+                                      "intValue", "()I");
 
     for (int index = 0; index < size; index++)
     {
@@ -75,9 +75,9 @@ 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(gSimulatorClassRefs.vectorCls,
-        "get", "(I)Ljava/lang/Object;");
+                                 "get", "(I)Ljava/lang/Object;");
     static jmethodID doubleValueMethod = m_env->GetMethodID(gSimulatorClassRefs.doubleCls,
-        "doubleValue", "()D");
+                                         "doubleValue", "()D");
 
     for (int index = 0; index < size; index++)
     {
@@ -90,7 +90,7 @@ 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(gSimulatorClassRefs.vectorCls,
-        "get", "(I)Ljava/lang/Object;");
+                                   "get", "(I)Ljava/lang/Object;");
 
     for (int index = 0; index < size; index++)
     {
index 2f0406a24c0dd90205a5adebf34d403dbfd5b208..cb34eba9ba270576a7b8c22dc56ed02aec7f3fba 100644 (file)
@@ -159,10 +159,10 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
     getClassRef(env, SIMULATOR_RESOURCE_TYPE_CLS, gSimulatorClassRefs.simulatorResourceTypeCls);
     getClassRef(env, SIMULATOR_SINGLE_RESOURCE_CLS, gSimulatorClassRefs.simulatorSingleResourceCls);
     getClassRef(env, SIMULATOR_COLLECTION_RESOURCE_CLS,
-        gSimulatorClassRefs.simulatorCollectionResourceCls);
+                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);
@@ -182,7 +182,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
     getClassRef(env, AUTO_UPDATE_TYPE_CLS, gSimulatorClassRefs.autoUpdateTypeCls);
 
     getClassRef(env, SIMULATOR_REMOTE_RESOURCE_CLS,
-        gSimulatorClassRefs.simulatorRemoteResourceCls);
+                gSimulatorClassRefs.simulatorRemoteResourceCls);
     getClassRef(env, REQUEST_TYPE_CLS, gSimulatorClassRefs.requestTypeCls);
     getClassRef(env, OBSERVER_CLS, gSimulatorClassRefs.observerCls);
     getClassRef(env, DEVICE_INFO_CLS, gSimulatorClassRefs.deviceInfoCls);
@@ -193,7 +193,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
     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);
@@ -209,11 +209,11 @@ 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;
index eb45d3d15ac66fbfa6e43c6f0b746811408fadc9..a5b135e1f16fd761d6b956c3cd94d59ec832fb38 100644 (file)
@@ -96,7 +96,8 @@ static void onResourceFound(jobject listener, SimulatorRemoteResourceSP remoteRe
     ReleaseEnv();
 }
 
-static void onDeviceInfoReceived(jobject listener, const std::string &hostUri, DeviceInfo &deviceInfo)
+static void onDeviceInfoReceived(jobject listener, const std::string &hostUri,
+                                 DeviceInfo &deviceInfo)
 {
     JNIEnv *env = GetEnv();
     if (!env)
@@ -126,7 +127,7 @@ static void onDeviceInfoReceived(jobject listener, const std::string &hostUri, D
 }
 
 static void onPlatformInfoReceived(jobject listener, const std::string &hostUri,
-                            PlatformInfo &platformInfo)
+                                   PlatformInfo &platformInfo)
 {
     JNIEnv *env = GetEnv();
     if (!env)
index 104541f0096d6110c22ae713afbbd6a781b96a35..f033f2cc692882d05d4d070b8f802f5d81abd9e7 100644 (file)
@@ -45,7 +45,7 @@ static SimulatorRemoteResourceSP simulatorRemoteResourceToCpp(
 }
 
 static void onObserveCallback(jobject listener, const std::string &uid, SimulatorResult /*result*/,
-                       const SimulatorResourceModel &representation, const int seq)
+                              const SimulatorResourceModel &representation, const int seq)
 {
     JNIEnv *env = GetEnv();
     if (!env)
@@ -62,7 +62,7 @@ static void onObserveCallback(jobject listener, const std::string &uid, Simulato
 }
 
 static void onGetCallback(jobject listener, const std::string &uid, SimulatorResult result,
-                   const SimulatorResourceModel &representation)
+                          const SimulatorResourceModel &representation)
 {
     JNIEnv *env = GetEnv();
     if (!env)
@@ -81,7 +81,7 @@ static void onGetCallback(jobject listener, const std::string &uid, SimulatorRes
 }
 
 static void onPutCallback(jobject listener, const std::string &uid, SimulatorResult result,
-                   const SimulatorResourceModel &representation)
+                          const SimulatorResourceModel &representation)
 {
     JNIEnv *env = GetEnv();
     if (!env)
@@ -100,7 +100,7 @@ static void onPutCallback(jobject listener, const std::string &uid, SimulatorRes
 }
 
 static void onPostCallback(jobject listener, const std::string &uid, SimulatorResult result,
-                    const SimulatorResourceModel &representation)
+                           const SimulatorResourceModel &representation)
 {
     JNIEnv *env = GetEnv();
     if (!env)
@@ -119,14 +119,14 @@ static void onPostCallback(jobject listener, const std::string &uid, SimulatorRe
 }
 
 static void onVerificationCallback(jobject listener, const std::string &uid, int id,
-                            OperationState opState)
+                                   OperationState opState)
 {
     JNIEnv *env = GetEnv();
     if (!env)
         return;
 
     jclass listenerCls = env->GetObjectClass(listener);
-    jmethodID listenerMethodId;
+    jmethodID listenerMethodId = nullptr;
     if (OP_START == opState)
     {
         listenerMethodId = env->GetMethodID(listenerCls, "onVerificationStarted", "(Ljava/lang/String;I)V");
@@ -141,8 +141,12 @@ static void onVerificationCallback(jobject listener, const std::string &uid, int
         listenerMethodId = env->GetMethodID(listenerCls, "onVerificationAborted", "(Ljava/lang/String;I)V");
     }
 
-    jstring jUid = env->NewStringUTF(uid.c_str());
-    env->CallVoidMethod(listener, listenerMethodId, jUid, id);
+    // Invoke java callback method
+    if (nullptr != listenerMethodId)
+    {
+        jstring jUid = env->NewStringUTF(uid.c_str());
+        env->CallVoidMethod(listener, listenerMethodId, jUid, id);
+    }
 
     if (OP_COMPLETE == opState || OP_ABORT == opState)
         env->DeleteGlobalRef(listener);
@@ -201,7 +205,7 @@ class JniRequestType
         static RequestType toCpp(JNIEnv *env, jobject jRequestType)
         {
             static jmethodID ordinalMID = env->GetMethodID(
-                                    gSimulatorClassRefs.requestTypeCls, "ordinal", "()I");
+                                              gSimulatorClassRefs.requestTypeCls, "ordinal", "()I");
             int ordinal = env->CallIntMethod(jRequestType, ordinalMID);
             return RequestType(ordinal);
         }
@@ -231,13 +235,13 @@ class JniSimulatorRequestModel
 
             // 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");
+                        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);
+                                  simulatorRequestModelCtor, jRequestType,
+                                  jQueryParams.get(), jRequestBodyModel);
         }
 };
 
index f4f4659a866da9593818f6c34a4b439de90c277a..b33ed4837fbbabad28b53a9ba428080b1371dd68 100644 (file)
@@ -28,7 +28,7 @@ jobject SimulatorResourceAttributeToJava(JNIEnv *env,
         const SimulatorResourceAttribute &attribute);
 
 bool SimulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
-        SimulatorResourceAttribute &attribute);
+                                     SimulatorResourceAttribute &attribute);
 
 jobject SimulatorResourceAttributesToJava(JNIEnv *env,
         const std::map<std::string, SimulatorResourceAttribute> &attributes);
index e77dfe3f60f1b1e959d928614192296e3dbd83bd..489c7871f541e6dc3e43f5f0f1864731e7c28a7a 100644 (file)
 #include "simulator_resource_model.h"
 
 jobject SimulatorResourceModelToJava(JNIEnv *env,
-        const SimulatorResourceModel &resModel);
+                                     const SimulatorResourceModel &resModel);
 
 bool SimulatorResourceModelToCpp(JNIEnv *env, jobject jResModel,
-        SimulatorResourceModel &resModel);
+                                 SimulatorResourceModel &resModel);
 
 jobject AttributeValueToJava(JNIEnv *env, const AttributeValueVariant &value);
 
 bool AttributeValueToCpp(JNIEnv *env, jobject jAttributeValue,
-        AttributeValueVariant &jValue);
+                         AttributeValueVariant &jValue);
 
 #endif
index 96b2dfb471f5ab6b98fb4c653db1d96fc0edbca0..d7e42a1f294e67073a28f41c9fb31ad3220168ea 100644 (file)
@@ -58,8 +58,8 @@ class JniIntegerProperty
             // Set Range or enum value set
             if (property->hasRange())
             {
-                int min;
-                int max;
+                int min = 0;
+                int max = 0;
                 property->getRange(min, max);
 
                 static jmethodID setRangeMID = env->GetMethodID(
@@ -122,6 +122,7 @@ class JniIntegerProperty
                     {
                         values.push_back(jIntArray[index]);
                     }
+                    integerProperty->setValues(values);
 
                     env->ReleaseIntArrayElements(jValues, jIntArray, 0);
                 }
@@ -153,8 +154,8 @@ class JniDoubleProperty
             // Set Range or enum value set
             if (property->hasRange())
             {
-                double min;
-                double max;
+                double min = 0.0;
+                double max = 0.0;
                 property->getRange(min, max);
 
                 static jmethodID setRangeMID = env->GetMethodID(
@@ -187,7 +188,7 @@ class JniDoubleProperty
             static jfieldID hasRangeFID = env->GetFieldID(gSimulatorClassRefs.doublePropertyCls,
                                           "mHasRange", "Z");
 
-            jdouble defaultValue = env->GetIntField(jProperty, defaultValueFID);
+            jdouble defaultValue = env->GetDoubleField(jProperty, defaultValueFID);
             jboolean hasRange = env->GetBooleanField(jProperty, hasRangeFID);
 
             std::shared_ptr<DoubleProperty> doubleProperty =
@@ -218,6 +219,7 @@ class JniDoubleProperty
                     {
                         values.push_back(jDoubleArray[index]);
                     }
+                    doubleProperty->setValues(values);
 
                     env->ReleaseDoubleArrayElements(jValues, jDoubleArray, 0);
                 }
@@ -285,8 +287,8 @@ class JniStringProperty
             // Set Range or enum value set
             if (property->hasRange())
             {
-                size_t min;
-                size_t max;
+                size_t min = 0;
+                size_t max = 0;
                 property->getRange(min, max);
 
                 static jmethodID setRangeMID = env->GetMethodID(
@@ -357,6 +359,7 @@ class JniStringProperty
                         jstring jValue = (jstring) env->GetObjectArrayElement(jValues, index);
                         values.push_back(JniString(env, jValue).get());
                     }
+                    stringProperty->setValues(values);
                 }
             }
 
index cf3e40320a607d8f879b9a850fa702371d5dace6..2c26a3becba9a9fe1b39e17e67c46091c85a2020 100644 (file)
@@ -26,7 +26,7 @@
 #include "simulator_resource_model_schema.h"
 
 jobject AttributePropertyToJava(JNIEnv *env,
-        const std::shared_ptr<AttributeProperty> &property);
+                                const std::shared_ptr<AttributeProperty> &property);
 
 std::shared_ptr<AttributeProperty> AttributePropertyToCpp(JNIEnv *env,
         jobject &jProperty);
index 22cd6bb842923d0e53405f4bb6a33001dc976d7d..a2dc1a12ebda617028877daa9acd83d84c8a8944 100644 (file)
@@ -223,7 +223,7 @@ Java_org_oic_simulator_server_SimulatorSingleResource_nativeStartAttributeUpdati
         JniString jniAttrName(env, jAttrName);
         AutoUpdateType autoUpdateType = autoUpdateTypeToCpp(env, jType);
         return singleResource->startAttributeUpdation(jniAttrName.get(), autoUpdateType,
-                 jInterval, callback);
+                jInterval, callback);
     }
     catch (InvalidArgsException &e)
     {