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>
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);
}
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)
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++)
{
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++)
{
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++)
{
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);
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);
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, 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;
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)
}
static void onPlatformInfoReceived(jobject listener, const std::string &hostUri,
- PlatformInfo &platformInfo)
+ PlatformInfo &platformInfo)
{
JNIEnv *env = GetEnv();
if (!env)
}
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)
}
static void onGetCallback(jobject listener, const std::string &uid, SimulatorResult result,
- const SimulatorResourceModel &representation)
+ const SimulatorResourceModel &representation)
{
JNIEnv *env = GetEnv();
if (!env)
}
static void onPutCallback(jobject listener, const std::string &uid, SimulatorResult result,
- const SimulatorResourceModel &representation)
+ const SimulatorResourceModel &representation)
{
JNIEnv *env = GetEnv();
if (!env)
}
static void onPostCallback(jobject listener, const std::string &uid, SimulatorResult result,
- const SimulatorResourceModel &representation)
+ const SimulatorResourceModel &representation)
{
JNIEnv *env = GetEnv();
if (!env)
}
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");
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);
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);
}
// 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);
}
};
const SimulatorResourceAttribute &attribute);
bool SimulatorResourceAttributeToCpp(JNIEnv *env, jobject jAttribute,
- SimulatorResourceAttribute &attribute);
+ SimulatorResourceAttribute &attribute);
jobject SimulatorResourceAttributesToJava(JNIEnv *env,
const std::map<std::string, SimulatorResourceAttribute> &attributes);
#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
// 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(
{
values.push_back(jIntArray[index]);
}
+ integerProperty->setValues(values);
env->ReleaseIntArrayElements(jValues, jIntArray, 0);
}
// 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(
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 =
{
values.push_back(jDoubleArray[index]);
}
+ doubleProperty->setValues(values);
env->ReleaseDoubleArrayElements(jValues, jDoubleArray, 0);
}
// 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(
jstring jValue = (jstring) env->GetObjectArrayElement(jValues, index);
values.push_back(JniString(env, jValue).get());
}
+ stringProperty->setValues(values);
}
}
#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);
JniString jniAttrName(env, jAttrName);
AutoUpdateType autoUpdateType = autoUpdateTypeToCpp(env, jType);
return singleResource->startAttributeUpdation(jniAttrName.get(), autoUpdateType,
- jInterval, callback);
+ jInterval, callback);
}
catch (InvalidArgsException &e)
{