Apply Java API which can start transport type in initialization
authorjihwan.seo <jihwan.seo@samsung.com>
Fri, 24 Feb 2017 07:01:24 +0000 (16:01 +0900)
committerRick Bell <richard.s.bell@intel.com>
Wed, 8 Mar 2017 18:38:16 +0000 (18:38 +0000)
this patch is related to https://gerrit.iotivity.org/gerrit/#/c/16433/

Change-Id: I405306ef94add209e8743fc4636855a5263df58c
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17687
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Larry Sachs <larry.j.sachs@intel.com>
Reviewed-by: George Nash <george.nash@intel.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
java/iotivity-android/src/main/java/org/iotivity/base/OcPlatform.java
java/iotivity-android/src/main/java/org/iotivity/base/PlatformConfig.java
java/iotivity-linux/src/main/java/org/iotivity/base/OcPlatform.java
java/iotivity-linux/src/main/java/org/iotivity/base/PlatformConfig.java
java/jni/JniOcPlatform.cpp
java/jni/JniOcPlatform.h
java/jni/JniUtils.h
resource/include/OCApi.h

index fd11235..6f63eea 100644 (file)
@@ -108,7 +108,8 @@ public final class OcPlatform {
                     platformConfig.getIpAddress(),
                     platformConfig.getPort(),
                     platformConfig.getQualityOfService().getValue(),
-                    platformConfig.getSvrDbPath()
+                    platformConfig.getSvrDbPath(),
+                    platformConfig.getAvailableTransportType()
             );
 
             sIsPlatformInitialized = true;
@@ -120,7 +121,8 @@ public final class OcPlatform {
                                          String ipAddress,
                                          int port,
                                          int qualityOfService,
-                                         String dbPath);
+                                         String dbPath,
+                                         int transport);
 
     /**
      * API for stop all process of the OcPlatform.
index b41b65c..d1cab3d 100644 (file)
@@ -24,7 +24,7 @@ package org.iotivity.base;
 
 import android.content.Context;
 import android.app.Activity;
-
+import java.util.EnumSet;
 /**
  * Data structure to provide the configuration.
  */
