From: Jay Sharma Date: Thu, 17 Sep 2015 12:15:33 +0000 (+0530) Subject: Updated Java SDK of RE layer X-Git-Tag: 1.2.0+RC1~1113 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=037388c9cdcc9998d5721d410710e29c4d384bcf;p=platform%2Fupstream%2Fiotivity.git Updated Java SDK of RE layer - Updated the RCSResourceAttributes class to support Nested Attributes. - Updated the JNI Layer. Change-Id: Ief1fe17a2d497a1167d4b6cc3bc727b0dfe62096 Signed-off-by: Jay Sharma Reviewed-on: https://gerrit.iotivity.org/gerrit/2639 Tested-by: jenkins-iotivity Reviewed-by: Rami Jung Reviewed-by: Madan Lanka --- diff --git a/service/resource-encapsulation/examples/android/REClient/src/com/re/sampleclient/ResourceClient.java b/service/resource-encapsulation/examples/android/REClient/src/com/re/sampleclient/ResourceClient.java index 888e458..88ba6c8 100644 --- a/service/resource-encapsulation/examples/android/REClient/src/com/re/sampleclient/ResourceClient.java +++ b/service/resource-encapsulation/examples/android/REClient/src/com/re/sampleclient/ResourceClient.java @@ -31,6 +31,7 @@ import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.ICacheU import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.CacheState; import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.ResourceState; import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject; +import org.iotivity.ResourceEncapsulation.common.AttriubtesGetValueTypes; import org.iotivity.ResourceEncapsulation.common.RCSException; import org.iotivity.ResourceEncapsulation.common.RCSResourceAttributes; @@ -489,7 +490,7 @@ public class ResourceClient { Log.d(LOG_TAG, "Printing Attributes"); try { - int temperature = attributes.getValueInt("Temperature"); + int temperature = attributes.getValue("Temperature", AttriubtesGetValueTypes.Integer); Log.i(LOG_TAG, "Temperature : " + temperature); logMessage = "Attributes : \n\nTemperature : " + temperature + "\n"; } catch (Exception e) { diff --git a/service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_jvm.h b/service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_jvm.h index 46a1d1d..52d3187 100644 --- a/service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_jvm.h +++ b/service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_jvm.h @@ -60,10 +60,17 @@ extern jclass g_cls_RCSRequest; extern jclass g_cls_RCSBundleInfo; extern jmethodID g_mid_Integer_ctor; +extern jmethodID g_mid_Integer_getInt; +extern jmethodID g_mid_Double_getDouble; +extern jmethodID g_mid_Boolean_getBoolean; extern jmethodID g_mid_Double_ctor; extern jmethodID g_mid_Boolean_ctor; extern jmethodID g_mid_LinkedList_ctor; extern jmethodID g_mid_LinkedList_add_object; +extern jmethodID g_mid_Vector_ctor; +extern jmethodID g_mid_Vector_size; +extern jmethodID g_mid_Vector_get; +extern jmethodID g_mid_Vector_add; extern jmethodID g_mid_Map_entrySet; extern jmethodID g_mid_MapEntry_getKey; extern jmethodID g_mid_MapEntry_getValue; @@ -74,6 +81,7 @@ extern jmethodID g_mid_HashMap_ctor; extern jmethodID g_mid_HashMap_put; extern jmethodID g_mid_RCSRemoteResourceObject_ctor; extern jmethodID g_mid_RCSRemoteResourceAttributesObject_ctor; +extern jmethodID g_mid_RCSRemoteResourceAttributesObject_ctor_bool; extern jmethodID g_mid_RCSException_ctor; extern jmethodID g_mid_RCSResourceObject_ctor; diff --git a/service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_utils.h b/service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_utils.h index 1af08e5..4e51f88 100644 --- a/service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_utils.h +++ b/service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_utils.h @@ -19,9 +19,8 @@ ******************************************************************/ /** - * @file jni_re_utils.h - * - * @brief This file contains the utility functions for JNI + * @file + * This file contains the utility functions for JNI */ #ifndef __JNI_RE_UTILS_H_ @@ -58,7 +57,6 @@ jobject convertStrVectorToJavaStrList(JNIEnv *env, std::vector vect jobject convertNativeResourceStateToJavaResourceState(ResourceState nativeResourceState, JNIEnv *env); - /** * @brief Convert Java AutoNotifyPolicy to Native AutoNotifyPolicy */ @@ -97,6 +95,142 @@ void convertJavaMapToParamsMap(JNIEnv *env, jobject hashMap, jobject convertStrListToJavaStrList(JNIEnv *env, std::list &list); /** + *@brief Convert java Integer vector to native Integer vector + */ +std::vector covertJavaIntVectorToNativeVector(JNIEnv *env, jobject javaVector); + +/** + *@brief Convert java vector of Vector of Integer to native vector + */ +std::vector> convertJavaVectorOfVectorOfIntToNativeVector(JNIEnv *env, + jobject javaVector); + +/** + *@brief Convert java vector of Vector of Vector of Integer to native vector + */ +std::vector>> convertJavaVectorOfVectorOfVectorOfIntToNativeVector( + JNIEnv *env, jobject javaVector); + +/** + *@brief Convert native Integer vector to Java Integer vector + */ +jobject convertNativeIntVectorToJavaVector(JNIEnv *env, std::vector &nativeVector); + +/** + *@brief Convert native Vector of Vector of Integer to Java vector + */ +jobject convertNativeVectorOfVectorOfIntToJavaVector(JNIEnv *env, + std::vector> &nativeVector); + +/** + *@brief Convert native Vector of Vector of Vector of Integer to Java vector + */ +jobject convertNativeVectorOfVectorOfVectorOfIntToJavaVector(JNIEnv *env, + std::vector>> &nativeVector); + +/** + *@brief Convert java Double vector to native vector + */ +std::vector covertJavaDoubleVectorToNativeVector(JNIEnv *env, jobject javaVector); + +/** + *@brief Convert java vector of Vector of Double to native vector + */ +std::vector> convertJavaVectorOfVectorOfDoubleToNativeVector(JNIEnv *env, + jobject javaVector); + +/** + *@brief Convert java vector of Vector of Vector of Double to native vector + */ +std::vector>> +convertJavaVectorOfVectorOfVectorOfDoubleToNativeVector(JNIEnv *env, jobject javaVector); + +/** + *@brief Convert native Double vector to jave vector + */ +jobject convertNativeDoubleVectorToJavaVector(JNIEnv *env, std::vector &nativeVector); + +/** + *@brief Convert native Vector of Vector of Double to Java vector + */ +jobject convertNativeVectorOfVectorOfDoubleToJavaVector(JNIEnv *env, + std::vector> &nativeVector); + +/** + *@brief Convert native Vector of Vector of Vector of Double to Java vector + */ +jobject convertNativeVectorOfVectorOfVectorOfDoubleToJavaVector(JNIEnv *env, + std::vector>> &nativeVector); + +/** + *@brief Convert java Boolean vector to native vector + */ +std::vector covertJavaBooleanVectorToNativeVector(JNIEnv *env, jobject javaVector); + +/** + *@brief Convert java vector of Vector of boolean to native vector + */ +std::vector> convertJavaVectorOfVectorOfBooleanToNativeVector(JNIEnv *env, + jobject javaVector); + +/** + *@brief Convert java vector of Vector of Vector of Boolean to native vector + */ +std::vector>> +convertJavaVectorOfVectorOfVectorOfBooleanToNativeVector(JNIEnv *env, jobject javaVector); + +/** + *@brief Convert native Bool vector to Java vector + */ +jobject convertNativeBooleanVectorToJavaVector(JNIEnv *env, std::vector &nativeVector); + +/** + *@brief Convert native Vector of Vector of Boolean to Java vector + */ +jobject convertNativeVectorOfVectorOfBooleanToJavaVector(JNIEnv *env, + std::vector> &nativeVector); + +/** + *@brief Convert native Vector of Vector of Vector of Boolean to Java vector + */ +jobject convertNativeVectorOfVectorOfVectorOfBooleanToJavaVector(JNIEnv *env, + std::vector>> &nativeVector); + +/** + *@brief Convert java String vector to native vector + */ +std::vector covertJavaStringVectorToNativeVector(JNIEnv *env, jobject javaVector); + +/** + *@brief Convert java vector of Vector of String to native vector + */ +std::vector> convertJavaVectorOfVectorOfStringToNativeVector(JNIEnv *env, + jobject javaVector); + +/** + *@brief Convert java vector of Vector of Vector of String to native vector + */ +std::vector>> +convertJavaVectorOfVectorOfVectorOfStringToNativeVector(JNIEnv *env, jobject javaVector); + +/** + *@brief Convert native String vector to Java vector + */ +jobject convertNativeStringVectorToJavaVector(JNIEnv *env, std::vector &nativeVector); + +/** + *@brief Convert native Vector of Vector of String to Java vector + */ +jobject convertNativeVectorOfVectorOfStringToJavaVector(JNIEnv *env, + std::vector> &nativeVector); + +/** + *@brief Convert native Vector of Vector of Vector of String to Java vector + */ +jobject convertNativeVectorOfVectorOfVectorOfStringToJavaVector(JNIEnv *env, + std::vector>> &nativeVector); + +/** * @brief Throw the RCS exception to the upper layer */ void throwRCSException(JNIEnv *env, std::string reason); diff --git a/service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_jvm.cpp b/service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_jvm.cpp index e53d9ab..d42cbc7 100644 --- a/service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_jvm.cpp +++ b/service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_jvm.cpp @@ -41,11 +41,18 @@ jclass g_cls_RCSRequest = NULL; jclass g_cls_RCSBundleInfo = NULL; jmethodID g_mid_Integer_ctor = NULL; +jmethodID g_mid_Integer_getInt = NULL; jmethodID g_mid_Double_ctor = NULL; +jmethodID g_mid_Double_getDouble = NULL; +jmethodID g_mid_Boolean_getBoolean = NULL; jmethodID g_mid_Boolean_ctor = NULL; jmethodID g_mid_LinkedList_ctor = NULL; jmethodID g_mid_Set_iterator = NULL; jmethodID g_mid_LinkedList_add_object = NULL; +jmethodID g_mid_Vector_ctor = NULL; +jmethodID g_mid_Vector_size = NULL; +jmethodID g_mid_Vector_get = NULL; +jmethodID g_mid_Vector_add = NULL; jmethodID g_mid_Map_entrySet = NULL; jmethodID g_mid_MapEntry_getKey = NULL; jmethodID g_mid_MapEntry_getValue = NULL; @@ -53,6 +60,7 @@ jmethodID g_mid_Iterator_hasNext = NULL; jmethodID g_mid_Iterator_next = NULL; jmethodID g_mid_RCSRemoteResourceObject_ctor = NULL; jmethodID g_mid_RCSRemoteResourceAttributesObject_ctor = NULL; +jmethodID g_mid_RCSRemoteResourceAttributesObject_ctor_bool = NULL; jmethodID g_mid_RCSException_ctor = NULL; jmethodID g_mid_RCSResourceObject_ctor = NULL; @@ -83,6 +91,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) g_mid_Integer_ctor = env->GetMethodID(g_cls_Integer, "", "(I)V"); if (!g_mid_Integer_ctor) return JNI_ERR; + g_mid_Integer_getInt = env->GetMethodID(g_cls_Integer, "intValue", "()I"); + if (!g_mid_Integer_getInt) return JNI_ERR; + //Double clazz = env->FindClass("java/lang/Double"); if (!clazz) return JNI_ERR; @@ -92,6 +103,10 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) g_mid_Double_ctor = env->GetMethodID(g_cls_Double, "", "(D)V"); if (!g_mid_Double_ctor) return JNI_ERR; + g_mid_Double_getDouble = env->GetMethodID(g_cls_Double, "doubleValue", "()D"); + if (!g_mid_Double_getDouble) return JNI_ERR; + + //Boolean clazz = env->FindClass("java/lang/Boolean"); if (!clazz) return JNI_ERR; @@ -101,6 +116,10 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) g_mid_Boolean_ctor = env->GetMethodID(g_cls_Boolean, "", "(Z)V"); if (!g_mid_Boolean_ctor) return JNI_ERR; + g_mid_Boolean_getBoolean = env->GetMethodID(g_cls_Boolean, "booleanValue", "()Z"); + if (!g_mid_Boolean_getBoolean) return JNI_ERR; + + //String clazz = env->FindClass("java/lang/String"); if (!clazz) return JNI_ERR; @@ -166,6 +185,18 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) g_cls_Vector = (jclass)env->NewGlobalRef(clazz); env->DeleteLocalRef(clazz); + g_mid_Vector_ctor = env->GetMethodID(g_cls_Vector, "", "()V"); + if (!g_mid_Vector_ctor) return JNI_ERR; + + g_mid_Vector_size = env->GetMethodID(g_cls_Vector, "size", "()I"); + if (!g_mid_Vector_size) return JNI_ERR; + + g_mid_Vector_get = env->GetMethodID(g_cls_Vector, "get", "(I)""Ljava/lang/Object;"); + if (!g_mid_Vector_get) return JNI_ERR; + + g_mid_Vector_add = env->GetMethodID(g_cls_Vector, "add", "(Ljava/lang/Object;)Z"); + if (!g_mid_Vector_add) return JNI_ERR; + //RCSRemoteResourceObject clazz = env->FindClass("org/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject"); if (!clazz) return JNI_ERR; @@ -197,6 +228,10 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) g_cls_RCSRemoteResourceAttributesObject, "", "(J)V"); if (!g_mid_RCSRemoteResourceAttributesObject_ctor) return JNI_ERR; + g_mid_RCSRemoteResourceAttributesObject_ctor_bool = env->GetMethodID( + g_cls_RCSRemoteResourceAttributesObject, "", "(JZ)V"); + if (!g_mid_RCSRemoteResourceAttributesObject_ctor_bool) return JNI_ERR; + //RCSException clazz = env->FindClass("org/iotivity/ResourceEncapsulation/common/RCSException"); if (!clazz) return JNI_ERR; @@ -251,6 +286,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) env->DeleteGlobalRef(g_cls_Boolean); env->DeleteGlobalRef(g_cls_String); env->DeleteGlobalRef(g_cls_LinkedList); + env->DeleteGlobalRef(g_cls_Vector); env->DeleteGlobalRef(g_cls_Iterator); env->DeleteGlobalRef(g_cls_RCSRemoteResourceObject); env->DeleteGlobalRef(g_cls_RCSRemoteResourceAttributesObject); diff --git a/service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_utils.cpp b/service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_utils.cpp index 95f8c61..fa2a6f6 100644 --- a/service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_utils.cpp +++ b/service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_utils.cpp @@ -18,6 +18,7 @@ * ******************************************************************/ #include "jni_re_utils.h" +#include "jni_re_resource_attributes.h" int covertResourceStateToInt(ResourceState state) { @@ -255,11 +256,8 @@ int convertSetRequestHandlerPolicyToInt(RCSResourceObject::SetRequestHandlerPoli void convertJavaMapToParamsMap(JNIEnv *env, jobject hashMap, std::map ¶ms) { - - LOGI("convertJavaMapToParamsMap Enter"); if (!hashMap) { - LOGI("convertJavaMapToParamsMap hashMap is NULL"); return; } @@ -267,7 +265,6 @@ void convertJavaMapToParamsMap(JNIEnv *env, jobject hashMap, jobject jIterator = env->CallObjectMethod(jEntrySet, g_mid_Set_iterator); if (!jEntrySet || !jIterator || env->ExceptionCheck()) { - LOGI("convertJavaMapToParamsMap !jEntrySet || !jIterator || env->ExceptionCheck()"); return; } @@ -280,7 +277,6 @@ void convertJavaMapToParamsMap(JNIEnv *env, jobject hashMap, jstring jValue = (jstring)env->CallObjectMethod(jEntry, g_mid_MapEntry_getValue); if (!jValue) return; - LOGI("convertJavaMapToParamsMap about to insert"); params.insert(std::make_pair(env->GetStringUTFChars(jKey, NULL), env->GetStringUTFChars(jValue, NULL))); @@ -305,4 +301,697 @@ jobject convertStrListToJavaStrList(JNIEnv *env, std::list &nativeL env->DeleteLocalRef(jStr); } return jList; +} + +std::vector covertJavaIntVectorToNativeVector(JNIEnv *env, jobject javaVector) +{ + std::vector vectorInt; + LOGI("covertJavaIntVectorToNativeVector"); + + jint jSize = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVector = jSize; + int nativeValue; + jint jIndex; + + for (int index = 0; index < sizeOfVector; index++) + { + jIndex = index; + jobject intValue = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex); + nativeValue = env->CallIntMethod( intValue, g_mid_Integer_getInt); + vectorInt.push_back(nativeValue); + } + return vectorInt; +} + +std::vector> convertJavaVectorOfVectorOfIntToNativeVector(JNIEnv *env, + jobject javaVector) +{ + std::vector> vectorInt; + LOGI("covertJavaIntVectorToNativeVector"); + + jint jSizeOne = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVectorOne = jSizeOne; + int nativeValue; + jint jIndex1; + jint jIndex2; + + for (int index1 = 0; index1 < sizeOfVectorOne; index1++) + { + jIndex1 = index1; + + jobject vectorTwoObj = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex1); + + jint jSizeTwo = env->CallIntMethod(vectorTwoObj, g_mid_Vector_size); + int sizeOfVectorTwo = jSizeTwo; + std::vector vectorTwo; + for (int index2 = 0; index2 < sizeOfVectorTwo; index2++) + { + jIndex2 = index2; + jobject intValue = env->CallObjectMethod(vectorTwoObj, g_mid_Vector_get, jIndex2); + nativeValue = env->CallIntMethod( intValue, g_mid_Integer_getInt); + vectorTwo.push_back(nativeValue); + } + vectorInt.push_back(vectorTwo); + } + return vectorInt; +} + +std::vector>> convertJavaVectorOfVectorOfVectorOfIntToNativeVector( + JNIEnv *env, jobject javaVector) +{ + std::vector>> vectorInt; + LOGI("convertJavaVectorOfVectorOfVectorOfIntToNativeVector"); + + jint jSizeOne = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVectorOne = jSizeOne; + int nativeValue; + jint jIndex1; + jint jIndex2; + jint jIndex3; + + for (int index1 = 0; index1 < sizeOfVectorOne; index1++) + { + jIndex1 = index1; + + jobject vectorTwoObj = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex1); + + jint jSizeTwo = env->CallIntMethod(vectorTwoObj, g_mid_Vector_size); + int sizeOfVectorTwo = jSizeTwo; + std::vector> vectorTwo; + for (int index2 = 0; index2 < sizeOfVectorTwo; index2++) + { + jIndex2 = index2; + + jobject vectorThreeObj = env->CallObjectMethod(vectorTwoObj, g_mid_Vector_get, jIndex2); + + jint jSizeThree = env->CallIntMethod(vectorThreeObj, g_mid_Vector_size); + int sizeOfVectorThree = jSizeThree; + std::vector vectorThree; + for (int index3 = 0; index3 < sizeOfVectorTwo; index3++) + { + jIndex3 = index3; + jobject intValue = env->CallObjectMethod(vectorThreeObj, g_mid_Vector_get, jIndex3); + nativeValue = env->CallIntMethod( intValue, g_mid_Integer_getInt); + vectorThree.push_back(nativeValue); + } + vectorTwo.push_back(vectorThree); + } + vectorInt.push_back(vectorTwo); + } + return vectorInt; +} + +jobject convertNativeIntVectorToJavaVector(JNIEnv *env, std::vector &nativeVector) +{ + LOGI("convertNativeIntVectorToJavaVector"); + jobject javaVector = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + if (!javaVector) return nullptr; + + for (std::vector::iterator it = nativeVector.begin(); it != nativeVector.end(); ++it) + { + jint jInt = (jint)(*it); + jobject value = env->NewObject(g_cls_Integer, g_mid_Integer_ctor, jInt); + env->CallBooleanMethod(javaVector, g_mid_Vector_add, value); + } + return javaVector; +} + +jobject convertNativeVectorOfVectorOfIntToJavaVector(JNIEnv *env, + std::vector> &nativeVector) +{ + LOGI("convertNativeVectorOfVectorOfIntToJavaVector"); + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + if (!javaVector1) return nullptr; + + std::vector>::iterator firstIt; + std::vector::iterator secondIt; + + jobject javaVector2 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + for (firstIt = nativeVector.begin(); firstIt != nativeVector.end(); firstIt++) + { + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (secondIt = firstIt->begin(); secondIt != firstIt->end(); secondIt++) + { + jint jInt = (jint)(*secondIt); + jobject value = env->NewObject(g_cls_Integer, g_mid_Integer_ctor, jInt); + env->CallBooleanMethod(javaVector1, g_mid_Vector_add, value); + } + env->CallBooleanMethod(javaVector2, g_mid_Vector_add, javaVector1); + } + return javaVector2; +} + +jobject convertNativeVectorOfVectorOfVectorOfIntToJavaVector(JNIEnv *env, + std::vector>> &nativeVector) +{ + + LOGI("convertNativeVectorOfVectorOfVectorOfIntToJavaVector"); + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + std::vector>>::iterator firstIt; + std::vector>::iterator secondIt; + std::vector::iterator thirdIt; + + jobject javaVector3 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + for (firstIt = nativeVector.begin(); firstIt != nativeVector.end(); firstIt++) + { + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (secondIt = firstIt->begin(); secondIt != firstIt->end(); secondIt++) + { + jobject javaVector2 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (thirdIt = secondIt->begin(); thirdIt != secondIt->end(); thirdIt++) + { + jint jInt = (jint)(*thirdIt); + jobject value = env->NewObject(g_cls_Integer, g_mid_Integer_ctor, jInt); + env->CallBooleanMethod(javaVector2, g_mid_Vector_add, value); + } + env->CallBooleanMethod(javaVector1, g_mid_Vector_add, javaVector2); + } + env->CallBooleanMethod(javaVector3, g_mid_Vector_add, javaVector1); + } + return javaVector3; +} + + +//double +std::vector covertJavaDoubleVectorToNativeVector(JNIEnv *env, jobject javaVector) +{ + std::vector vectorDouble; + LOGI("covertJavaDoubleVectorToNativeVector"); + + jint jSize = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVector = jSize; + double nativeValue; + jint jIndex; + + for (int index = 0; index < sizeOfVector; index++) + { + jIndex = index; + jobject doubleValue = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex); + nativeValue = env->CallDoubleMethod( doubleValue, g_mid_Double_getDouble); + + vectorDouble.push_back(nativeValue); + } + return vectorDouble; +} + +std::vector> convertJavaVectorOfVectorOfDoubleToNativeVector(JNIEnv *env, + jobject javaVector) +{ + + std::vector> vectorDouble; + LOGI("convertJavaVectorOfVectorOfDoubleToNativeVector"); + + jint jSizeOne = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVectorOne = jSizeOne; + double nativeValue; + jint jIndex1; + jint jIndex2; + + for (int index1 = 0; index1 < sizeOfVectorOne; index1++) + { + jIndex1 = index1; + + jobject vectorTwoObj = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex1); + + jint jSizeTwo = env->CallIntMethod(vectorTwoObj, g_mid_Vector_size); + int sizeOfVectorTwo = jSizeTwo; + std::vector vectorTwo; + for (int index2 = 0; index2 < sizeOfVectorTwo; index2++) + { + jIndex2 = index2; + jobject doubleValue = env->CallObjectMethod(vectorTwoObj, g_mid_Vector_get, jIndex2); + nativeValue = env->CallDoubleMethod( doubleValue, g_mid_Double_getDouble); + vectorTwo.push_back(nativeValue); + } + vectorDouble.push_back(vectorTwo); + } + return vectorDouble; +} + +std::vector>> +convertJavaVectorOfVectorOfVectorOfDoubleToNativeVector(JNIEnv *env, jobject javaVector) +{ + + std::vector>> vectorDouble; + LOGI("convertJavaVectorOfVectorOfVectorOfDoubleToNativeVector"); + + jint jSizeOne = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVectorOne = jSizeOne; + double nativeValue; + jint jIndex1; + jint jIndex2; + jint jIndex3; + + for (int index1 = 0; index1 < sizeOfVectorOne; index1++) + { + jIndex1 = index1; + + jobject vectorTwoObj = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex1); + + jint jSizeTwo = env->CallIntMethod(vectorTwoObj, g_mid_Vector_size); + int sizeOfVectorTwo = jSizeTwo; + std::vector> vectorTwo; + for (int index2 = 0; index2 < sizeOfVectorTwo; index2++) + { + jIndex2 = index2; + + jobject vectorThreeObj = env->CallObjectMethod(vectorTwoObj, g_mid_Vector_get, jIndex2); + + jint jSizeThree = env->CallIntMethod(vectorThreeObj, g_mid_Vector_size); + int sizeOfVectorThree = jSizeThree; + std::vector vectorThree; + for (int index3 = 0; index3 < sizeOfVectorTwo; index3++) + { + jIndex3 = index3; + + jobject doubleValue = env->CallObjectMethod(vectorThreeObj, g_mid_Vector_get, jIndex3); + nativeValue = env->CallDoubleMethod( doubleValue, g_mid_Double_getDouble); + + vectorThree.push_back(nativeValue); + } + vectorTwo.push_back(vectorThree); + } + vectorDouble.push_back(vectorTwo); + } + return vectorDouble; +} + +jobject convertNativeDoubleVectorToJavaVector(JNIEnv *env, std::vector &nativeVector) +{ + LOGI("convertNativeIntVectorToJavaVector"); + jobject javaVector = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + if (!javaVector) return nullptr; + + for (std::vector::iterator it = nativeVector.begin(); it != nativeVector.end(); ++it) + { + jdouble jDouble = (jdouble)(*it); + jobject value = env->NewObject(g_cls_Double, g_mid_Double_ctor, jDouble); + env->CallBooleanMethod(javaVector, g_mid_Vector_add, value); + } + return javaVector; +} + +jobject convertNativeVectorOfVectorOfDoubleToJavaVector(JNIEnv *env, + std::vector> &nativeVector) +{ + LOGI("convertNativeVectorOfVectorOfIntToJavaVector"); + + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + if (!javaVector1) return nullptr; + + std::vector>::iterator firstIt; + std::vector::iterator secondIt; + + jobject javaVector2 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + for (firstIt = nativeVector.begin(); firstIt != nativeVector.end(); firstIt++) + { + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (secondIt = firstIt->begin(); secondIt != firstIt->end(); secondIt++) + { + jdouble jDouble = (jdouble)(*secondIt); + jobject value = env->NewObject(g_cls_Double, g_mid_Double_ctor, jDouble); + env->CallBooleanMethod(javaVector1, g_mid_Vector_add, value); + } + env->CallBooleanMethod(javaVector2, g_mid_Vector_add, javaVector1); + } + return javaVector2; +} + +jobject convertNativeVectorOfVectorOfVectorOfDoubleToJavaVector(JNIEnv *env, + std::vector>> &nativeVector) +{ + LOGI("convertNativeVectorOfVectorOfVectorOfDoubleToJavaVector"); + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + std::vector>>::iterator firstIt; + std::vector>::iterator secondIt; + std::vector::iterator thirdIt; + + jobject javaVector3 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + for (firstIt = nativeVector.begin(); firstIt != nativeVector.end(); firstIt++) + { + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (secondIt = firstIt->begin(); secondIt != firstIt->end(); secondIt++) + { + jobject javaVector2 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (thirdIt = secondIt->begin(); thirdIt != secondIt->end(); thirdIt++) + { + jdouble jDouble = (jdouble)(*thirdIt); + jobject value = env->NewObject(g_cls_Double, g_mid_Double_ctor, jDouble); + env->CallBooleanMethod(javaVector2, g_mid_Vector_add, value); + } + env->CallBooleanMethod(javaVector1, g_mid_Vector_add, javaVector2); + } + env->CallBooleanMethod(javaVector3, g_mid_Vector_add, javaVector1); + } + return javaVector3; +} + +//booean +std::vector covertJavaBooleanVectorToNativeVector(JNIEnv *env, jobject javaVector) +{ + std::vector vectorBoolean; + LOGI("covertJavaBooleanVectorToNativeVector"); + + jint jSize = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVector = jSize; + bool nativeValue; + jint jIndex; + + for (int index = 0; index < sizeOfVector; index++) + { + jIndex = index; + jobject boolValue = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex); + nativeValue = env->CallBooleanMethod( boolValue, g_mid_Boolean_getBoolean); + vectorBoolean.push_back(nativeValue); + } + return vectorBoolean; +} + +std::vector> convertJavaVectorOfVectorOfBooleanToNativeVector(JNIEnv *env, + jobject javaVector) +{ + std::vector> vectorBoolean; + LOGI("convertJavaVectorOfVectorOfBooleanToNativeVector"); + + jint jSizeOne = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVectorOne = jSizeOne; + bool nativeValue; + jint jIndex1; + jint jIndex2; + + for (int index1 = 0; index1 < sizeOfVectorOne; index1++) + { + jIndex1 = index1; + + jobject vectorTwoObj = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex1); + + jint jSizeTwo = env->CallIntMethod(vectorTwoObj, g_mid_Vector_size); + int sizeOfVectorTwo = jSizeTwo; + std::vector vectorTwo; + for (int index2 = 0; index2 < sizeOfVectorTwo; index2++) + { + jIndex2 = index2; + jobject boolValue = env->CallObjectMethod(vectorTwoObj, g_mid_Vector_get, jIndex2); + nativeValue = env->CallBooleanMethod( boolValue, g_mid_Boolean_getBoolean); + vectorTwo.push_back(nativeValue); + } + vectorBoolean.push_back(vectorTwo); + } + return vectorBoolean; +} + +std::vector>> +convertJavaVectorOfVectorOfVectorOfBooleanToNativeVector(JNIEnv *env, jobject javaVector) +{ + std::vector>> vectorBoolean; + LOGI("convertJavaVectorOfVectorOfVectorOfDoubleToNativeVector"); + + jint jSizeOne = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVectorOne = jSizeOne; + bool nativeValue; + jint jIndex1; + jint jIndex2; + jint jIndex3; + + for (int index1 = 0; index1 < sizeOfVectorOne; index1++) + { + jIndex1 = index1; + + jobject vectorTwoObj = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex1); + + jint jSizeTwo = env->CallIntMethod(vectorTwoObj, g_mid_Vector_size); + int sizeOfVectorTwo = jSizeTwo; + std::vector> vectorTwo; + for (int index2 = 0; index2 < sizeOfVectorTwo; index2++) + { + jIndex2 = index2; + + jobject vectorThreeObj = env->CallObjectMethod(vectorTwoObj, g_mid_Vector_get, jIndex2); + + jint jSizeThree = env->CallIntMethod(vectorThreeObj, g_mid_Vector_size); + int sizeOfVectorThree = jSizeThree; + std::vector vectorThree; + for (int index3 = 0; index3 < sizeOfVectorTwo; index3++) + { + jIndex3 = index3; + + jobject boolValue = env->CallObjectMethod(vectorThreeObj, g_mid_Vector_get, jIndex3); + nativeValue = env->CallBooleanMethod( boolValue, g_mid_Boolean_getBoolean); + + vectorThree.push_back(nativeValue); + } + vectorTwo.push_back(vectorThree); + } + vectorBoolean.push_back(vectorTwo); + } + return vectorBoolean; +} + +jobject convertNativeBooleanVectorToJavaVector(JNIEnv *env, std::vector &nativeVector) +{ + LOGI("convertNativeBooleanVectorToJavaVector"); + + jobject javaVector = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + if (!javaVector) return nullptr; + + for (std::vector::iterator it = nativeVector.begin(); it != nativeVector.end(); ++it) + { + jboolean jBoolean = (jboolean)(*it); + jobject value = env->NewObject(g_cls_Boolean, g_mid_Boolean_ctor, jBoolean); + env->CallBooleanMethod(javaVector, g_mid_Vector_add, value); + } + return javaVector; +} + +jobject convertNativeVectorOfVectorOfBooleanToJavaVector(JNIEnv *env, + std::vector> &nativeVector) +{ + LOGI("convertNativeVectorOfVectorOfBooleanToJavaVector"); + + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + if (!javaVector1) return nullptr; + + std::vector>::iterator firstIt; + std::vector::iterator secondIt; + + jobject javaVector2 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + for (firstIt = nativeVector.begin(); firstIt != nativeVector.end(); firstIt++) + { + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (secondIt = firstIt->begin(); secondIt != firstIt->end(); secondIt++) + { + jboolean jBoolean = (jboolean)(*secondIt); + jobject value = env->NewObject(g_cls_Boolean, g_mid_Boolean_ctor, jBoolean); + env->CallBooleanMethod(javaVector1, g_mid_Vector_add, value); + } + env->CallBooleanMethod(javaVector2, g_mid_Vector_add, javaVector1); + } + return javaVector2; +} + +jobject convertNativeVectorOfVectorOfVectorOfBooleanToJavaVector(JNIEnv *env, + std::vector>> &nativeVector) +{ + LOGI("convertNativeVectorOfVectorOfVectorOfBooleanToJavaVector"); + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + std::vector>>::iterator firstIt; + std::vector>::iterator secondIt; + std::vector::iterator thirdIt; + + jobject javaVector3 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + for (firstIt = nativeVector.begin(); firstIt != nativeVector.end(); firstIt++) + { + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (secondIt = firstIt->begin(); secondIt != firstIt->end(); secondIt++) + { + jobject javaVector2 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (thirdIt = secondIt->begin(); thirdIt != secondIt->end(); thirdIt++) + { + jboolean jBoolean = (jboolean)(*thirdIt); + jobject value = env->NewObject(g_cls_Boolean, g_mid_Boolean_ctor, jBoolean); + env->CallBooleanMethod(javaVector2, g_mid_Vector_add, value); + } + env->CallBooleanMethod(javaVector1, g_mid_Vector_add, javaVector2); + } + env->CallBooleanMethod(javaVector3, g_mid_Vector_add, javaVector1); + } + return javaVector3; +} + +//String +std::vector covertJavaStringVectorToNativeVector(JNIEnv *env, jobject javaVector) +{ + std::vector vectorString; + LOGI("covertJavaBooleanVectorToNativeVector"); + + jint jSize = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVector = jSize; + std::string nativeValue; + jint jIndex; + + for (int index = 0; index < sizeOfVector; index++) + { + jIndex = index; + jstring StringValue = (jstring)env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex); + nativeValue = env->GetStringUTFChars(StringValue, NULL); + vectorString.push_back(nativeValue); + } + return vectorString; +} + +std::vector> convertJavaVectorOfVectorOfStringToNativeVector(JNIEnv *env, + jobject javaVector) +{ + std::vector> vectorString; + LOGI("convertJavaVectorOfVectorOfBooleanToNativeVector"); + + jint jSizeOne = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVectorOne = jSizeOne; + std::string nativeValue; + jint jIndex1; + jint jIndex2; + + for (int index1 = 0; index1 < sizeOfVectorOne; index1++) + { + jIndex1 = index1; + + jobject vectorTwoObj = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex1); + + jint jSizeTwo = env->CallIntMethod(vectorTwoObj, g_mid_Vector_size); + int sizeOfVectorTwo = jSizeTwo; + std::vector vectorTwo; + for (int index2 = 0; index2 < sizeOfVectorTwo; index2++) + { + jIndex2 = index2; + jstring StringValue = (jstring)env->CallObjectMethod(vectorTwoObj, g_mid_Vector_get, jIndex2); + nativeValue = env->GetStringUTFChars(StringValue, NULL); + vectorTwo.push_back(nativeValue); + } + vectorString.push_back(vectorTwo); + } + return vectorString; +} + +std::vector>> +convertJavaVectorOfVectorOfVectorOfStringToNativeVector(JNIEnv *env, jobject javaVector) +{ + std::vector>> vectorString; + LOGI("convertJavaVectorOfVectorOfVectorOfDoubleToNativeVector"); + + jint jSizeOne = env->CallIntMethod(javaVector, g_mid_Vector_size); + int sizeOfVectorOne = jSizeOne; + std::string nativeValue; + jint jIndex1; + jint jIndex2; + jint jIndex3; + + for (int index1 = 0; index1 < sizeOfVectorOne; index1++) + { + jIndex1 = index1; + jobject vectorTwoObj = env->CallObjectMethod(javaVector, g_mid_Vector_get, jIndex1); + jint jSizeTwo = env->CallIntMethod(vectorTwoObj, g_mid_Vector_size); + int sizeOfVectorTwo = jSizeTwo; + std::vector> vectorTwo; + for (int index2 = 0; index2 < sizeOfVectorTwo; index2++) + { + jIndex2 = index2; + + jobject vectorThreeObj = env->CallObjectMethod(vectorTwoObj, g_mid_Vector_get, jIndex2); + + jint jSizeThree = env->CallIntMethod(vectorThreeObj, g_mid_Vector_size); + int sizeOfVectorThree = jSizeThree; + std::vector vectorThree; + for (int index3 = 0; index3 < sizeOfVectorTwo; index3++) + { + jIndex3 = index3; + + jstring StringValue = (jstring)env->CallObjectMethod(vectorThreeObj, g_mid_Vector_get, jIndex3); + nativeValue = env->GetStringUTFChars(StringValue, NULL); + + vectorThree.push_back(nativeValue); + } + vectorTwo.push_back(vectorThree); + } + vectorString.push_back(vectorTwo); + } + return vectorString; +} + +jobject convertNativeStringVectorToJavaVector(JNIEnv *env, std::vector &nativeVector) +{ + LOGI("convertNativeStringVectorToJavaVector"); + + jobject javaVector = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + if (!javaVector) return nullptr; + + for (std::vector::iterator it = nativeVector.begin(); it != nativeVector.end(); ++it) + { + env->CallBooleanMethod(javaVector, g_mid_Vector_add, env -> NewStringUTF((*it).c_str())); + } + return javaVector; +} + +jobject convertNativeVectorOfVectorOfStringToJavaVector(JNIEnv *env, + std::vector> &nativeVector) +{ + LOGI("convertNativeVectorOfVectorOfBooleanToJavaVector"); + + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + if (!javaVector1) return nullptr; + + std::vector>::iterator firstIt; + std::vector::iterator secondIt; + + jobject javaVector2 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + for (firstIt = nativeVector.begin(); firstIt != nativeVector.end(); firstIt++) + { + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (secondIt = firstIt->begin(); secondIt != firstIt->end(); secondIt++) + { + env->CallBooleanMethod(javaVector1, g_mid_Vector_add, env -> NewStringUTF((*secondIt).c_str())); + } + env->CallBooleanMethod(javaVector2, g_mid_Vector_add, javaVector1); + } + return javaVector2; +} + +jobject convertNativeVectorOfVectorOfVectorOfStringToJavaVector(JNIEnv *env, + std::vector>> &nativeVector) +{ + LOGI("convertNativeVectorOfVectorOfVectorOfStringToJavaVector"); + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + std::vector>>::iterator firstIt; + std::vector>::iterator secondIt; + std::vector::iterator thirdIt; + + jobject javaVector3 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + + for (firstIt = nativeVector.begin(); firstIt != nativeVector.end(); firstIt++) + { + jobject javaVector1 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (secondIt = firstIt->begin(); secondIt != firstIt->end(); secondIt++) + { + jobject javaVector2 = env->NewObject(g_cls_Vector, g_mid_Vector_ctor); + for (thirdIt = secondIt->begin(); thirdIt != secondIt->end(); thirdIt++) + { + env->CallBooleanMethod(javaVector2, g_mid_Vector_add, env -> NewStringUTF((*thirdIt).c_str())); + } + env->CallBooleanMethod(javaVector1, g_mid_Vector_add, javaVector2); + } + env->CallBooleanMethod(javaVector3, g_mid_Vector_add, javaVector1); + } + return javaVector3; } \ No newline at end of file diff --git a/service/resource-encapsulation/sdk/java/jni/re/include/jni_re_resource_attributes.h b/service/resource-encapsulation/sdk/java/jni/re/include/jni_re_resource_attributes.h index 7e32759..136fdf8 100644 --- a/service/resource-encapsulation/sdk/java/jni/re/include/jni_re_resource_attributes.h +++ b/service/resource-encapsulation/sdk/java/jni/re/include/jni_re_resource_attributes.h @@ -18,10 +18,9 @@ * ******************************************************************/ -/** @file jni_re_resource_attributes.h - * - * @brief This file contains the declaration of Resource Attribute APIs - * for JNI implementation +/** @file + * This file contains the declaration of Resource Attribute APIs + * for JNI implementation */ #ifndef __JNI_RE_RCS_RESOURCE_ATTRIBUTES_H_ @@ -40,22 +39,22 @@ struct NullType {}; /** - * @class JniResourceAttributes - * @brief This class provides the API for getting the RCSResourceAttribute pointer - * + * @class + * This class provides the API for getting the RCSResourceAttribute pointer */ class JniResourceAttributes { public: + /** - * @brief Get the ResourceAttibute pointer - * internally get the native handle by calling REGetHandle + * Get the ResourceAttibute pointer + * internally get the native handle by calling REGetHandle */ static RCSResourceAttributes *getResourceAttributePtr(JNIEnv *env, jobject thiz); }; /** - * @brief Utility structure for jobject conversion + * Utility structure for jobject conversion */ struct JObjectConverter : boost::static_visitor < jobject > { @@ -100,69 +99,222 @@ extern "C" { #endif /** - * API for getting attribute value corresponding the requested Key + * API for getting attribute value corresponding to requested Key * * @param key - Attribute key + * @param dataType - dataType for the value. + * + * @return value of attribute * + * @throws RCSException */ JNIEXPORT jobject JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeGetValueN -(JNIEnv *env, jobject interfaceObject, jstring key); +(JNIEnv *env, jobject interfaceObject, jstring key, jint dataType); /** * API for setting integer value for attribute * * @param key - Attribute key * @param value - Attribute value - * */ JNIEXPORT void JNICALL -Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueInteger +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueInt (JNIEnv *env, jobject interfaceObject, jstring key, jint value); /** - * API for setting Double value for attribute + * API for setting Vector of integer as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfInt +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting vector of vector of integer as attribute value * * @param key - Attribute key * @param value - Attribute value * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfInt +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting vector of vector of vector of integer as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfInt +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting double as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty */ JNIEXPORT void JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueDouble (JNIEnv *env, jobject interfaceObject, jstring key, jdouble value); /** - * API for setting Boolean value for attribute + * API for setting Vector of double as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfDouble +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting Vector of Vector of double as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfDouble +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting Vector of Vector of Vector of double as attribute value * * @param key - Attribute key * @param value - Attribute value * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfDouble +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + + +/** + * API for setting boolean as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty */ JNIEXPORT void JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueBoolean (JNIEnv *env, jobject interfaceObject, jstring key, jboolean value); /** - * API for setting String value for attribute + * API for setting vector of boolean as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfBoolean +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting vector of vector of boolean as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfBoolean +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting vector of vector of vector of boolean as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfBoolean +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting String as attribute value * - * @param Key - Attribute key + * @param key - Attribute key * @param value - Attribute value * + * @throws RCSException - If Key is empty */ JNIEXPORT void JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueString (JNIEnv *env, jobject interfaceObject, jstring key, jstring value); /** - * API for setting IntegerArray for attribute + * API for setting Vector of String as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfString +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting Vector of Vector of String as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfString +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting Vector of Vector of Vector of String as attribute value * * @param key - Attribute key * @param value - Attribute value * + * @throws RCSException - If Key is empty */ JNIEXPORT void JNICALL -Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueIntegerArray -(JNIEnv *env, jobject interfaceObject, jstring key, jintArray value); +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfString +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + +/** + * API for setting RCSResourceAttribute as attribute value + * + * @param key - Attribute key + * @param value - Attribute value + * + * @throws RCSException - If Key is empty + */ +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueAttributes +(JNIEnv *env, jobject interfaceObject, jstring key, jobject value); + /** * API for checking whether attribute is empty or not @@ -211,13 +363,13 @@ Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeHasAt (JNIEnv *env, jobject interfaceObject, jstring key); /** - * @brief API for creating a new RCSResourceAttributes object and setting of Native handle + * API for creating a new RCSResourceAttributes object and setting of Native handle */ JNIEXPORT void JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_create (JNIEnv *env, jobject interfaceObject); /** - * @brief API for deleting the RCSResourceAttributes object + * API for deleting the RCSResourceAttributes object */ JNIEXPORT void JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_dispose (JNIEnv *env, jobject interfaceObject, jboolean jNeedsDelete); diff --git a/service/resource-encapsulation/sdk/java/jni/re/src/jni_re_resource_attributes.cpp b/service/resource-encapsulation/sdk/java/jni/re/src/jni_re_resource_attributes.cpp index f4b6e95..b26eaf3 100644 --- a/service/resource-encapsulation/sdk/java/jni/re/src/jni_re_resource_attributes.cpp +++ b/service/resource-encapsulation/sdk/java/jni/re/src/jni_re_resource_attributes.cpp @@ -21,6 +21,8 @@ #include "jni_re_resource_attributes.h" #include "jni_re_jvm.h" +using namespace std; + RCSResourceAttributes *JniResourceAttributes::getResourceAttributePtr(JNIEnv *env, jobject interfaceObject) { @@ -38,9 +40,9 @@ RCSResourceAttributes *JniResourceAttributes::getResourceAttributePtr(JNIEnv *en JNIEXPORT jobject JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeGetValueN -(JNIEnv *env, jobject interfaceObject, jstring jKey) +(JNIEnv *env, jobject interfaceObject, jstring jKey, jint dataType) { - LOGD("RCSResourceAttributes_getValueN"); + LOGD("RCSResourceAttributes_nativeGetValueN"); if (!jKey) { throwRCSException(env, "attributeKey cannot be null"); @@ -51,52 +53,304 @@ Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeGetVa if (!rep) return nullptr; std::string key = env->GetStringUTFChars(jKey, NULL); - - if (! rep->contains(key)) return nullptr; - - RCSResourceAttributes::Value attrValue = rep->at(key); - RCSResourceAttributes::TypeId typeId = attrValue.getType().getId(); - - if (typeId == RCSResourceAttributes::TypeId::INT) + if (!(rep->contains(key))) { - int val = attrValue.get(); - jobject jobj = env->NewObject( - g_cls_Integer, - g_mid_Integer_ctor, - static_cast(val)); - return jobj; + throwRCSException(env, "Key not Found"); } - else if (typeId == RCSResourceAttributes::TypeId::DOUBLE) + else { - double val = attrValue.get(); - jobject jobj = env->NewObject( - g_cls_Double, - g_mid_Double_ctor, - static_cast(val)); - return jobj; + RCSResourceAttributes::Value attrValue = rep->at(key); + jobject jobj; + + if (0 == dataType) + { + LOGD("nativeGetValueN : integer"); + try + { + int val = attrValue.get(); + jobj = env->NewObject(g_cls_Integer, g_mid_Integer_ctor, static_cast(val)); + return jobj; + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (1 == dataType) + { + LOGD("nativeGetValueN : Vector of Integer"); + try + { + std::vector vectors = attrValue.get>(); + return convertNativeIntVectorToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (2 == dataType) + { + LOGD("nativeGetValueN : Vector of Vector of Integer"); + try + { + std::vector> vectors = attrValue.get>>(); + return convertNativeVectorOfVectorOfIntToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (3 == dataType) + { + LOGD("nativeGetValueN : Vector of Vector of vector Integer"); + try + { + std::vector>> vectors = + attrValue.get>>>(); + return convertNativeVectorOfVectorOfVectorOfIntToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (4 == dataType) + { + LOGD("nativeGetValueN : Double"); + try + { + double val = attrValue.get(); + jobj = env->NewObject(g_cls_Double, g_mid_Double_ctor, static_cast(val)); + return jobj; + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (5 == dataType) + { + LOGD("nativeGetValueN : Vector of Double"); + try + { + std::vector vectors = attrValue.get>(); + return convertNativeDoubleVectorToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (6 == dataType) + { + LOGD("nativeGetValueN : Vector of Vector of Double"); + try + { + std::vector> vectors = attrValue.get>>(); + return convertNativeVectorOfVectorOfDoubleToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (7 == dataType) + { + LOGD("nativeGetValueN : Vector of Vector of vector Double"); + try + { + std::vector>> vectors = + attrValue.get>>>(); + return convertNativeVectorOfVectorOfVectorOfDoubleToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (8 == dataType) + { + LOGD("nativeGetValueN : Boolean"); + try + { + bool val = attrValue.get(); + jobj = env->NewObject(g_cls_Boolean, g_mid_Boolean_ctor, static_cast(val)); + return jobj; + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (9 == dataType) + { + LOGD("nativeGetValueN : Vector of Boolean"); + try + { + std::vector vectors = attrValue.get>(); + return convertNativeBooleanVectorToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (10 == dataType) + { + LOGD("nativeGetValueN : Vector of Vector of Boolean"); + try + { + std::vector> vectors = attrValue.get>>(); + return convertNativeVectorOfVectorOfBooleanToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (11 == dataType) + { + LOGD("nativeGetValueN : Vector of Vector of Vector of Boolean"); + try + { + std::vector>> vectors = + attrValue.get>>>(); + return convertNativeVectorOfVectorOfVectorOfBooleanToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (12 == dataType) + { + LOGD("nativeGetValueN : String"); + try + { + std::string val = attrValue.get(); + jstring jstr = env->NewStringUTF(val.c_str()); + return static_cast(jstr); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (13 == dataType) + { + LOGD("nativeGetValueN : Vector of String"); + try + { + std::vector vectors = attrValue.get>(); + return convertNativeStringVectorToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (14 == dataType) + { + LOGD("nativeGetValueN : Vector of Vector of String"); + try + { + std::vector> vectors = + attrValue.get>>(); + return convertNativeVectorOfVectorOfStringToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (15 == dataType) + { + LOGD("nativeGetValueN : Vector of Vector of Vector of String"); + try + { + std::vector>> vectors = + attrValue.get>>>(); + return convertNativeVectorOfVectorOfVectorOfStringToJavaVector(env, vectors); + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } + else if (16 == dataType) + { + LOGD("nativeGetValueN : RCSResourceAttribute"); + try + { + RCSResourceAttributes values = attrValue.get(); + RCSResourceAttributes *rep = new RCSResourceAttributes(values); + jlong handle = reinterpret_cast(rep); + jobject jRepresentation = env->NewObject(g_cls_RCSRemoteResourceAttributesObject, + g_mid_RCSRemoteResourceAttributesObject_ctor_bool, + handle, true); + if (!jRepresentation) + { + delete rep; + } + return jRepresentation; + } + catch (std::exception e) + { + throwRCSException(env, e.what()); + } + } } - else if (typeId == RCSResourceAttributes::TypeId::BOOL) +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueInt +(JNIEnv *env, jobject interfaceObject, jstring jKey, jint jValue) +{ + LOGD("RCSResourceAttributes_setValueInteger"); + if (!jKey) { - bool val = attrValue.get(); - jobject jobj = env->NewObject( - g_cls_Boolean, - g_mid_Boolean_ctor, - static_cast(val)); - return jobj; + throwRCSException(env, "key cannot be null"); + return; } - else if (typeId == RCSResourceAttributes::TypeId::STRING) + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + + RCSResourceAttributes setAttribute; + setAttribute[key] = static_cast(jValue); + *rep = setAttribute; +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfInt +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject vectorOfInt) +{ + LOGD("RCSResourceAttributes_nativeSetValueVectorOfInt"); + if (!jKey) { - std::string val = attrValue.get(); - jstring jstr = env->NewStringUTF(val.c_str()); - return static_cast(jstr); + throwRCSException(env, "key cannot be null"); + return; } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector nativeVector = covertJavaIntVectorToNativeVector(env, vectorOfInt); + setAttribute[key] = nativeVector; + *rep = setAttribute; } JNIEXPORT void JNICALL -Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueInteger -(JNIEnv *env, jobject interfaceObject, jstring jKey, jint jValue) +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfInt +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject vectorOfVectorOfInt) { - LOGD("RCSResourceAttributes_setValueInteger"); + LOGD("RCSResourceAttributes_nativeSetValueVectorOfVectorOfInt"); if (!jKey) { throwRCSException(env, "key cannot be null"); @@ -107,12 +361,37 @@ Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetVa if (!rep) return; std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector> nativeVector = convertJavaVectorOfVectorOfIntToNativeVector(env, + vectorOfVectorOfInt); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfInt +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + LOGD("RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfInt"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + std::string key = env->GetStringUTFChars(jKey, NULL); RCSResourceAttributes setAttribute; - setAttribute[key] = static_cast(jValue); + std::vector>> nativeVector = + convertJavaVectorOfVectorOfVectorOfIntToNativeVector(env, value); + setAttribute[key] = nativeVector; *rep = setAttribute; } + JNIEXPORT void JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueDouble (JNIEnv *env, jobject interfaceObject, jstring jKey, jdouble jValue) @@ -134,6 +413,75 @@ Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetVa *rep = setAttribute; } + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfDouble +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + LOGD("RCSResourceAttributes_nativeSetValueVectorOfDouble"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector nativeVector = covertJavaDoubleVectorToNativeVector(env, value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfDouble +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + + LOGD("RCSResourceAttributes_nativeSetValueVectorOfVectorOfDouble"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector> nativeVector = convertJavaVectorOfVectorOfDoubleToNativeVector( + env, value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfDouble +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + + LOGD("RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfDouble"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector>> nativeVector = + convertJavaVectorOfVectorOfVectorOfDoubleToNativeVector(env, value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + + JNIEXPORT void JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueBoolean (JNIEnv *env, jobject interfaceObject, jstring jKey, jboolean jValue) @@ -156,10 +504,75 @@ Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetVa } JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfBoolean +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + LOGD("RCSResourceAttributes_nativeSetValueVectorOfBoolean"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector nativeVector = covertJavaBooleanVectorToNativeVector(env, value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfBoolean +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + LOGD("RCSResourceAttributes_nativeSetValueVectorOfVectorOfBoolean"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector> nativeVector = convertJavaVectorOfVectorOfBooleanToNativeVector(env, + value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfBoolean +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + LOGD("RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfBoolean"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector>> nativeVector = + convertJavaVectorOfVectorOfVectorOfBooleanToNativeVector(env, value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + +JNIEXPORT void JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueString (JNIEnv *env, jobject interfaceObject, jstring jKey, jstring jValue) { - LOGD("RCSResourceAttributes_setValueStringN"); + LOGD("RCSResourceAttributes_setValueString"); if (!jKey) { throwRCSException(env, "key cannot be null"); @@ -178,31 +591,92 @@ Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetVa } JNIEXPORT void JNICALL -Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueIntegerArray -(JNIEnv *env, jobject interfaceObject, jstring jKey, jintArray jValue) +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfString +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + LOGD("RCSResourceAttributes_nativeSetValueVectorOfString"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector nativeVector = covertJavaStringVectorToNativeVector(env, value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfString +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) +{ + LOGD("RCSResourceAttributes_nativeSetValueVectorOfVectorOfString"); + if (!jKey) + { + throwRCSException(env, "key cannot be null"); + return; + } + + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; + + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector> nativeVector = + convertJavaVectorOfVectorOfStringToNativeVector(env, value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfString +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject value) { - LOGD("RCSResourceAttributes_setValueIntegerArray"); + LOGD("RCSResourceAttributes_nativeSetValueVectorOfVectorOfVectorOfString"); if (!jKey) { throwRCSException(env, "key cannot be null"); return; } - const jsize len = env->GetArrayLength(jValue); - jint *ints = env->GetIntArrayElements(jValue, NULL); + RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); + if (!rep) return; - std::vector value; - for (jsize i = 0; i < len; ++i) + std::string key = env->GetStringUTFChars(jKey, NULL); + RCSResourceAttributes setAttribute; + std::vector>> nativeVector = + convertJavaVectorOfVectorOfVectorOfStringToNativeVector(env, value); + setAttribute[key] = nativeVector; + *rep = setAttribute; +} + +JNIEXPORT void JNICALL +Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueAttributes +(JNIEnv *env, jobject interfaceObject, jstring jKey, jobject jValue) +{ + + LOGD("RCSResourceAttributes_nativeSetValueAttributes"); + if (!jKey) { - value.push_back(static_cast(ints[i])); + throwRCSException(env, "key cannot be null"); + return; } - env->ReleaseIntArrayElements(jValue, ints, JNI_ABORT); RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); if (!rep) return; std::string key = env->GetStringUTFChars(jKey, NULL); RCSResourceAttributes setAttribute; + RCSResourceAttributes *value = JniResourceAttributes::getResourceAttributePtr(env, jValue); + if (!value) return; + + setAttribute[key] = *value; + *rep = setAttribute; } JNIEXPORT jboolean JNICALL @@ -220,7 +694,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSize (JNIEnv *env, jobject interfaceObject) { - LOGD("RCSResourceAttributes_size"); + LOGD("RCSResourceAttributes_nativeSize"); RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); if (!rep) return -1; @@ -231,7 +705,7 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeRemove (JNIEnv *env, jobject interfaceObject, jstring jAttributeKey) { - LOGD("RCSResourceAttributes_remove"); + LOGD("RCSResourceAttributes_nativeRemove"); if (!jAttributeKey) { throwRCSException(env, "attributeKey cannot be null"); @@ -249,7 +723,7 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeHasAttribute (JNIEnv *env, jobject interfaceObject, jstring jstr) { - LOGD("RCSResourceAttributes_hasAttribute"); + LOGD("RCSResourceAttributes_nativeHasAttribute"); if (!jstr) { throwRCSException(env, "attributeKey cannot be null"); diff --git a/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/common/AttriubtesGetValueTypes.java b/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/common/AttriubtesGetValueTypes.java new file mode 100644 index 0000000..2c88698 --- /dev/null +++ b/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/common/AttriubtesGetValueTypes.java @@ -0,0 +1,40 @@ +/****************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +/** + * @file + * This file provides AttriubtesGetValueTypes Enum. + * It is passed as second parameter to get the value of the + * RCSResourceArributes. + */ + +package org.iotivity.ResourceEncapsulation.common; + +public enum AttriubtesGetValueTypes { + + Integer, VectorOfInteger, VectorOfVectorOfInteger, VectorOfVectorOfVectorOfInteger, + + Double, VectorOfDouble, VectorOfVectorOfDouble, VectorOfVectorOfVectorOfDouble, + + Boolean, VectorOfBoolean, VectorOfVectorOfBoolean, VectorOfVectorOfVectorOfBoolean, + + String, VectorOfString, VectorOfVectorOfString, VectorOfVectorOfVectorOfString, + + RCSRemoteAtttributes +} diff --git a/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/common/RCSResourceAttributes.java b/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/common/RCSResourceAttributes.java index f00943d..d3fd7e6 100644 --- a/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/common/RCSResourceAttributes.java +++ b/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/common/RCSResourceAttributes.java @@ -24,6 +24,8 @@ package org.iotivity.ResourceEncapsulation.common; +import java.util.Vector; + import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager; import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject; import org.iotivity.ResourceEncapsulation.server.RCSResourceObject; @@ -31,8 +33,8 @@ import org.iotivity.ResourceEncapsulation.server.RCSResourceObject; /** * RCSResourceAttributes represents the attributes for a resource. * - * An attribute value can be one of various types : integer, double, boolean, - * String. + * An attribute value can be one of types specified in enum + * "AttriubtesGetValueTypes" * *

