Add Cpp Api for Provider to Enable MQ cloud service.
authorabitha.s <abitha.s@samsung.com>
Thu, 3 Nov 2016 05:39:37 +0000 (11:09 +0530)
committerUze Choi <uzchoi@samsung.com>
Thu, 17 Nov 2016 07:45:59 +0000 (07:45 +0000)
Add environments for MQ build
added JNI and Java API modifications for MQ cloud service API

Change-Id: I0e2c2cf1e4f1a2672ca1ad6dacee7edff1eb3df2
Signed-off-by: abitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13987
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
14 files changed:
service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/ConsumerService.java
service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java [changed mode: 0644->0755]
service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.cpp
service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.h
service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp
service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h [changed mode: 0644->0755]
service/notification/cpp-wrapper/consumer/SConscript
service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h
service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp
service/notification/cpp-wrapper/consumer/src/NSProvider.cpp
service/notification/cpp-wrapper/examples/linux/SConscript
service/notification/cpp-wrapper/provider/SConscript
service/notification/cpp-wrapper/provider/inc/NSProviderService.h
service/notification/cpp-wrapper/provider/src/NSProviderService.cpp

index 58bf57a..a4914c2 100755 (executable)
@@ -91,6 +91,17 @@ public class ConsumerService
     }
 
     /**
+      * Request to subscribe to MQ server
+      * @param servAdd -  servAdd combined with IP address and port number  and MQ broker uri using delimiter :
+      * @param topicName - the interest Topic name for subscription
+      * @return  result code
+      */
+    public int  subscribeMQService(String servAdd, String topicName) throws NSException
+    {
+        return nativeSubscribeMQService(servAdd, topicName);
+    }
+
+    /**
       * Request discovery manually
       */
     public void rescanProvider() throws NSException
@@ -116,5 +127,6 @@ public class ConsumerService
 
     private native void nativeStop() throws NSException;
     private native void nativeEnableRemoteService(String serverAddress) throws NSException;
-    private native void nativeRescanProvider() throws NSException;
+    private native int  nativeSubscribeMQService(String servAdd, String topicName) throws NSException;
+   private native void nativeRescanProvider() throws NSException;
 }
old mode 100644 (file)
new mode 100755 (executable)
index b15ba46..d3bb718
@@ -138,6 +138,17 @@ public class ProviderService
     }
 
     /**
+      * Request to subscribe to MQ server
+      * @param servAdd -  servAdd combined with IP address and port number  and MQ broker uri using delimiter :
+      * @param topicName - the interest Topic name for subscription
+      * @return  result code
+      */
+    public int  subscribeMQService(String servAdd, String topicName) throws NSException
+    {
+        return nativeSubscribeMQService(servAdd, topicName);
+    }
+
+    /**
       * Add topic to topic list
       * @param  topicName - Topic name to add
       * @return :: result code
@@ -202,6 +213,7 @@ public class ProviderService
     public native Message nativeCreateMessage() throws NSException;
     public native int  nativeEnableRemoteService(String servAdd) throws NSException;
     public native int  nativeDisableRemoteService(String servAdd) throws NSException;
+    public native int  nativeSubscribeMQService(String servAdd, String topicName) throws NSException;
     public native int  nativeRegisterTopic(String topicName) throws NSException;
     public native int  nativeUnregisterTopic(String topicName) throws NSException;
     public native TopicsList  nativeGetRegisteredTopicList() throws NSException;
index ce49ec3..b355baf 100755 (executable)
@@ -924,6 +924,40 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService
     return (jint) res;\r
 }\r
 \r
+JNIEXPORT jint JNICALL\r
+Java_org_iotivity_service_ns_consumer_ConsumerService_nativeSubscribeMQService\r
+(JNIEnv *env, jobject jObj, jstring jserverAddress, jstring jTopicName)\r
+{\r
+    LOGD("ConsumerService: nativeSubscribeMQService - IN");\r
+    if (!jserverAddress)\r
+    {\r
+        ThrowNSException(NS_ERROR, "Server Address Can't be NULL");\r
+        return (jint) OIC::Service::NSResult::ERROR;\r
+    }\r
+    if (!jTopicName)\r
+    {\r
+        ThrowNSException(NS_ERROR, "TopicName Can't be NULL");\r
+        return (jint) OIC::Service::NSResult::ERROR;\r
+    }\r
+\r
+    const char *address = env->GetStringUTFChars( jserverAddress, NULL);\r
+    std::string servAddress(address);\r
+    const char *topic = env->GetStringUTFChars( jTopicName, NULL);\r
+    std::string topicName(topic);\r
+\r
+    OIC::Service::NSResult result  =\r
+        OIC::Service::NSConsumerService::getInstance()->subscribeMQService(\r
+            servAddress, topicName);\r
+    if (result !=  OIC::Service::NSResult::OK)\r
+    {\r
+        LOGE("Fail to Subscribe to MQ Service");\r
+    }\r
+    env->ReleaseStringUTFChars(jserverAddress, address);\r
+    env->ReleaseStringUTFChars(jTopicName, topic);\r
+    LOGD("ConsumerService: nativeSubscribeMQService - OUT");\r
+    return (jint) result;\r
+}\r
+\r
 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeRescanProvider\r
 (JNIEnv *env, jobject jObj)\r
 {\r
index 97ae3d8..d04c626 100755 (executable)
@@ -55,6 +55,15 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService
 \r
 /*\r
  * Class:     org_iotivity_service_ns_consumer_ConsumerService\r
+ * Method:    nativeSubscribeMQService\r
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)I\r
+ */\r
+JNIEXPORT jint JNICALL\r
+Java_org_iotivity_service_ns_consumer_ConsumerService_nativeSubscribeMQService\r
+(JNIEnv *, jobject, jstring, jstring);\r
+\r
+/*\r
+ * Class:     org_iotivity_service_ns_consumer_ConsumerService\r
  * Method:    nativeRescanProvider\r
  * Signature: ()V\r
  */\r
