[IOT-2184] Expost OCResoruce.getAllHosts method in Java
authorGeorge Nash <george.nash@intel.com>
Mon, 1 May 2017 22:22:10 +0000 (15:22 -0700)
committerRick Bell <richard.s.bell@intel.com>
Tue, 2 May 2017 19:09:49 +0000 (19:09 +0000)
Bug: https://jira.iotivity.org/browse/IOT-2184
Change-Id: Iea34fa38db79da58f7245ea24ed5d85e26cf68c8
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19511
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Larry Sachs <larry.j.sachs@intel.com>
Reviewed-by: Thiago Moura <thiagogcm@gmail.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
java/common/src/main/java/org/iotivity/base/OcResource.java
java/jni/JniOcResource.cpp
java/jni/JniOcResource.h

index 719e91b..bb78050 100644 (file)
@@ -527,6 +527,13 @@ public class OcResource {
     public native String getHost();
 
     /**
+     * Method to get the endpoints information of this resource
+     *
+     * @return List of endpoints information
+     */
+    public native List<String> getAllHosts();
+
+    /**
      * Method to get the URI for this resource
      *
      * @return resource URI
index 44f1eb3..6c887f6 100644 (file)
@@ -321,6 +321,11 @@ std::string JniOcResource::host()
     return m_sharedResource->host();
 }
 
+std::vector< std::string > JniOcResource::getAllHosts() const
+{
+    return m_sharedResource->getAllHosts();
+}
+
 std::string JniOcResource::uri()
 {
     return m_sharedResource->uri();
@@ -1560,6 +1565,26 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getHost
 
 /*
 * Class:     org_iotivity_base_OcResource
+* Method:    getAllHosts
+* Signature: ()Ljava/util/List;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getAllHosts
+    (JNIEnv *env, jobject thiz)
+{
+    LOGD("OcResource_getAllHosts");
+    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+    if (!resource)
+    {
+        return nullptr;
+    }
+
+    std::vector<std::string> allHosts = resource->getAllHosts();
+
+    return JniUtils::convertStrVectorToJavaStrList(env, allHosts);
+}
+
+/*
+* Class:     org_iotivity_base_OcResource
 * Method:    getUri
 * Signature: ()Ljava/lang/String;
 */
index 7dfacd3..ff2a432 100644 (file)
@@ -85,6 +85,7 @@ public:
     void setHeaderOptions(const HeaderOptions &headerOptions);
     void unsetHeaderOptions();
     std::string host();
+    std::vector< std::string > getAllHosts() const;
     std::string uri();
     OCConnectivityType connectivityType() const;
     bool isObservable();
@@ -318,6 +319,14 @@ extern "C" {
 
     /*
     * Class:     org_iotivity_base_OcResource
+    * Method:    getAllHosts
+    * Signature: ()Ljava/util/List;
+    */
+    JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getAllHosts
+        (JNIEnv *, jobject);
+
+    /*
+    * Class:     org_iotivity_base_OcResource
     * Method:    getUri
     * Signature: ()Ljava/lang/String;
     */