* If developer on client side wants to get the RCSResourceAttributes for the @@ -44,7 +46,7 @@ import org.iotivity.ResourceEncapsulation.server.RCSResourceObject; * steps: Call the getAttributes() API of RCSResourceObject class. * * {@link RCSDiscoveryManager} {@link RCSRemoteResourceObject} - * {@link RCSResourceObject} + * {@link RCSResourceObject} {@link AttriubtesGetValueTypes} */ public class RCSResourceAttributes { @@ -52,16 +54,55 @@ public class RCSResourceAttributes { private boolean m_nativeNeedsDelete; // native methods - private native Object nativeGetValueN(String key); + private native Object nativeGetValueN(String key, int type); + + private native void nativeSetValueInt(String key, int value); + + private native void nativeSetValueVectorOfInt(String key, + Vector values); - private native void nativeSetValueInteger(String key, int value); + private native void nativeSetValueVectorOfVectorOfInt(String key, + Vector> values); + + private native void nativeSetValueVectorOfVectorOfVectorOfInt(String key, + Vector>> values); private native void nativeSetValueDouble(String key, double value); + private native void nativeSetValueVectorOfDouble(String key, + Vector values); + + private native void nativeSetValueVectorOfVectorOfDouble(String key, + Vector> values); + + private native void nativeSetValueVectorOfVectorOfVectorOfDouble( + String key, Vector>> values); + private native void nativeSetValueBoolean(String key, boolean value); + private native void nativeSetValueVectorOfBoolean(String key, + Vector values); + + private native void nativeSetValueVectorOfVectorOfBoolean(String key, + Vector> values); + + private native void nativeSetValueVectorOfVectorOfVectorOfBoolean( + String key, Vector>> values); + private native void nativeSetValueString(String key, String value); + private native void nativeSetValueVectorOfString(String key, + Vector values); + + private native void nativeSetValueVectorOfVectorOfString(String key, + Vector> values); + + private native void nativeSetValueVectorOfVectorOfVectorOfString( + String key, Vector>> values); + + private native void nativeSetValueAttributes(String key, + RCSResourceAttributes value); + private native boolean nativeIsEmpty(); private native int nativeSize(); @@ -97,117 +138,188 @@ public class RCSResourceAttributes { this.m_nativeNeedsDelete = nativeNeedsDelete; } - private T getValue(String key) throws RCSException { - Object obj = this.nativeGetValueN(key); + /** + * Get the Resource Attribute value. + * + * @param key + * Key for which value is requested + * + * @param type + * AttriubtesGetValueTypes + * + * @return Value of the attribute. + * + * @throws RCSException + * In case of bad Request + * + * {@link AttriubtesGetValueTypes} + */ + public T getValue(String key, AttriubtesGetValueTypes type) + throws RCSException { + Object obj = this.nativeGetValueN(key, type.ordinal()); T t = (T) obj; return t; } /** - * get attribute value as an integer + * Set Integer as Attribute value. * * @param key - * - Key of the element. + * Key of the element to be added. * - * @return int - integer value of key provided. + * @param value + * integer value to be set. + * + * @throws RCSException + * In case of bad Request */ - public int getValueInt(String key) { - Integer value = 0; + public void setValueInt(String key, int value) throws RCSException { try { - value = this.getValue(key); - } catch (RCSException e) { + this.nativeSetValueInt(key, value); + } catch (Exception e) { e.printStackTrace(); } - return value; } /** - * get attribute value as a double + * Set Vector of Integer as Attribute Value. * * @param key - * - Key of the element. + * Key of the element to be added. + * + * @param values + * Vector of integer to be set. * - * @return boolean - boolean value of key provided. + * @throws RCSException + * In case of bad Request */ - public double getValueDouble(String key) { - double value = 0; + public void setValueVectorOfInt(String key, Vector values) { try { - value = this.getValue(key); - } catch (RCSException e) { + this.nativeSetValueVectorOfInt(key, values); + } catch (Exception e) { e.printStackTrace(); } - return value; } /** - * get attribute value as a boolean + * Set Vector of Vector of Integer as Attribute Value. * * @param key - * - Key of the element. + * Key of the element to be added. * - * @return boolean - boolean value of key provided. + * @param values + * Vector of Vector of integer to be set. + * + * @throws RCSException + * In case of bad Request */ - public boolean getValueBool(String key) { - Boolean value = false; + public void setValueVectorOfVectorInt(String key, + Vector> values) { try { - value = this.getValue(key); - } catch (RCSException e) { + this.nativeSetValueVectorOfVectorOfInt(key, values); + } catch (Exception e) { e.printStackTrace(); } - return value; } /** - * get attribute value as a string + * Set Vector Vector of Vector of Integer as Attribute Value. * * @param key - * - Key of the element. + * Key of the element to be added. * - * @return String - String value of key provided. + * @param values + * Vector of Vector of Vector of integer to be set. + * + * @throws RCSException + * In case of bad Request */ - public String getValueString(String key) { - String value = ""; + public void setValueVectorOfVectorOfVectorInt(String key, + Vector>> values) { try { - value = this.getValue(key); - } catch (RCSException e) { + this.nativeSetValueVectorOfVectorOfVectorOfInt(key, values); + } catch (Exception e) { e.printStackTrace(); } - return value; } /** - * set an integer type attribute value. + * set a double attribute value. * * @param key - * - Key of the element to be added. + * Key of the element to be added. * * @param value - * - integer value of key to be set. + * double value of key to be set. * * @throws RCSException + * In case of bad Request */ - public void setValueInt(String key, int value) throws RCSException { + public void setValueDouble(String key, double value) throws RCSException { + try { + this.nativeSetValueDouble(key, value); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Set Vector of double as Attribute Value. + * + * @param key + * Key of the element to be added. + * + * @param values + * Vector of double value of key to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueVectorOfDouble(String key, Vector values) { try { - this.nativeSetValueInteger(key, value); + this.nativeSetValueVectorOfDouble(key, values); } catch (Exception e) { e.printStackTrace(); } } /** - * set a double attribute value. + * Set Vector of Vector of double as Attribute Value. * * @param key - * - Key of the element to be added. + * Key of the element to be added. * - * @param value - * - double value of key to be set. + * @param values + * Vector of vector of double value of key to be set. * * @throws RCSException + * In case of bad Request */ - public void setValueDouble(String key, double value) throws RCSException { + public void setValueVectorOfVectorOfDouble(String key, + Vector> values) { try { - this.nativeSetValueDouble(key, value); + this.nativeSetValueVectorOfVectorOfDouble(key, values); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Set Vector Vector of Vector of double as Attribute Value. + * + * @param key + * Key of the element to be added. + * + * @param values + * Vector of Vector of Vector of double value of key to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueVectorOfVectorOfVectorOfDouble(String key, + Vector>> values) { + try { + this.nativeSetValueVectorOfVectorOfVectorOfDouble(key, values); } catch (Exception e) { e.printStackTrace(); } @@ -217,12 +329,14 @@ public class RCSResourceAttributes { * set a boolean attribute value. * * @param key - * - Key of the element to be added. + * Key of the element to be added. * - * @param value - * - integer value of key to be set. + * @param values + * boolean value of key to be set. * * @throws RCSException + * In case of bad Request + * */ public void setValueBool(String key, boolean value) throws RCSException { try { @@ -233,15 +347,78 @@ public class RCSResourceAttributes { } /** + * Set Vector of boolean as Attribute Value. + * + * @param key + * Key of the element to be added. + * + * @param values + * Vector of boolean value of key to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueVectorOfBool(String key, Vector values) { + try { + this.nativeSetValueVectorOfBoolean(key, values); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Set Vector of Vector of boolean as Attribute Value. + * + * @param key + * Key of the element to be added. + * + * @param values + * Vector of vector of boolean value of key to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueVectorOfVectorOfBool(String key, + Vector> values) { + try { + this.nativeSetValueVectorOfVectorOfBoolean(key, values); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Set Vector Vector of Vector of boolean as Attribute Value. + * + * @param key + * Key of the element to be added. + * + * @param values + * Vector of Vector of Vector of boolean value of key to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueVectorOfVectorOfVectorOfBool(String key, + Vector>> values) { + try { + this.nativeSetValueVectorOfVectorOfVectorOfBoolean(key, values); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** * set a string attribute value. * * @param key - * - Key of the element to be added. + * Key of the element to be added. * * @param value - * - integer value of key to be set. + * String value of key to be set. * * @throws RCSException + * In case of bad Request */ public void setValueString(String key, String value) throws RCSException { try { @@ -252,6 +429,89 @@ public class RCSResourceAttributes { } /** + * Set Vector of String as Attribute Value. + * + * @param key + * Key of the element to be added. + * + * @param values + * Vector of String value of key to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueVectorOfString(String key, Vector values) { + try { + this.nativeSetValueVectorOfString(key, values); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Set Vector of Vector of String as Attribute Value. + * + * @param key + * Key of the element to be added. + * + * @param values + * Vector of vector of String value of key to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueVectorOfVectorOfString(String key, + Vector> values) { + try { + this.nativeSetValueVectorOfVectorOfString(key, values); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Set Vector Vector of Vector of String as Attribute Value. + * + * @param key + * Key of the element to be added. + * + * @param values + * Vector of Vector of Vector of String value of key to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueVectorOfVectorOfVectorOfString(String key, + Vector>> values) { + try { + this.nativeSetValueVectorOfVectorOfVectorOfString(key, values); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * set a Attribute as attribute value. + * + * @param key + * Key of the element to be added. + * + * @param values + * RCSResourceAttributes to be set. + * + * @throws RCSException + * In case of bad Request + */ + public void setValueAttributes(String key, RCSResourceAttributes value) + throws RCSException { + try { + this.nativeSetValueAttributes(key, value); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** * Returns whether attribute is empty. * * @return boolean