From ddedeb08066b11328a58de3a3a2f18c07f5fe118 Mon Sep 17 00:00:00 2001 From: "abitha.s" Date: Thu, 3 Nov 2016 11:09:37 +0530 Subject: [PATCH] Add Cpp Api for Provider to Enable MQ cloud service. Add environments for MQ build added JNI and Java API modifications for MQ cloud service API Change-Id: I0e2c2cf1e4f1a2672ca1ad6dacee7edff1eb3df2 Signed-off-by: abitha.s Reviewed-on: https://gerrit.iotivity.org/gerrit/13987 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../service/ns/consumer/ConsumerService.java | 14 ++++++++- .../service/ns/provider/ProviderService.java | 12 ++++++++ .../main/jni/consumer/JniNotificationConsumer.cpp | 34 ++++++++++++++++++++++ .../main/jni/consumer/JniNotificationConsumer.h | 9 ++++++ .../main/jni/provider/JniNotificationProvider.cpp | 34 ++++++++++++++++++++++ .../main/jni/provider/JniNotificationProvider.h | 9 ++++++ .../notification/cpp-wrapper/consumer/SConscript | 12 ++++++++ .../cpp-wrapper/consumer/inc/NSConsumerService.h | 8 +++++ .../cpp-wrapper/consumer/src/NSConsumerService.cpp | 18 ++++++++++++ .../cpp-wrapper/consumer/src/NSProvider.cpp | 8 ++--- .../cpp-wrapper/examples/linux/SConscript | 13 +++++++++ .../notification/cpp-wrapper/provider/SConscript | 12 ++++++++ .../cpp-wrapper/provider/inc/NSProviderService.h | 8 +++++ .../cpp-wrapper/provider/src/NSProviderService.cpp | 18 ++++++++++++ 14 files changed, 204 insertions(+), 5 deletions(-) mode change 100644 => 100755 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java mode change 100644 => 100755 service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/ConsumerService.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/ConsumerService.java index 58bf57a..a4914c2 100755 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/ConsumerService.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/ConsumerService.java @@ -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; } diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java old mode 100644 new mode 100755 index b15ba46..d3bb718 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java @@ -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; diff --git a/service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.cpp b/service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.cpp index ce49ec3..b355baf 100755 --- a/service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.cpp +++ b/service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.cpp @@ -924,6 +924,40 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService return (jint) res; } +JNIEXPORT jint JNICALL +Java_org_iotivity_service_ns_consumer_ConsumerService_nativeSubscribeMQService +(JNIEnv *env, jobject jObj, jstring jserverAddress, jstring jTopicName) +{ + LOGD("ConsumerService: 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::NSConsumerService::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("ConsumerService: nativeSubscribeMQService - OUT"); + return (jint) result; +} + JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeRescanProvider (JNIEnv *env, jobject jObj) { diff --git a/service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.h b/service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.h index 97ae3d8..d04c626 100755 --- a/service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.h +++ b/service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.h @@ -55,6 +55,15 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService /* * Class: org_iotivity_service_ns_consumer_ConsumerService + * Method: nativeSubscribeMQService + * Signature: (Ljava/lang/String;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_org_iotivity_service_ns_consumer_ConsumerService_nativeSubscribeMQService +(JNIEnv *, jobject, jstring, jstring); + +/* + * Class: org_iotivity_service_ns_consumer_ConsumerService * Method: nativeRescanProvider * Signature: ()V */ diff --git a/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp index 91c4fc5..1995d1b 100755 --- a/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp +++ b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp @@ -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) { diff --git a/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h old mode 100644 new mode 100755 index d3a1a50..d72936d --- a/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h +++ b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h @@ -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 */ diff --git a/service/notification/cpp-wrapper/consumer/SConscript b/service/notification/cpp-wrapper/consumer/SConscript index e18ce7c..5fc27e7 100755 --- a/service/notification/cpp-wrapper/consumer/SConscript +++ b/service/notification/cpp-wrapper/consumer/SConscript @@ -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 ###################################################################### diff --git a/service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h b/service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h index f60dd57..dd054d8 100755 --- a/service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h +++ b/service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h @@ -78,6 +78,14 @@ namespace OIC NSResult enableRemoteService(const std::string &serverAddress); /** + * Request to subscribe to remote MQ address as parameter. + * @param[in] server address combined with IP address and port number and MQ broker uri using delimiter : + * @param[in] topicName the interest Topic name for subscription. + * @return ::NS_OK or result code of NSResult + */ + NSResult subscribeMQService(const std::string &serverAddress, const std::string &topicName); + + /** * Request discovery manually */ void rescanProvider(); diff --git a/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp b/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp index 4187c9c..78b5197 100755 --- a/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp +++ b/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp @@ -229,6 +229,24 @@ namespace OIC return result; } + NSResult NSConsumerService::subscribeMQService(const std::string &serverAddress, + const std::string &topicName) + { + NS_LOG(DEBUG, "subscribeMQService - IN"); + NS_LOG_V(DEBUG, "Server Address : %s", serverAddress.c_str()); + NSResult result = NSResult::ERROR; +#ifdef WITH_MQ + result = (NSResult) NSConsumerSubscribeMQService( + serverAddress.c_str(), topicName.c_str()); +#else + NS_LOG(ERROR, "MQ Services feature is not enabled in the Build"); + (void) serverAddress; + (void) topicName; +#endif + NS_LOG(DEBUG, "subscribeMQService - OUT"); + return result; + } + void NSConsumerService::rescanProvider() { NS_LOG(DEBUG, "rescanProvider - IN"); diff --git a/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp b/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp index e9e4e48..0c5588a 100755 --- a/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp +++ b/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp @@ -161,15 +161,15 @@ namespace OIC getProviderId().c_str()); NSResult result = (NSResult) NSConsumerUpdateTopicList(getProviderId().c_str(), topicLL); - if(topicLL) + if (topicLL) { - NSTopicLL * iter = topicLL; - NSTopicLL * following = NULL; + NSTopicLL *iter = topicLL; + NSTopicLL *following = NULL; while (iter) { following = iter->next; - if(iter) + if (iter) { NSOICFree(iter->topicName); iter->next = NULL; diff --git a/service/notification/cpp-wrapper/examples/linux/SConscript b/service/notification/cpp-wrapper/examples/linux/SConscript index bff7f1c..6184f49 100755 --- a/service/notification/cpp-wrapper/examples/linux/SConscript +++ b/service/notification/cpp-wrapper/examples/linux/SConscript @@ -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': diff --git a/service/notification/cpp-wrapper/provider/SConscript b/service/notification/cpp-wrapper/provider/SConscript index 956830e..28d983e 100755 --- a/service/notification/cpp-wrapper/provider/SConscript +++ b/service/notification/cpp-wrapper/provider/SConscript @@ -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 ###################################################################### diff --git a/service/notification/cpp-wrapper/provider/inc/NSProviderService.h b/service/notification/cpp-wrapper/provider/inc/NSProviderService.h index f96d239..da2a890 100755 --- a/service/notification/cpp-wrapper/provider/inc/NSProviderService.h +++ b/service/notification/cpp-wrapper/provider/inc/NSProviderService.h @@ -118,6 +118,14 @@ namespace OIC NSResult disableRemoteService(const std::string &serverAddress); /** + * Request to subscribe to remote MQ address as parameter. + * @param[in] server address combined with IP address and port number and MQ broker uri using delimiter : + * @param[in] topicName the interest Topic name for subscription. + * @return ::NS_OK or result code of NSResult + */ + NSResult subscribeMQService(const std::string &serverAddress, const std::string &topicName); + + /** * Send notification message to all subscribers * @param[in] msg Notification message including id, title, contentText * @return :: result code of Provider Service diff --git a/service/notification/cpp-wrapper/provider/src/NSProviderService.cpp b/service/notification/cpp-wrapper/provider/src/NSProviderService.cpp index 79d2dc5..68d3b5e 100755 --- a/service/notification/cpp-wrapper/provider/src/NSProviderService.cpp +++ b/service/notification/cpp-wrapper/provider/src/NSProviderService.cpp @@ -157,6 +157,24 @@ namespace OIC return result; } + NSResult NSProviderService::subscribeMQService(const std::string &serverAddress, + const std::string &topicName) + { + NS_LOG(DEBUG, "subscribeMQService - IN"); + NS_LOG_V(DEBUG, "Server Address : %s", serverAddress.c_str()); + NSResult result = NSResult::ERROR; +#ifdef WITH_MQ + result = (NSResult) NSProviderSubscribeMQService( + serverAddress.c_str(), topicName.c_str()); +#else + NS_LOG(ERROR, "MQ Services feature is not enabled in the Build"); + (void) serverAddress; + (void) topicName; +#endif + NS_LOG(DEBUG, "subscribeMQService - OUT"); + return result; + } + NSResult NSProviderService::sendMessage(NSMessage *msg) { NS_LOG(DEBUG, "sendMessage - IN"); -- 2.7.4