Expose OcRepresentation values to the Java layer
authorSalvatore Iovene <salvatore.iovene@intel.com>
Thu, 28 Apr 2016 10:52:19 +0000 (13:52 +0300)
committerAshok Babu Channa <ashok.channa@samsung.com>
Thu, 9 Jun 2016 11:33:18 +0000 (11:33 +0000)
Change-Id: Ia6ef76be68f686e9a461475b1cd6282b749a39fd
Signed-off-by: Salvatore Iovene <salvatore.iovene@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8193
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sakari Poussa <sakari.poussa@intel.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
android/android_api/base/jni/JniOcRepresentation.cpp
android/android_api/base/jni/JniOcRepresentation.h
android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java
resource/include/OCRepresentation.h

index c9cf0d3..1403349 100644 (file)
@@ -19,6 +19,9 @@
 * //
 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 */
+
+#include <map>
+
 #include "JniOcRepresentation.h"
 #include "JniUtils.h"
 
@@ -40,6 +43,30 @@ OCRepresentation* JniOcRepresentation::getOCRepresentationPtr(JNIEnv *env, jobje
 
 /*
 * Class:     org_iotivity_base_OcRepresentation
+* Method:    getValues
+* Signature: ()Ljava/util/Map;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
+(JNIEnv *env, jobject thiz)
+{
+    LOGD("OcRepresentation_getValues");
+    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+    if (!rep) return nullptr;
+
+    std::map<std::string, AttributeValue> values = rep->getValues();
+    jobject jHashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor);
+    if (!jHashMap) return nullptr;
+
+    for (std::map<std::string, AttributeValue>::const_iterator it = values.begin(); it != values.end(); it++) {
+        jobject key = static_cast<jobject>(env->NewStringUTF(it->first.c_str()));
+        jobject val = boost::apply_visitor(JObjectConverter(env), it->second);
+        env->CallObjectMethod(jHashMap, g_mid_HashMap_put, key, val);
+    }
+    return jHashMap;
+}
+
+/*
+* Class:     org_iotivity_base_OcRepresentation
 * Method:    getValueN
 * Signature: (Ljava/lang/String;)Ljava/lang/Object;
 */
index e0a87b6..a153dd7 100644 (file)
@@ -462,6 +462,14 @@ extern "C" {
 
     /*
     * Class:     org_iotivity_base_OcRepresentation
+    * Method:    getValues
+    * Signature: ()Ljava/util/Map;
+    */
+    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
+        (JNIEnv *, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcRepresentation
     * Method:    getValueN
     * Signature: (Ljava/lang/String;)Ljava/lang/Object;
     */
index 0be617a..24d8b88 100644 (file)
@@ -25,6 +25,7 @@ package org.iotivity.base;
 import java.security.InvalidParameterException;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 /**
  *
@@ -52,6 +53,8 @@ public class OcRepresentation {
         this.mNativeNeedsDelete = nativeNeedsDelete;
     }
 
+    public native Map<String, Object> getValues();
+
     public <T> T getValue(String key) throws OcException {
         Object obj = this.getValueN(key);
         @SuppressWarnings("unchecked")
index 5f2071a..4a18fe7 100644 (file)
@@ -160,6 +160,10 @@ namespace OC
                 m_values[str] = std::forward<T>(val);
             }
 
+            const std::map<std::string, AttributeValue>& getValues() const {
+                return m_values;
+            }
+
             /**
              *  Retrieve the attribute value associated with the supplied name
              *