index 91c4fc5..1995d1b 100755 (executable)
@@ -979,6 +979,40 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService
     return (jint) result;
 }
 
+JNIEXPORT jint JNICALL
+Java_org_iotivity_service_ns_provider_ProviderService_nativeSubscribeMQService
+(JNIEnv *env, jobject jObj, jstring jserverAddress, jstring jTopicName)
+{
+    LOGD("JNIProviderService: nativeSubscribeMQService - IN");
+    if (!jserverAddress)
+    {
+        ThrowNSException(NS_ERROR, "Server Address Can't be NULL");
+        return (jint) OIC::Service::NSResult::ERROR;
+    }
+    if (!jTopicName)
+    {
+        ThrowNSException(NS_ERROR, "TopicName Can't be NULL");
+        return (jint) OIC::Service::NSResult::ERROR;
+    }
+
+    const char *address = env->GetStringUTFChars( jserverAddress, NULL);
+    std::string servAddress(address);
+    const char *topic = env->GetStringUTFChars( jTopicName, NULL);
+    std::string topicName(topic);
+
+    OIC::Service::NSResult result  =
+        OIC::Service::NSProviderService::getInstance()->subscribeMQService(
+            servAddress, topicName);
+    if (result !=  OIC::Service::NSResult::OK)
+    {
+        LOGE("Fail to Subscribe to MQ Service");
+    }
+    env->ReleaseStringUTFChars(jserverAddress, address);
+    env->ReleaseStringUTFChars(jTopicName, topic);
+    LOGD("JNIProviderService: nativeSubscribeMQService - OUT");
+    return (jint) result;
+}
+
 JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic
 (JNIEnv *env, jobject jObj, jstring jTopicName)
 {
old mode 100644 (file)
new mode 100755 (executable)
index d3a1a50..d72936d
@@ -87,6 +87,15 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService
 
 /*
  * Class:     org_iotivity_service_ns_provider_ProviderService
+ * Method:    nativeSubscribeMQService
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL
+Java_org_iotivity_service_ns_provider_ProviderService_nativeSubscribeMQService
+(JNIEnv *, jobject, jstring, jstring);
+
+/*
+ * Class:     org_iotivity_service_ns_provider_ProviderService
  * Method:    nativeRegisterTopic
  * Signature: (Ljava/lang/String;)I
  */
index e18ce7c..5fc27e7 100755 (executable)
@@ -77,6 +77,18 @@ if not env.get('RELEASE'):
 if env.get('WITH_CLOUD') == True:
        notification_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
 
+with_mq = env.get('WITH_MQ')
+if 'SUB' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
+    print "MQ SUB support"
+
+if 'PUB' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
+    print "MQ PUB support"
+
+if 'BROKER' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
+    print "MQ Broker support"
 ######################################################################
 # Source files and Targets for Consumer
 ######################################################################
index f60dd57..dd054d8 100755 (executable)
@@ -78,6 +78,14 @@ namespace OIC
                 NSResult enableRemoteService(const std::string &serverAddress);\r
 \r
                 /**\r
+                      * Request to subscribe to remote MQ address as parameter.\r
+                      * @param[in] server address combined with IP address and port number and MQ broker uri using delimiter :\r
+                      * @param[in] topicName the interest Topic name for subscription.\r
+                      * @return ::NS_OK or result code of NSResult\r
+                      */\r
+                NSResult subscribeMQService(const std::string &serverAddress, const std::string &topicName);\r
+\r
+                /**\r
                       * Request discovery manually\r
                       */\r
                 void rescanProvider();\r
index 4187c9c..78b5197 100755 (executable)
@@ -229,6 +229,24 @@ namespace OIC
             return result;\r
         }\r
 \r
