From 30a7d9a3220403bd8d0d1e0a18f449f610e181fb Mon Sep 17 00:00:00 2001 From: "abitha.s" Date: Tue, 24 Jan 2017 14:25:37 +0530 Subject: [PATCH] [IOT-1773]Removing redundant return code by modifying Java APIs to return void. As error status is thrown in exception Change-Id: I3bd917cb1840db51ade54e49033b2281416d7add Signed-off-by: abitha.s Reviewed-on: https://gerrit.iotivity.org/gerrit/16723 Tested-by: jenkins-iotivity Reviewed-by: Chihyun Cho Reviewed-by: Uze Choi --- .../iotivity/service/ns/common/MediaContents.java | 2 +- .../org/iotivity/service/ns/common/Message.java | 24 +++--- .../org/iotivity/service/ns/common/SyncInfo.java | 6 +- .../java/org/iotivity/service/ns/common/Topic.java | 4 +- .../org/iotivity/service/ns/common/TopicsList.java | 2 +- .../service/ns/consumer/ConsumerService.java | 8 +- .../org/iotivity/service/ns/consumer/Provider.java | 10 +-- .../org/iotivity/service/ns/provider/Consumer.java | 26 +++--- .../service/ns/provider/ProviderService.java | 66 ++++++---------- .../main/jni/consumer/JniNotificationConsumer.cpp | 34 ++++---- .../main/jni/consumer/JniNotificationConsumer.h | 12 +-- .../main/jni/provider/JniNotificationProvider.cpp | 86 +++++++++++--------- .../main/jni/provider/JniNotificationProvider.h | 44 +++++------ .../ns/sample/consumer/ExampleUnitTest.java | 10 +-- .../ns/sample/consumer/ProviderSimulator.java | 8 +- .../service/ns/sample/consumer/ConsumerSample.java | 8 +- .../service/ns/sample/consumer/MainActivity.java | 5 +- .../ns/sample/provider/ExampleUnitTest.java | 23 +++--- .../service/ns/sample/provider/MainActivity.java | 17 ++-- .../service/ns/sample/provider/ProviderSample.java | 92 ++++++++-------------- 20 files changed, 218 insertions(+), 269 deletions(-) mode change 100644 => 100755 service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ProviderSimulator.java mode change 100644 => 100755 service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/org/iotivity/service/ns/sample/provider/ExampleUnitTest.java mode change 100644 => 100755 service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/MainActivity.java mode change 100644 => 100755 service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/ProviderSample.java diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/MediaContents.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/MediaContents.java index 52e5ced..4766ff0 100755 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/MediaContents.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/MediaContents.java @@ -31,7 +31,7 @@ public class MediaContents { private static final String LOG_TAG = "NotificationService_MediaContents"; - public String mIconImage = null; + private String mIconImage = null; public MediaContents(String iconImage) { Log.i(LOG_TAG, "MediaContents()"); diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Message.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Message.java index 8d01ef6..8466970 100755 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Message.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Message.java @@ -53,18 +53,18 @@ public class Message { } }; - public long mMessageId = 0; - public String mProviderId = null; - - public String mSourceName = null; - public MessageType mType = MessageType.ALERT; - public String mTime = null; - public long mTTL = 0; - public String mTitle = null; - public String mContentText = null; - public MediaContents mMediaContents = null; - public String mTopic = null; - public OcRepresentation mExtraInfo = null; + private long mMessageId = 0; + private String mProviderId = null; + + private String mSourceName = null; + private MessageType mType = MessageType.ALERT; + private String mTime = null; + private long mTTL = 0; + private String mTitle = null; + private String mContentText = null; + private MediaContents mMediaContents = null; + private String mTopic = null; + private OcRepresentation mExtraInfo = null; private long mNativeHandle = 0; diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/SyncInfo.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/SyncInfo.java index 70b970d..aa94b65 100755 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/SyncInfo.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/SyncInfo.java @@ -50,9 +50,9 @@ public class SyncInfo { } }; - public long mMessageId = 0; - public String mProviderId = null; - public SyncType mState = SyncType.UNREAD; + private long mMessageId = 0; + private String mProviderId = null; + private SyncType mState = SyncType.UNREAD; public SyncInfo(long messageId, String providerId, SyncType state) { Log.i(LOG_TAG, "SyncInfo()"); diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Topic.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Topic.java index 40c4595..e949d2c 100644 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Topic.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Topic.java @@ -51,8 +51,8 @@ public class Topic { }; - public String mTopicName = null; - public TopicState mState = TopicState.UNSUBSCRIBED; + private String mTopicName = null; + private TopicState mState = TopicState.UNSUBSCRIBED; public Topic(String topicName, TopicState state) { Log.i(LOG_TAG, "Topic()"); diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/TopicsList.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/TopicsList.java index 64c3a88..62c288e 100644 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/TopicsList.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/TopicsList.java @@ -33,7 +33,7 @@ public class TopicsList { private static final String LOG_TAG = "NotificationService_TopicList"; - public Vector mTopicsList = new Vector(); + private Vector mTopicsList = new Vector(); public void addTopic(String topicname, Topic.TopicState state) { mTopicsList.add(new Topic(topicname, state)); 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 def5940..fa9f78c 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 @@ -105,13 +105,11 @@ public class ConsumerService { * @param topicName * the interest Topic name for subscription * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failed to subscribe to MQ server */ - public int subscribeMQService(String servAdd, String topicName) + public void subscribeMQService(String servAdd, String topicName) throws NSException { - return nativeSubscribeMQService(servAdd, topicName); + nativeSubscribeMQService(servAdd, topicName); } /** @@ -146,7 +144,7 @@ public class ConsumerService { private native void nativeEnableRemoteService(String serverAddress) throws NSException; - private native int nativeSubscribeMQService(String servAdd, + private native void 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/consumer/Provider.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/Provider.java index c3823df..e42da4a 100755 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/Provider.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/Provider.java @@ -53,7 +53,7 @@ public class Provider { } }; - public String mProviderId = null; + private String mProviderId = null; private long mNativeHandle = 0; /** @@ -167,12 +167,10 @@ public class Provider { * @param topicsList * TopicsList of interested Topics * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failure to update topic list. */ - public int updateTopicList(TopicsList topicsList) throws NSException { - return nativeUpdateTopicList(topicsList); + public void updateTopicList(TopicsList topicsList) throws NSException { + nativeUpdateTopicList(topicsList); } /** @@ -233,7 +231,7 @@ public class Provider { public native TopicsList nativeGetTopicList() throws NSException; - private native int nativeUpdateTopicList(TopicsList topicsList) + private native void nativeUpdateTopicList(TopicsList topicsList) throws NSException; private native ProviderState nativeGetProviderState() throws NSException; diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/Consumer.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/Consumer.java index d16b58b..fd4c01e 100644 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/Consumer.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/Consumer.java @@ -29,7 +29,7 @@ import java.util.Vector; */ public class Consumer { - public String mConsumerId = null; + private String mConsumerId = null; /** * Constructor of Consumer @@ -57,12 +57,10 @@ public class Consumer { * boolean variable representing Subscription response as * TRUE/FALSE. * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failure accepting subscription request */ - public int acceptSubscription(boolean accepted) throws NSException { - return nativeAcceptSubscription(mConsumerId, accepted); + public void acceptSubscription(boolean accepted) throws NSException { + nativeAcceptSubscription(mConsumerId, accepted); } /** @@ -71,12 +69,10 @@ public class Consumer { * @param topicName * Topic name to select * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failure selecting a topic */ - public int setTopic(String topicName) throws NSException { - return nativeSetConsumerTopic(mConsumerId, topicName); + public void setTopic(String topicName) throws NSException { + nativeSetConsumerTopic(mConsumerId, topicName); } /** @@ -85,12 +81,10 @@ public class Consumer { * @param topicName * Topic name to Unselect * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failure unselecting topic */ - public int unsetTopic(String topicName) throws NSException { - return nativeUnsetConsumerTopic(mConsumerId, topicName); + public void unsetTopic(String topicName) throws NSException { + nativeUnsetConsumerTopic(mConsumerId, topicName); } /** @@ -104,13 +98,13 @@ public class Consumer { return nativeGetConsumerTopicList(mConsumerId); } - public native int nativeAcceptSubscription(String consumerId, + public native void nativeAcceptSubscription(String consumerId, boolean accepted) throws NSException; - public native int nativeSetConsumerTopic(String consumerId, + public native void nativeSetConsumerTopic(String consumerId, String topicName) throws NSException; - public native int nativeUnsetConsumerTopic(String consumerId, + public native void nativeUnsetConsumerTopic(String consumerId, String topicName) throws NSException; public native TopicsList nativeGetConsumerTopicList(String consumerId) 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 index db8e50f..9128524 100755 --- 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 @@ -76,28 +76,24 @@ public class ProviderService { * @param resourceSecurity * Set on/off for secure resource channel setting * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException * if any callback parameter passed is null */ - public int start(OnConsumerSubscribedListener subscribedListener, + public void start(OnConsumerSubscribedListener subscribedListener, OnMessageSynchronizedListener messageSynchronized, boolean subControllability, String userInfo, boolean resourceSecurity) throws NSException { - return nativeStart(subscribedListener, messageSynchronized, + nativeStart(subscribedListener, messageSynchronized, subControllability, userInfo, resourceSecurity); } /** * Stop ProviderService * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failed to stop ProviderService */ - public int stop() throws NSException { - return nativeStop(); + public void stop() throws NSException { + nativeStop(); } /** @@ -106,12 +102,10 @@ public class ProviderService { * @param message * Notification message including id, title, contentText * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failed to send notification message */ - public int sendMessage(Message message) throws NSException { - return nativeSendMessage(message); + public void sendMessage(Message message) throws NSException { + nativeSendMessage(message); } /** @@ -148,12 +142,10 @@ public class ProviderService { * servAdd combined with IP address and port number using * delimiter * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failed to publish resource */ - public int enableRemoteService(String servAdd) throws NSException { - return nativeEnableRemoteService(servAdd); + public void enableRemoteService(String servAdd) throws NSException { + nativeEnableRemoteService(servAdd); } /** @@ -163,12 +155,10 @@ public class ProviderService { * servAdd combined with IP address and port number using * delimiter * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failed to publish resource */ - public int disableRemoteService(String servAdd) throws NSException { - return nativeDisableRemoteService(servAdd); + public void disableRemoteService(String servAdd) throws NSException { + nativeDisableRemoteService(servAdd); } /** @@ -180,13 +170,11 @@ public class ProviderService { * @param topicName * the interest Topic name for subscription * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failed to subscribe to MQ server */ - public int subscribeMQService(String servAdd, String topicName) + public void subscribeMQService(String servAdd, String topicName) throws NSException { - return nativeSubscribeMQService(servAdd, topicName); + nativeSubscribeMQService(servAdd, topicName); } /** @@ -195,12 +183,10 @@ public class ProviderService { * @param topicName * Topic name to add * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failed to add topic */ - public int registerTopic(String topicName) throws NSException { - return nativeRegisterTopic(topicName); + public void registerTopic(String topicName) throws NSException { + nativeRegisterTopic(topicName); } /** @@ -209,19 +195,15 @@ public class ProviderService { * @param topicName * Topic name to add * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL - * * @throws NSException failed to delete topic */ - public int unregisterTopic(String topicName) throws NSException { - return nativeUnregisterTopic(topicName); + public void unregisterTopic(String topicName) throws NSException { + nativeUnregisterTopic(topicName); } /** * Request topics list already registered by provider user * - * - * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL * * @throws NSException failed to get topics list */ @@ -260,33 +242,33 @@ public class ProviderService { public void onMessageSynchronized(SyncInfo syncInfo); } - public native int nativeStart( + public native void nativeStart( OnConsumerSubscribedListener subscribedListener, OnMessageSynchronizedListener messageSynchronized, boolean subControllability, String userInfo, boolean resourceSecurity) throws NSException; - public native int nativeStop() throws NSException; + public native void nativeStop() throws NSException; - public native int nativeSendMessage(Message message) throws NSException; + public native void nativeSendMessage(Message message) throws NSException; public native void nativeSendSyncInfo(long messageId, int type) throws NSException; public native Message nativeCreateMessage() throws NSException; - public native int nativeEnableRemoteService(String servAdd) + public native void nativeEnableRemoteService(String servAdd) throws NSException; - public native int nativeDisableRemoteService(String servAdd) + public native void nativeDisableRemoteService(String servAdd) throws NSException; - public native int nativeSubscribeMQService(String servAdd, String topicName) + public native void nativeSubscribeMQService(String servAdd, String topicName) throws NSException; - public native int nativeRegisterTopic(String topicName) throws NSException; + public native void nativeRegisterTopic(String topicName) throws NSException; - public native int nativeUnregisterTopic(String topicName) + public native void 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 85550e7..03191eb 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 @@ -1027,7 +1027,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nat return; } -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService (JNIEnv *env, jobject jObj, jstring jServerAddress) { @@ -1035,7 +1035,7 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService if (!jServerAddress) { ThrowNSException(JNI_INVALID_VALUE, "EnableRemoteService server address NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *serverAddress = env->GetStringUTFChars(jServerAddress, 0); OIC::Service::NSResult result = @@ -1044,14 +1044,14 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to EnableRemoteService"); - return (jint) result; + return; } env->ReleaseStringUTFChars(jServerAddress, serverAddress); LOGD (TAG,"ConsumerService_EnableRemoteService - OUT"); - return (jint) result; + return; } -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeSubscribeMQService (JNIEnv *env, jobject jObj, jstring jserverAddress, jstring jTopicName) { @@ -1059,12 +1059,12 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeSubscribeMQService if (!jserverAddress) { ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } if (!jTopicName) { ThrowNSException(JNI_INVALID_VALUE, "TopicName Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *address = env->GetStringUTFChars( jserverAddress, NULL); @@ -1078,12 +1078,12 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeSubscribeMQService if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Subscribe to MQ Service"); - return (jint) result; + return; } env->ReleaseStringUTFChars(jserverAddress, address); env->ReleaseStringUTFChars(jTopicName, topic); LOGD (TAG,"ConsumerService: nativeSubscribeMQService - OUT"); - return (jint) result; + return; } JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeRescanProvider @@ -1373,34 +1373,34 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeG return obj_topicList; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpdateTopicList +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpdateTopicList (JNIEnv *env, jobject jObj, jobject jTopicsList) { LOGD (TAG,"Provider_nativeUpdateTopicList -IN"); if (!jTopicsList) { ThrowNSException(JNI_INVALID_VALUE, "TopicList cannot be null"); - return (jint) OIC::Service::NSResult::ERROR; + return; } OIC::Service::NSTopicsList *nsTopicsList = getNativeTopicsList(env, jTopicsList); if (nsTopicsList == nullptr) { ThrowNSException(JNI_INVALID_VALUE, "NSTopicList cannot be created "); - return (jint) OIC::Service::NSResult::ERROR; + return; } jclass providerClass = env->GetObjectClass(jObj); if (!providerClass) { ThrowNSException(JNI_INVALID_VALUE, "Failed to Get ObjectClass for Provider"); - return (jint) OIC::Service::NSResult::ERROR; + return; } jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J"); if (!nativeHandle) { ThrowNSException(JNI_INVALID_VALUE, "Failed to get nativeHandle for Provider"); - return (jint) OIC::Service::NSResult::ERROR; + return; } jlong jProvider = env->GetLongField(jObj, nativeHandle); OIC::Service::NSResult result = OIC::Service::NSResult::ERROR; @@ -1416,7 +1416,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpda if (provider == nullptr) { ThrowNSException(JNI_INVALID_VALUE, "Provider with Given Id doesn't exist"); - return (jint) OIC::Service::NSResult::ERROR; + return; } LOGD (TAG,"calling subscribe on ProviderID"); result = provider->updateTopicList(nsTopicsList); @@ -1424,10 +1424,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpda if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Update Interest Topics"); - return (jint) result; + return; } LOGD (TAG,"Provider_nativeUpdateTopicList -OUT"); - return (jint) result; + return; } JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetProviderState 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 bd24deb..57e6b8d 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 @@ -47,18 +47,18 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nat /* * Class: org_iotivity_service_ns_consumer_ConsumerService * Method: nativeEnableRemoteService - * Signature: (Ljava/lang/String;)I + * Signature: (Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService (JNIEnv *, jobject, jstring); /* * Class: org_iotivity_service_ns_consumer_ConsumerService * Method: nativeSubscribeMQService - * Signature: (Ljava/lang/String;Ljava/lang/String;)I + * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeSubscribeMQService (JNIEnv *, jobject, jstring, jstring); @@ -114,9 +114,9 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeG /* * Class: org_iotivity_service_ns_consumer_Provider * Method: nativeUpdateTopicList - * Signature: (Lorg/iotivity/service/ns/common/TopicsList;)I + * Signature: (Lorg/iotivity/service/ns/common/TopicsList;)V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpdateTopicList +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpdateTopicList (JNIEnv *, jobject, jobject); /* 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 4673a3e..cb6360c 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 @@ -870,7 +870,7 @@ void onSyncInfoListenerCb(OIC::Service::NSSyncInfo *sync) } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart (JNIEnv *env, jobject jObj, jobject jSubscriptionListener, jobject jSyncListener, jboolean jPolicy, jstring jUserInfo, jboolean jResourceSecurity) { @@ -878,7 +878,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat if (!jSubscriptionListener || !jSyncListener) { ThrowNSException(JNI_INVALID_VALUE, "Listener cannot be null"); - return (jint) OIC::Service::NSResult::ERROR; + return; } if (g_obj_subscriptionListener != NULL) @@ -911,14 +911,14 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to start NSProviderService"); - + return; } LOGD (TAG,"JNIProviderService: nativeStart - OUT"); - return (jint) result; + return; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop (JNIEnv *env, jobject jObj) { LOGD (TAG,"JNIProviderService: nativeStop - IN"); @@ -927,7 +927,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to stop NSProviderService"); - return (jint) result; + return; } env->DeleteGlobalRef( g_obj_subscriptionListener); @@ -936,32 +936,33 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat g_obj_syncListener = NULL; LOGD (TAG,"JNIProviderService: nativeStop - OUT"); - return (jint) result; + return; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage (JNIEnv *env, jobject jObj, jobject jMsg) { LOGD (TAG,"JNIProviderService: nativeSendMessage - IN"); if (!jMsg) { ThrowNSException(JNI_INVALID_VALUE, "Message cannot be null"); - return (jint) OIC::Service::NSResult::ERROR; + return; } OIC::Service::NSMessage *nsMsg = getNativeMessage(env, jMsg); if (nsMsg == nullptr) { ThrowNSException(JNI_INVALID_VALUE, "Message didn't have a field ID "); - return (jint) OIC::Service::NSResult::ERROR; + return; } OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->sendMessage(nsMsg); if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to send NSProvider Message"); + return; } LOGD (TAG,"JNIProviderService: nativeSendMessage - OUT"); - return (jint) result; + return; } JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendSyncInfo @@ -1000,7 +1001,7 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_ return jMsg; } -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService (JNIEnv *env, jobject jObj, jstring jstr) { @@ -1008,7 +1009,7 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService if (!jstr) { ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *address = env->GetStringUTFChars( jstr, NULL); @@ -1019,13 +1020,14 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Enable Remote Service"); + return; } env->ReleaseStringUTFChars(jstr, address); LOGD (TAG,"JNIProviderService: nativeEnableRemoteService - OUT"); - return (jint) result; + return; } -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService (JNIEnv *env, jobject jObj, jstring jstr) { @@ -1033,7 +1035,7 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService if (!jstr) { ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *address = env->GetStringUTFChars( jstr, NULL); @@ -1044,13 +1046,14 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Disable Remote Service"); + return; } env->ReleaseStringUTFChars(jstr, address); LOGD (TAG,"JNIProviderService: nativeDisableRemoteService - OUT"); - return (jint) result; + return; } -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSubscribeMQService (JNIEnv *env, jobject jObj, jstring jserverAddress, jstring jTopicName) { @@ -1058,12 +1061,12 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeSubscribeMQService if (!jserverAddress) { ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } if (!jTopicName) { ThrowNSException(JNI_INVALID_VALUE, "TopicName Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *address = env->GetStringUTFChars( jserverAddress, NULL); @@ -1077,21 +1080,22 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeSubscribeMQService if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Subscribe to MQ Service"); + return; } env->ReleaseStringUTFChars(jserverAddress, address); env->ReleaseStringUTFChars(jTopicName, topic); LOGD (TAG,"JNIProviderService: nativeSubscribeMQService - OUT"); - return (jint) result; + return; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic (JNIEnv *env, jobject jObj, jstring jTopicName) { LOGD (TAG,"JNIProviderService: nativeRegisterTopic - IN"); if (!jTopicName) { ThrowNSException(JNI_INVALID_VALUE, "Topic Name Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *name = env->GetStringUTFChars( jTopicName, NULL); std::string topicName(name); @@ -1100,19 +1104,20 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Register Topic"); + return; } env->ReleaseStringUTFChars(jTopicName, name); LOGD (TAG,"JNIProviderService: nativeRegisterTopic - OUT"); - return (jint) result; + return; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic (JNIEnv *env, jobject jObj, jstring jTopicName) { LOGD (TAG,"JNIProviderService: nativeUnregisterTopic - IN"); if (!jTopicName) { ThrowNSException(JNI_INVALID_VALUE, "Topic Name Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *name = env->GetStringUTFChars( jTopicName, NULL); std::string topicName(name); @@ -1121,10 +1126,11 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Unregister Topic"); + return; } env->ReleaseStringUTFChars(jTopicName, name); LOGD (TAG,"JNIProviderService: nativeUnregisterTopic - OUT"); - return (jint) result; + return; } JNIEXPORT jobject JNICALL @@ -1148,14 +1154,14 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeGetRegisteredTopicLi return obj_topicList; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription (JNIEnv *env, jobject jObj, jstring jConsumerId, jboolean jAccepted) { LOGD (TAG,"JNIProviderService: nativeAcceptSubscription - IN"); if (!jConsumerId) { ThrowNSException(JNI_INVALID_VALUE, "ConsumerId Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *id = env->GetStringUTFChars( jConsumerId, NULL); std::string consumerId(id); @@ -1169,21 +1175,21 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcce if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to acceptSubscription"); - return (jint) result; + return; } } LOGE (TAG,"Couldn't find consumer"); ThrowNSException(JNI_NO_NATIVE_POINTER, "Fail to find consumer"); - return (jint) OIC::Service::NSResult::ERROR; + return; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName) { LOGD (TAG,"JNIProviderService: nativeSetConsumerTopic - IN"); if (!jConsumerId || !jTopicName) { ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *name = env->GetStringUTFChars( jTopicName, NULL); const char *id = env->GetStringUTFChars( jConsumerId, NULL); @@ -1194,27 +1200,28 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetC if (!nsConsumer) { ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists"); - return (jint) OIC::Service::NSResult::ERROR; + return; } OIC::Service::NSResult result = nsConsumer->setTopic(topicName); if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Select Topic"); + return; } env->ReleaseStringUTFChars(jTopicName, name); env->ReleaseStringUTFChars(jConsumerId, id); LOGD (TAG,"JNIProviderService: nativeSetConsumerTopic - OUT"); - return (jint) result; + return; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName) { LOGD (TAG,"JNIProviderService: nativeUnsetConsumerTopic - IN"); if (!jConsumerId || !jTopicName) { ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL"); - return (jint) OIC::Service::NSResult::ERROR; + return; } const char *name = env->GetStringUTFChars( jTopicName, NULL); const char *id = env->GetStringUTFChars( jConsumerId, NULL); @@ -1225,18 +1232,19 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnse if (!nsConsumer) { ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists"); - return (jint) OIC::Service::NSResult::ERROR; + return; } OIC::Service::NSResult result = nsConsumer->unsetTopic(topicName); if (result != OIC::Service::NSResult::OK) { ThrowNSException((int) result, "Fail to Unselect Topic"); + return; } env->ReleaseStringUTFChars(jTopicName, name); env->ReleaseStringUTFChars(jConsumerId, id); LOGD (TAG,"JNIProviderService: nativeUnsetConsumerTopic - OUT"); - return (jint) result; + return; } JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeGetConsumerTopicList 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 index d72936d..f17d110 100755 --- a/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h +++ b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h @@ -30,25 +30,25 @@ extern "C" { /* * Class: org_iotivity_service_ns_provider_ProviderService * Method: nativeStart - * Signature: (Lorg/iotivity/service/ns/provider/ProviderService/OnConsumerSubscribedListener;Lorg/iotivity/service/ns/provider/ProviderService/OnMessageSynchronizedListener;ZLjava/lang/String;Z)I + * Signature: (Lorg/iotivity/service/ns/provider/ProviderService/OnConsumerSubscribedListener;Lorg/iotivity/service/ns/provider/ProviderService/OnMessageSynchronizedListener;ZLjava/lang/String;Z)V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart (JNIEnv *, jobject, jobject, jobject, jboolean, jstring, jboolean); /* * Class: org_iotivity_service_ns_provider_ProviderService * Method: nativeStop - * Signature: ()I + * Signature: ()V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop (JNIEnv *, jobject); /* * Class: org_iotivity_service_ns_provider_ProviderService * Method: nativeSendMessage - * Signature: (Lorg/iotivity/service/ns/common/Message;)I + * Signature: (Lorg/iotivity/service/ns/common/Message;)V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage (JNIEnv *, jobject, jobject); /* @@ -70,44 +70,44 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_ /* * Class: org_iotivity_service_ns_provider_ProviderService * Method: nativeEnableRemoteService - * Signature: (Ljava/lang/String;)I + * Signature: (Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService (JNIEnv *, jobject, jstring); /* * Class: org_iotivity_service_ns_provider_ProviderService * Method: nativeDisableRemoteService - * Signature: (Ljava/lang/String;)I + * Signature: (Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService (JNIEnv *, jobject, jstring); /* * Class: org_iotivity_service_ns_provider_ProviderService * Method: nativeSubscribeMQService - * Signature: (Ljava/lang/String;Ljava/lang/String;)I + * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL +JNIEXPORT void 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 + * Signature: (Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic (JNIEnv *, jobject, jstring); /* * Class: org_iotivity_service_ns_provider_ProviderService * Method: nativeUnregisterTopic - * Signature: (Ljava/lang/String;)I + * Signature: (Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic (JNIEnv *, jobject, jstring); /* @@ -122,25 +122,25 @@ Java_org_iotivity_service_ns_provider_ProviderService_nativeGetRegisteredTopicLi /* * Class: org_iotivity_service_ns_provider_Consumer * Method: nativeAcceptSubscription - * Signature: (Ljava/lang/String;Z)I + * Signature: (Ljava/lang/String;Z)V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription (JNIEnv *, jobject, jstring, jboolean); /* * Class: org_iotivity_service_ns_provider_Consumer * Method: nativeSetConsumerTopic - * Signature: (Ljava/lang/String;Ljava/lang/String;)I + * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic (JNIEnv *, jobject, jstring, jstring); /* * Class: org_iotivity_service_ns_provider_Consumer * Method: nativeUnsetConsumerTopic - * Signature: (Ljava/lang/String;Ljava/lang/String;)I + * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic (JNIEnv *, jobject, jstring, jstring); /* diff --git a/service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ExampleUnitTest.java b/service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ExampleUnitTest.java index 992c8c5..11ef47a 100755 --- a/service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ExampleUnitTest.java +++ b/service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ExampleUnitTest.java @@ -28,6 +28,8 @@ import org.iotivity.base.PlatformConfig; import org.iotivity.base.QualityOfService; import org.iotivity.base.ServiceType; import org.iotivity.service.ns.common.Message; +import org.iotivity.service.ns.common.NSException; +import org.iotivity.service.ns.common.NSErrorCode; import org.iotivity.service.ns.common.Topic; import org.iotivity.service.ns.common.TopicsList; import org.iotivity.service.ns.common.SyncInfo; @@ -429,8 +431,6 @@ public class ExampleUnitTest extends ApplicationTestCase { registerTopic("OIC_TOPIC1"); assertEquals(true, response.get()); - int result = 0; - try { TopicsList list = mProvider.getTopicList(); Iterator it = list.getTopicsList().iterator(); @@ -438,11 +438,11 @@ public class ExampleUnitTest extends ApplicationTestCase { Topic element = it.next(); element.setState(Topic.TopicState.SUBSCRIBED); } - result = mProvider.updateTopicList(list); - } catch (Exception e) { + mProvider.updateTopicList(list); + } catch (NSException e) { e.printStackTrace(); + assertEquals(NSErrorCode.ERROR, e.getErrorCode()); } - assertEquals(200, result); } @Test diff --git a/service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ProviderSimulator.java b/service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ProviderSimulator.java old mode 100644 new mode 100755 index 7190864..7a46eb8 --- a/service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ProviderSimulator.java +++ b/service/notification/examples/android/NotiConsumerExample/app/src/androidTest/java/org/iotivity/service/ns/sample/consumer/ProviderSimulator.java @@ -43,10 +43,10 @@ class ProviderSimulator public void onConsumerSubscribed(Consumer consumer) { gConsumer = consumer; try { - int result = gConsumer.acceptSubscription(true); - Log.i(TAG, "Notification AcceptSubscription: " + result); + gConsumer.acceptSubscription(true); + Log.i(TAG, "Notification AcceptSubscription" ); } catch (Exception e) { - + e.printStackTrace(); } } @@ -65,4 +65,4 @@ class ProviderSimulator return null; } -} \ No newline at end of file +} diff --git a/service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/ConsumerSample.java b/service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/ConsumerSample.java index bd21e4b..0e61948 100755 --- a/service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/ConsumerSample.java +++ b/service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/ConsumerSample.java @@ -113,17 +113,15 @@ public class ConsumerSample } } - public int subscribeMQService(String servAdd, String topicName) { + public void subscribeMQService(String servAdd, String topicName) { Log.i(TAG, "SubscribeMQService - IN"); - int result = 0; try { - result = consumerService.subscribeMQService(servAdd, topicName); - Log.i(TAG, "Notification SubscribeMQService: " + result); + consumerService.subscribeMQService(servAdd, topicName); } catch (Exception e) { Log.e(TAG, "Exception: subscribeMQService : " + e); } Log.i(TAG, "SubscribeMQService - OUT"); - return result; + return; } public void rescanProvider() { diff --git a/service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/MainActivity.java b/service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/MainActivity.java index 6a0b960..5348d8b 100755 --- a/service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/MainActivity.java +++ b/service/notification/examples/android/NotiConsumerExample/app/src/main/java/org/iotivity/service/ns/sample/consumer/MainActivity.java @@ -371,10 +371,9 @@ public class MainActivity extends Activity dialog.dismiss(); MQCloudAddress = ip.getText().toString(); MQCloudTopic = mqTopic.getText().toString(); - int result = mConsumerSample.subscribeMQService( + mConsumerSample.subscribeMQService( MQCloudAddress, MQCloudTopic); - TvLog.append("SubscribeMQService Result : " + result - + "\n"); + TvLog.append("SubscribeMQService success\n"); } }); dialog.show(); diff --git a/service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/org/iotivity/service/ns/sample/provider/ExampleUnitTest.java b/service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/org/iotivity/service/ns/sample/provider/ExampleUnitTest.java old mode 100644 new mode 100755 index cdd1ebf..701929b --- a/service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/org/iotivity/service/ns/sample/provider/ExampleUnitTest.java +++ b/service/notification/examples/android/NotiProviderExample/app/src/androidTest/java/org/iotivity/service/ns/sample/provider/ExampleUnitTest.java @@ -30,6 +30,8 @@ import org.iotivity.base.OcPlatform; import org.iotivity.base.PlatformConfig; import org.iotivity.base.QualityOfService; import org.iotivity.base.ServiceType; +import org.iotivity.service.ns.common.NSException; +import org.iotivity.service.ns.common.NSErrorCode; import org.iotivity.service.ns.common.SyncInfo; import org.iotivity.service.ns.common.Topic; @@ -152,38 +154,35 @@ public class ExampleUnitTest extends ApplicationTestCase { @Test public void StartProviderPositiveWithPolicyTrue() { - int result = 0; try { - result = gProviderRes.start(subCb, syncCb, true, "ok", false); + gProviderRes.start(subCb, syncCb, true, "ok", false); gProviderRes.stop(); - } catch (Exception e) { + } catch (NSException e) { e.printStackTrace(); + assertEquals(NSErrorCode.OK, e.getErrorCode()); } - assertEquals(100, result); } @Test public void StartProviderPositiveWithPolicyFalse() { - int result = 0; try { - result = gProviderRes.start(subCb, syncCb, false, "ok", false); + gProviderRes.start(subCb, syncCb, false, "ok", false); gProviderRes.stop(); - } catch (Exception e) { + } catch (NSException e) { e.printStackTrace(); + assertEquals(NSErrorCode.OK, e.getErrorCode()); } - assertEquals(100, result); } @Test public void StopProviderPositive() { - int result = 0; try { gProviderRes.start(subCb, syncCb, true, "ok", false); - result = gProviderRes.stop(); - } catch (Exception e) { + gProviderRes.stop(); + } catch (NSException e) { e.printStackTrace(); + assertEquals(NSErrorCode.OK, e.getErrorCode()); } - assertEquals(100, result); } @Test diff --git a/service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/MainActivity.java b/service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/MainActivity.java old mode 100644 new mode 100755 index ebfb568..b8ada11 --- a/service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/MainActivity.java +++ b/service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/MainActivity.java @@ -377,22 +377,18 @@ public class MainActivity extends Activity } if (gRemoteService) { TvLog.append("Enable Remote Service\n"); - int result = mProviderSample - .enableRemoteService(RemoteAddress); + mProviderSample.enableRemoteService(RemoteAddress); remoteService.setText(R.string.disableRemoteService); gRemoteService = false; remoteService.setEnabled(true); - TvLog.append("EnableRemoteService Result : " + result - + "\n"); + TvLog.append("EnableRemoteService success \n"); } else { TvLog.append("Disable Remote Service\n"); - int result = mProviderSample - .disableRemoteService(RemoteAddress); + mProviderSample.disableRemoteService(RemoteAddress); remoteService.setText(R.string.enableRemoteService); gRemoteService = true; remoteService.setEnabled(true); - TvLog.append("DisableRemoteService Result : " + result - + "\n"); + TvLog.append("DisableRemoteService success\n"); } } break; @@ -424,10 +420,9 @@ public class MainActivity extends Activity dialog.dismiss(); MQCloudAddress = ip.getText().toString(); MQCloudTopic = mqTopic.getText().toString(); - int result = mProviderSample.subscribeMQService( + mProviderSample.subscribeMQService( MQCloudAddress, MQCloudTopic); - TvLog.append("SubscribeMQService Result : " + result - + "\n"); + TvLog.append("SubscribeMQService success\n"); } }); dialog.show(); diff --git a/service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/ProviderSample.java b/service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/ProviderSample.java old mode 100644 new mode 100755 index 051fa6a..57e5be3 --- a/service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/ProviderSample.java +++ b/service/notification/examples/android/NotiProviderExample/app/src/main/java/org/iotivity/service/ns/sample/provider/ProviderSample.java @@ -96,54 +96,43 @@ public class ProviderSample configurePlatform(); gAcceptor = policy; try { - int result = ioTNotification.start(this, this, policy, "Info", - false); - Log.i(TAG, "Notification Start: " + result); + ioTNotification.start(this, this, policy, "Info", false); } catch (Exception e) { - + Log.e(TAG, "Exception: start : " + e); } - Log.i(TAG, "Start ProviderService - OUT"); } public void registerTopic() { Log.i(TAG, "Register Topics -IN"); try { - int result = ioTNotification.registerTopic("OCF_TOPIC1"); - Log.i(TAG, " RegisterTopic: " + result); - result = ioTNotification.registerTopic("OCF_TOPIC2"); - Log.i(TAG, " RegisterTopic: " + result); - result = ioTNotification.registerTopic("OCF_TOPIC3"); - Log.i(TAG, " RegisterTopic: " + result); - result = ioTNotification.registerTopic("OCF_TOPIC4"); - Log.i(TAG, " RegisterTopic: " + result); + ioTNotification.registerTopic("OCF_TOPIC1"); + ioTNotification.registerTopic("OCF_TOPIC2"); + ioTNotification.registerTopic("OCF_TOPIC3"); + ioTNotification.registerTopic("OCF_TOPIC4"); } catch (Exception e) { - + Log.e(TAG, "Exception: registerTopic : "+ e); } Log.i(TAG, "Start ProviderService - OUT"); } - public int setTopic() { + public void setTopic() { Log.i(TAG, "Set Topic -IN"); if (gConsumer == null) { - return 0; + return; } try { - int result = gConsumer.setTopic("OCF_TOPIC1"); - Log.i(TAG, " Set Topic : " + result); - result = gConsumer.setTopic("OCF_TOPIC2"); - Log.i(TAG, " Set Topic : " + result); - result = gConsumer.setTopic("OCF_TOPIC3"); - Log.i(TAG, " Set Topic : " + result); - result = gConsumer.setTopic("OCF_TOPIC4"); - Log.i(TAG, " Set Topic : " + result); + gConsumer.setTopic("OCF_TOPIC1"); + gConsumer.setTopic("OCF_TOPIC2"); + gConsumer.setTopic("OCF_TOPIC3"); + gConsumer.setTopic("OCF_TOPIC4"); } catch (Exception e) { - + Log.e(TAG, "Exception: setTopic : " + e); } - Log.i(TAG, "Start ProviderService - OUT"); - return 1; + Log.i(TAG, "setTopic ProviderService - OUT"); + return; } public void stop() { @@ -151,15 +140,12 @@ public class ProviderSample try { OcPlatform.stopPresence(); } catch (Exception e) { - Log.e(TAG, - "Exception: stopping presence when terminating NS server: " - + e); + Log.e(TAG,"Exception: stopping presence when terminating NS server: "+ e); } try { - int result = ioTNotification.stop(); - Log.i(TAG, "Notification Stop: " + result); + ioTNotification.stop(); } catch (Exception e) { - + Log.e(TAG, "Exception: stop : " + e); } Log.i(TAG, "Stop ProviderService - OUT"); @@ -169,10 +155,9 @@ public class ProviderSample Log.i(TAG, "SendMessage ProviderService - IN"); try { - int result = ioTNotification.sendMessage(notiMessage); - Log.i(TAG, "Notification Send Message: " + result); + ioTNotification.sendMessage(notiMessage); } catch (Exception e) { - + Log.e(TAG, "Exception: sendMessage : " + e); } Log.i(TAG, "SendMessage ProviderService - OUT"); @@ -193,7 +178,7 @@ public class ProviderSample ioTNotification.sendSyncInfo(messageId, syncType); Log.i(TAG, "Notification Sync "); } catch (Exception e) { - + Log.e(TAG, "Exception: sendSyncInfo : " + e); } Log.i(TAG, "SendSyncInfo ProviderService - OUT"); msgMap.put("ID: " + messageId, SYNC_READ); @@ -201,52 +186,45 @@ public class ProviderSample } } - public int enableRemoteService(String servAdd) { + public void enableRemoteService(String servAdd) { Log.i(TAG, "EnableRemoteService ProviderService - IN"); - int result = 0; try { - result = ioTNotification.enableRemoteService(servAdd); - Log.i(TAG, "Notification EnableRemoteService: " + result); + ioTNotification.enableRemoteService(servAdd); } catch (Exception e) { - + Log.e(TAG, "Exception: enableRemoteService : " + e); } Log.i(TAG, "EnableRemoteService ProviderService - OUT"); - return result; + return; } - public int disableRemoteService(String servAdd) { + public void disableRemoteService(String servAdd) { Log.i(TAG, "DisableRemoteService ProviderService - IN"); - int result = 0; try { - result = ioTNotification.disableRemoteService(servAdd); - Log.i(TAG, "Notification DisableRemoteService: " + result); + ioTNotification.disableRemoteService(servAdd); } catch (Exception e) { - + Log.e(TAG, "Exception: disableRemoteService : " + e); } Log.i(TAG, "DisableRemoteService ProviderService - OUT"); - return result; + return; } - public int subscribeMQService(String servAdd, String topicName) { + public void subscribeMQService(String servAdd, String topicName) { Log.i(TAG, "SubscribeMQService ProviderService - IN"); - int result = 0; try { - result = ioTNotification.subscribeMQService(servAdd, topicName); - Log.i(TAG, "Notification SubscribeMQService: " + result); + ioTNotification.subscribeMQService(servAdd, topicName); } catch (Exception e) { Log.e(TAG, "Exception: subscribeMQService : " + e); } Log.i(TAG, "SubscribeMQService ProviderService - OUT"); - return result; + return; } public void acceptSubscription(Consumer consumer, boolean accepted) { Log.i(TAG, "AcceptSubscription ProviderService - IN"); try { - int result = consumer.acceptSubscription(accepted); - Log.i(TAG, "Notification AcceptSubscription: " + result); + consumer.acceptSubscription(accepted); } catch (Exception e) { - + Log.e(TAG, "Exception: acceptSubscription : " + e); } Log.i(TAG, "AcceptSubscription ProviderService - OUT"); } -- 2.7.4