@@ -38,6 +38,7 @@ public class PlatformConfig {
     private QualityOfService mQualityOfService;
     private String mSvrDbPath; //TODO: Instead of SVRDB file, it should be Persistent Storage.
                               //this is only for 0.9.2
+    private int mTransportType;
     /**
      * @param activity         app activity
      * @param context          app context
@@ -68,6 +69,7 @@ public class PlatformConfig {
         this.mPort = port;
         this.mQualityOfService = qualityOfService;
         this.mSvrDbPath = dbPath;
+        this.mTransportType = 0;
     }
 
     /**
@@ -170,4 +172,14 @@ public class PlatformConfig {
         return mActivity;
     }
 
+    public void setAvailableTransportType(EnumSet<OcConnectivityType> type) {
+        for (OcConnectivityType connType : OcConnectivityType.values()) {
+            if (type.contains(connType))
+                mTransportType |= connType.getValue();
+        }
+    }
+
+    public int getAvailableTransportType() {
+        return mTransportType;
+    }
 }
index 215c946..4151c24 100644 (file)
@@ -102,7 +102,8 @@ public final class OcPlatform {
                     platformConfig.getIpAddress(),
                     platformConfig.getPort(),
                     platformConfig.getQualityOfService().getValue(),
-                    platformConfig.getSvrDbPath()
+                    platformConfig.getSvrDbPath(),
+                    platformConfig.getAvailableTransportType()
             );
 
             sIsPlatformInitialized = true;
@@ -114,7 +115,8 @@ public final class OcPlatform {
                                          String ipAddress,
                                          int port,
                                          int qualityOfService,
-                                         String dbPath);
+                                         String dbPath,
+                                         int transport);
 
     /**
      * API for stop all process of the OcPlatform.
index 7f56d4d..8d06aae 100644 (file)
@@ -22,6 +22,8 @@
 
 package org.iotivity.base;
 
+import java.util.EnumSet;
+
 /**
  * Data structure to provide the configuration.
  */
@@ -33,6 +35,7 @@ public class PlatformConfig {
     private QualityOfService mQualityOfService;
     private String mSvrDbPath; //TODO: Instead of SVRDB file, it should be Persistent Storage.
                               //this is only for 0.9.2
+    private int mTransportType;
     /**
      * @param serviceType      indicate IN_PROC or OUT_OF_PROC
      * @param modeType         indicate whether we want to do server, client or both
@@ -58,6 +61,7 @@ public class PlatformConfig {
         this.mPort = port;
         this.mQualityOfService = qualityOfService;
         this.mSvrDbPath = dbPath;
+        this.mTransportType = 0;
     }
 
     /**
@@ -105,4 +109,14 @@ public class PlatformConfig {
         return mSvrDbPath;
     }
 
+    public void setAvailableTransportType(EnumSet<OcConnectivityType> type) {
+        for (OcConnectivityType connType : OcConnectivityType.values()) {
+            if (type.contains(connType))
+                mTransportType |= connType.getValue();
+        }
+    }
+
+    public int getAvailableTransportType() {
+        return mTransportType;
+    }
 }
index 291b471..19b548e 100644 (file)
@@ -612,11 +612,11 @@ void RemoveOnDirectPairingListener(JNIEnv* env, jobject jListener)
 /*
 * Class:     org_iotivity_base_OcPlatform
 * Method:    configure
-* Signature: (IILjava/lang/String;II)V
+* Signature: (IILjava/lang/String;IILjava/lang/String;I)V
 */
 JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure
 (JNIEnv *env, jclass clazz, jint jServiceType, jint jModeType, jstring jIpAddress, jint jPort,
                                                                jint jQOS, jstring jDbPath)
jint jQOS, jstring jDbPath, jint jTransport)
 {
     LOGI("OcPlatform_configure");
 
@@ -642,6 +642,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure
         JniUtils::getModeType(env, jModeType),
         ipAddress,
         port,
+        JniUtils::getOCTransportAdapter(jTransport),
         JniUtils::getQOS(env, static_cast<int>(jQOS)),
         JniOcSecurity::getOCPersistentStorage()
     };
index 0b8106a..45d4125 100644 (file)
@@ -84,10 +84,10 @@ extern "C" {
     /*
     * Class:     org_iotivity_base_OcPlatform
     * Method:    configure
-    * Signature: (IILjava/lang/String;II)V
+    * Signature: (IILjava/lang/String;IILjava/lang/String;I)V
     */
     JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure
-        (JNIEnv *, jclass, jint, jint, jstring, jint, jint, jstring);
+        (JNIEnv *, jclass, jint, jint, jstring, jint, jint, jstring, jint);
 
     /*
     * Class:     org_iotivity_base_OcPlatform
index 5237866..376db66 100644 (file)
@@ -135,6 +135,36 @@ public:
         }
     }
 
+    static OCTransportAdapter getOCTransportAdapter(int adapter)
+    {
+        int transport = OCTransportAdapter::OC_DEFAULT_ADAPTER;
+        if (adapter & CT_ADAPTER_IP)
+        {
+            transport |= OCTransportAdapter::OC_ADAPTER_IP;
+        }
+
+        if (adapter & CT_ADAPTER_GATT_BTLE)
+        {
+            transport |= OCTransportAdapter::OC_ADAPTER_GATT_BTLE;
+        }
+
+        if (adapter & CT_ADAPTER_RFCOMM_BTEDR)
+        {
+            transport |= OCTransportAdapter::OC_ADAPTER_RFCOMM_BTEDR;
+        }
+
+        if (adapter & CT_ADAPTER_TCP)
+        {
+            transport |= OCTransportAdapter::OC_ADAPTER_TCP;
+        }
+
+        if (adapter & CT_ADAPTER_NFC)
+        {
+            transport |= OCTransportAdapter::OC_ADAPTER_NFC;
+        }
+        return (OCTransportAdapter)transport;
+    }
+
     static std::string stackResultToStr(const int result)
     {
         switch (result)
index 100eec0..2d200f3 100644 (file)
@@ -208,6 +208,23 @@ namespace OC
         {}
             PlatformConfig(const ServiceType serviceType_,
             const ModeType mode_,
+            const std::string& ipAddress_,
+            const uint16_t port_,
+            const OCTransportAdapter transportType_,
+            const QualityOfService QoS_,
+            OCPersistentStorage *ps_ = nullptr)
+                : serviceType(serviceType_),
+                mode(mode_),
+                serverConnectivity(CT_DEFAULT),
+                clientConnectivity(CT_DEFAULT),
+                transportType(transportType_),
+                ipAddress(ipAddress_),
+                port(port_),
+                QoS(QoS_),
+                ps(ps_)
+        {}
+            PlatformConfig(const ServiceType serviceType_,
+            const ModeType mode_,
             OCTransportAdapter transportType_,
             const QualityOfService QoS_,
             OCPersistentStorage *ps_ = nullptr)