+        NSResult NSConsumerService::subscribeMQService(const std::string &serverAddress,\r
+                const std::string &topicName)\r
+        {\r
+            NS_LOG(DEBUG, "subscribeMQService - IN");\r
+            NS_LOG_V(DEBUG, "Server Address : %s", serverAddress.c_str());\r
+            NSResult result = NSResult::ERROR;\r
+#ifdef WITH_MQ\r
+            result = (NSResult) NSConsumerSubscribeMQService(\r
+                         serverAddress.c_str(), topicName.c_str());\r
+#else\r
+            NS_LOG(ERROR, "MQ Services feature is not enabled in the Build");\r
+            (void) serverAddress;\r
+            (void) topicName;\r
+#endif\r
+            NS_LOG(DEBUG, "subscribeMQService - OUT");\r
+            return result;\r
+        }\r
+\r
         void NSConsumerService::rescanProvider()\r
         {\r
             NS_LOG(DEBUG, "rescanProvider - IN");\r
index e9e4e48..0c5588a 100755 (executable)
@@ -161,15 +161,15 @@ namespace OIC
                      getProviderId().c_str());\r
             NSResult result = (NSResult) NSConsumerUpdateTopicList(getProviderId().c_str(), topicLL);\r
 \r
-            if(topicLL)\r
+            if (topicLL)\r
             {\r
-                NSTopicLL * iter = topicLL;\r
-                NSTopicLL * following = NULL;\r
+                NSTopicLL *iter = topicLL;\r
+                NSTopicLL *following = NULL;\r
 \r
                 while (iter)\r
                 {\r
                     following = iter->next;\r
-                    if(iter)\r
+                    if (iter)\r
                     {\r
                         NSOICFree(iter->topicName);\r
                         iter->next = NULL;\r
index bff7f1c..6184f49 100755 (executable)
@@ -69,6 +69,19 @@ if not env.get('RELEASE'):
 if env.get('WITH_CLOUD') == True:
        notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
 
+with_mq = env.get('WITH_MQ')
+if 'SUB' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
+    print "MQ SUB support"
+
+if 'PUB' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
+    print "MQ PUB support"
+
+if 'BROKER' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
+    print "MQ Broker support"
+
 if env.get('WITH_TCP') == True:
        notification_sample_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
        if env.get('SECURED') == '1':
index 956830e..28d983e 100755 (executable)
@@ -76,6 +76,18 @@ if not env.get('RELEASE'):
 if env.get('WITH_CLOUD') == True:
        notification_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
 
+with_mq = env.get('WITH_MQ')
+if 'SUB' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
+    print "MQ SUB support"
+
+if 'PUB' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
+    print "MQ PUB support"
+
+if 'BROKER' in with_mq:
+    notification_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
+    print "MQ Broker support"
 ######################################################################
 # Source files and Targets for Provider
 ######################################################################
index f96d239..da2a890 100755 (executable)
@@ -118,6 +118,14 @@ namespace OIC
                 NSResult disableRemoteService(const std::string &serverAddress);\r
 \r
                 /**\r
+                      * Request to subscribe to remote MQ address as parameter.\r
+                      * @param[in] server address combined with IP address and port number and MQ broker uri using delimiter :\r
+                      * @param[in] topicName the interest Topic name for subscription.\r
+                      * @return ::NS_OK or result code of NSResult\r
+                      */\r
+                NSResult subscribeMQService(const std::string &serverAddress, const std::string &topicName);\r
+\r
+                /**\r
                       * Send notification message to all subscribers\r
                       * @param[in]  msg  Notification message including id, title, contentText\r
                       * @return :: result code of Provider Service\r
index 79d2dc5..68d3b5e 100755 (executable)
@@ -157,6 +157,24 @@ namespace OIC
             return result;\r
         }\r
 \r
+        NSResult NSProviderService::subscribeMQService(const std::string &serverAddress,\r
+                const std::string &topicName)\r
+        {\r
+            NS_LOG(DEBUG, "subscribeMQService - IN");\r
+            NS_LOG_V(DEBUG, "Server Address : %s", serverAddress.c_str());\r
+            NSResult result = NSResult::ERROR;\r
+#ifdef WITH_MQ\r
+            result = (NSResult) NSProviderSubscribeMQService(\r
+                         serverAddress.c_str(), topicName.c_str());\r
+#else\r
+            NS_LOG(ERROR, "MQ Services feature is not enabled in the Build");\r
+            (void) serverAddress;\r
+            (void) topicName;\r
+#endif\r
+            NS_LOG(DEBUG, "subscribeMQService - OUT");\r
+            return result;\r
+        }\r
+\r
         NSResult NSProviderService::sendMessage(NSMessage *msg)\r
         {\r
             NS_LOG(DEBUG, "sendMessage - IN");\r