From: Harish Kumara Marappa Date: Thu, 3 Mar 2016 20:32:38 +0000 (+0530) Subject: Fix for issue of allowed values property of IntegerProperty, DoubleProperty X-Git-Tag: 1.2.0+RC1~580^2^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=606c72488e1193d81838fe6632adc161e9254858;p=platform%2Fupstream%2Fiotivity.git Fix for issue of allowed values property of IntegerProperty, DoubleProperty and StringProperty not converting from Java to C++ objects. Change-Id: I1a639bbfd52e2c548d7ffad3e8fc000cf7fc982a Signed-off-by: Harish Kumara Marappa Reviewed-on: https://gerrit.iotivity.org/gerrit/5375 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- diff --git a/service/simulator/java/jni/jni_map.cpp b/service/simulator/java/jni/jni_map.cpp index 6d1daee..e14ec5f 100644 --- a/service/simulator/java/jni/jni_map.cpp +++ b/service/simulator/java/jni/jni_map.cpp @@ -26,14 +26,14 @@ JniMap::JniMap(JNIEnv *env) m_env = env; static jmethodID mapCtor = env->GetMethodID( - gSimulatorClassRefs.hashMapCls, "", "()V"); + gSimulatorClassRefs.hashMapCls, "", "()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); } diff --git a/service/simulator/java/jni/jni_vector.cpp b/service/simulator/java/jni/jni_vector.cpp index 10b8bd0..386a801 100644 --- a/service/simulator/java/jni/jni_vector.cpp +++ b/service/simulator/java/jni/jni_vector.cpp @@ -27,14 +27,14 @@ JniVector::JniVector(JNIEnv *env) : m_env(env) {} jobject JniVector::toJava() { static jmethodID vectorCtor = m_env->GetMethodID(gSimulatorClassRefs.vectorCls, - "", "()V"); + "", "()V"); return m_env->NewObject(gSimulatorClassRefs.vectorCls, vectorCtor); } jobject JniVector::toJava(std::vector &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 &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 &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 &resul void JniVector::addElementsCpp(jobject vector, int size, std::vector &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 &re void JniVector::addElementsCpp(jobject vector, int size, std::vector &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++) { diff --git a/service/simulator/java/jni/simulator_init_jni.cpp b/service/simulator/java/jni/simulator_init_jni.cpp index 2f0406a..cb34eba 100644 --- a/service/simulator/java/jni/simulator_init_jni.cpp +++ b/service/simulator/java/jni/simulator_init_jni.cpp @@ -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; diff --git a/service/simulator/java/jni/simulator_manager_jni.cpp b/service/simulator/java/jni/simulator_manager_jni.cpp index eb45d3d..a5b135e 100644 --- a/service/simulator/java/jni/simulator_manager_jni.cpp +++ b/service/simulator/java/jni/simulator_manager_jni.cpp @@ -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) diff --git a/service/simulator/java/jni/simulator_remote_resource_jni.cpp b/service/simulator/java/jni/simulator_remote_resource_jni.cpp index 104541f..f033f2c 100644 --- a/service/simulator/java/jni/simulator_remote_resource_jni.cpp +++ b/service/simulator/java/jni/simulator_remote_resource_jni.cpp @@ -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, "", - "(Lorg/oic/simulator/client/SimulatorRemoteResource$RequestType;" - "Ljava/util/Map;Lorg/oic/simulator/ModelProperty;)V"); + gSimulatorClassRefs.simulatorRequestModelCls, "", + "(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); } }; diff --git a/service/simulator/java/jni/simulator_resource_attribute_jni.h b/service/simulator/java/jni/simulator_resource_attribute_jni.h index f4f4659..b33ed48 100644 --- a/service/simulator/java/jni/simulator_resource_attribute_jni.h +++ b/service/simulator/java/jni/simulator_resource_attribute_jni.h @@ -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 &attributes); diff --git a/service/simulator/java/jni/simulator_resource_model_jni.h b/service/simulator/java/jni/simulator_resource_model_jni.h index e77dfe3..489c787 100644 --- a/service/simulator/java/jni/simulator_resource_model_jni.h +++ b/service/simulator/java/jni/simulator_resource_model_jni.h @@ -26,14 +26,14 @@ #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 diff --git a/service/simulator/java/jni/simulator_resource_model_schema_jni.cpp b/service/simulator/java/jni/simulator_resource_model_schema_jni.cpp index 96b2dfb..d7e42a1 100644 --- a/service/simulator/java/jni/simulator_resource_model_schema_jni.cpp +++ b/service/simulator/java/jni/simulator_resource_model_schema_jni.cpp @@ -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 = @@ -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); } } diff --git a/service/simulator/java/jni/simulator_resource_model_schema_jni.h b/service/simulator/java/jni/simulator_resource_model_schema_jni.h index cf3e403..2c26a3b 100644 --- a/service/simulator/java/jni/simulator_resource_model_schema_jni.h +++ b/service/simulator/java/jni/simulator_resource_model_schema_jni.h @@ -26,7 +26,7 @@ #include "simulator_resource_model_schema.h" jobject AttributePropertyToJava(JNIEnv *env, - const std::shared_ptr &property); + const std::shared_ptr &property); std::shared_ptr AttributePropertyToCpp(JNIEnv *env, jobject &jProperty); diff --git a/service/simulator/java/jni/simulator_single_resource_jni.cpp b/service/simulator/java/jni/simulator_single_resource_jni.cpp index 22cd6bb..a2dc1a1 100644 --- a/service/simulator/java/jni/simulator_single_resource_jni.cpp +++ b/service/simulator/java/jni/simulator_single_resource_jni.cpp @@ -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) {