From: nikhil.a Date: Sat, 3 Sep 2016 13:33:53 +0000 (+0530) Subject: Updated Android for new API Changes X-Git-Tag: 1.2.0+RC3~204^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=327f7b6845abe5a9129854ef7cc585d710446a2a;p=platform%2Fupstream%2Fiotivity.git Updated Android for new API Changes 1. Modified the Consumer and Provider design and callbacks mechanism in JAVA and JNI. 2. Updated the API name changes. 3. Refracted the code Change-Id: I51ea2eab73b575e67f336c46af9d330d0f8f8941 Signed-off-by: nikhil.a Reviewed-on: https://gerrit.iotivity.org/gerrit/11355 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- 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 88a7e01..7641ccc 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 @@ -46,24 +46,6 @@ public class ConsumerService System.loadLibrary("notification_consumer_jni"); } - public enum Response - { - ALLOW(1), - DENY(2), - TOPIC(3); - private int type; - - private Response(int type) - { - this.type = type; - } - - public int getResponseType() - { - return this.type; - } - }; - private static ConsumerService instance; static { @@ -74,57 +56,38 @@ public class ConsumerService return instance; } - public void Start( - OnProviderDiscoveredListner onProviderDiscoveredListner, - OnProviderChangedListener onProviderChangedListener + public void start( + OnProviderDiscoveredListener onProviderDiscoveredListener ) throws NSException { - nativeStart(onProviderDiscoveredListner, onProviderChangedListener); + nativeStart(onProviderDiscoveredListener); } - public void Stop() throws NSException + public void stop() throws NSException { nativeStop(); } - public void EnableRemoteService(String serverAddress) throws NSException + public void enableRemoteService(String serverAddress) throws NSException { nativeEnableRemoteService(serverAddress); } - public void RescanProvider() throws NSException + public void rescanProvider() throws NSException { nativeRescanProvider(); } - public Provider GetProvider(String providerId) throws NSException - { - return nativeGetProvider(providerId); - } - - public Message GetMessage(long messageId) throws NSException - { - return nativeGetMessage(messageId); - } - - public interface OnProviderDiscoveredListner + public interface OnProviderDiscoveredListener { public void onProviderDiscovered(Provider provider); } - public interface OnProviderChangedListener - { - public void onProviderChanged(Provider provider , Response response); - } - private native void nativeStart ( - OnProviderDiscoveredListner onProviderDiscoveredListner, - OnProviderChangedListener onProviderChangedListener + OnProviderDiscoveredListener onProviderDiscoveredListener ) throws NSException; private native void nativeStop() throws NSException; private native void nativeEnableRemoteService(String serverAddress) throws NSException; private native void nativeRescanProvider() throws NSException; - private native Provider nativeGetProvider(String providerId) throws NSException; - private native Message nativeGetMessage(long messageId) 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 622a09b..69e410e 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 @@ -32,8 +32,26 @@ public class Provider { private static final String LOG_TAG = "ConsumerService_Provider"; + public enum ProviderState + { + ALLOW(1), + DENY(2), + TOPIC(3), + STOPPED(12); + private int state; + + private ProviderState(int state) + { + this.state = state; + } + + public int getProviderState() + { + return this.state; + } + }; + public String mProviderId = null; - TopicsList mTopicsList = new TopicsList(); private long mNativeHandle = 0; public Provider(String providerId) @@ -48,35 +66,46 @@ public class Provider return mProviderId ; } - public TopicsList getTopicsList() + public TopicsList getTopicList() throws NSException + { + return nativeGetTopicList(); + } + + public ProviderState getProviderState() throws NSException { - return mTopicsList ; + return nativeGetProviderState(); } - public void Subscribe() throws NSException + public void subscribe() throws NSException { nativeSubscribe(); } - public void Unsubscribe() throws NSException + public boolean isSubscribed () throws NSException { - nativeUnsubscribe(); + return nativeIsSubscribed(); } - public void SendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException + public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException { nativeSendSyncInfo(messageId, syncType.ordinal()); } - public void SetListener(OnMessageReceivedListner onMessageReceivedListner, + public void setListener(OnProviderStateListener onProviderStateListener, + OnMessageReceivedListner onMessageReceivedListner, OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException { - nativeSetListener(onMessageReceivedListner, onSyncInfoReceivedListner); + nativeSetListener(onProviderStateListener, onMessageReceivedListner, onSyncInfoReceivedListner); } - public int SelectInterestTopics(TopicsList topicsList) throws NSException + public int updateTopicList(TopicsList topicsList) throws NSException { - return nativeSelectInterestTopics(topicsList); + return nativeUpdateTopicList(topicsList); + } + + public interface OnProviderStateListener + { + public void onProviderStateReceived(ProviderState state); } public interface OnMessageReceivedListner @@ -90,11 +119,13 @@ public class Provider } private native void nativeSubscribe() throws NSException; - private native void nativeUnsubscribe() throws NSException; private native void nativeSendSyncInfo(long messageId, int syncType) throws NSException; - private native void nativeSetListener( - OnMessageReceivedListner onMessageReceivedListner, - OnSyncInfoReceivedListner onSyncInfoReceivedListner - ) throws NSException; - private native int nativeSelectInterestTopics(TopicsList topicsList) throws NSException; + private native void nativeSetListener(OnProviderStateListener onProviderStateListener, + OnMessageReceivedListner onMessageReceivedListner, + OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException; + public native TopicsList nativeGetTopicList() throws NSException; + private native int nativeUpdateTopicList(TopicsList topicsList) throws NSException; + private native ProviderState nativeGetProviderState() throws NSException; + public native boolean nativeIsSubscribed() 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 37e2417..a711b2c 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 @@ -33,33 +33,34 @@ public class Consumer { mConsumerId = consumerId; } + public String getConsumerId( ) { return mConsumerId; } - public int AcceptSubscription(Consumer consumer, boolean accepted) throws NSException + + public int acceptSubscription(boolean accepted) throws NSException { - if (consumer != null) - return nativeAcceptSubscription(consumer, accepted); - return -1; + return nativeAcceptSubscription(mConsumerId, accepted); } - public int SelectTopic(String topicName) throws NSException + public int setTopic(String topicName) throws NSException { - return nativeSelectTopic(mConsumerId, topicName); + return nativeSetConsumerTopic(mConsumerId, topicName); } - public int UnselectTopic(String topicName) throws NSException + + public int unsetTopic(String topicName) throws NSException { - return nativeUnselectTopic(mConsumerId, topicName); + return nativeUnsetConsumerTopic(mConsumerId, topicName); } - public TopicsList GetConsumerTopics() throws NSException + public TopicsList getConsumerTopicList() throws NSException { - return nativeGetConsumerTopics(mConsumerId); + return nativeGetConsumerTopicList(mConsumerId); } - public native int nativeAcceptSubscription(Consumer consumer, boolean accepted); - public native int nativeSelectTopic(String consumerId, String topicName); - public native int nativeUnselectTopic(String consumerId, String topicName); - public native TopicsList nativeGetConsumerTopics(String consumerId); + public native int nativeAcceptSubscription(String consumerId, boolean accepted) throws NSException; + public native int nativeSetConsumerTopic(String consumerId, String topicName) throws NSException; + public native int nativeUnsetConsumerTopic(String consumerId, String topicName) throws NSException; + public native TopicsList nativeGetConsumerTopicList(String consumerId) throws NSException; } \ No newline at end of file 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 eb8f30a..428b022 100644 --- 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 @@ -47,81 +47,84 @@ public class ProviderService { instance = new ProviderService(); } - public interface OnSubscriptionListener - { - public void onConsumerSubscribed(Consumer consumer); - } - public interface OnSyncInfoListener - { - public void onMessageSynchronized(SyncInfo syncInfo); - } public static ProviderService getInstance() { return instance; } - public int Start(boolean policy, - OnSubscriptionListener subscriptionListener, - OnSyncInfoListener syncInfoListener) throws NSException - { - return nativeStart(policy, subscriptionListener, syncInfoListener); + public int start(OnConsumerSubscribedListener subscribedListener, + OnMessageSynchronizedListener messageSynchronized, + boolean subControllability, String userInfo) throws NSException + { + return nativeStart(subscribedListener, messageSynchronized,subControllability,userInfo); } - public int Stop() throws NSException + public int stop() throws NSException { return nativeStop(); } - public int SendMessage(Message message) throws NSException + public int sendMessage(Message message) throws NSException { return nativeSendMessage(message); } - public void SendSyncInfo ( long messageId , SyncInfo.SyncType syncType) throws NSException + public void sendSyncInfo ( long messageId , SyncInfo.SyncType syncType) throws NSException { nativeSendSyncInfo(messageId, syncType.ordinal()); - return; } - public Message CreateMessage () throws NSException + public Message createMessage () throws NSException { return nativeCreateMessage(); } - public int EnableRemoteService(String servAdd) throws NSException + public int enableRemoteService(String servAdd) throws NSException { return nativeEnableRemoteService(servAdd); } - public int DisableRemoteService(String servAdd) throws NSException + public int disableRemoteService(String servAdd) throws NSException { return nativeDisableRemoteService(servAdd); } - public int AddTopic(String topicName) throws NSException + public int registerTopic(String topicName) throws NSException + { + return nativeRegisterTopic(topicName); + } + + public int unregisterTopic(String topicName) throws NSException { - return nativeAddTopic(topicName); + return nativeUnregisterTopic(topicName); } - public int DeleteTopic(String topicName) throws NSException + + public TopicsList getRegisteredTopicList() throws NSException { - return nativeDeleteTopic(topicName); + return nativeGetRegisteredTopicList(); } - public TopicsList GetTopics() throws NSException + + public interface OnConsumerSubscribedListener { - return nativeGetTopics(); + public void onConsumerSubscribed(Consumer consumer); + } + + public interface OnMessageSynchronizedListener + { + public void onMessageSynchronized(SyncInfo syncInfo); } - public native int nativeStart(boolean policy, - OnSubscriptionListener subscriptionListener, - OnSyncInfoListener syncInfoListener); - public native int nativeStop(); - public native int nativeSendMessage(Message message); - public native void nativeSendSyncInfo( long messageId , int type); - public native Message nativeCreateMessage(); - public native int nativeEnableRemoteService(String servAdd); - public native int nativeDisableRemoteService(String servAdd); - public native int nativeAddTopic(String topicName); - public native int nativeDeleteTopic(String topicName); - public native TopicsList nativeGetTopics(); + public native int nativeStart(OnConsumerSubscribedListener subscribedListener, + OnMessageSynchronizedListener messageSynchronized, + boolean subControllability, String userInfo) throws NSException; + public native int nativeStop() throws NSException; + public native int 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) throws NSException; + public native int nativeDisableRemoteService(String servAdd) 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 b7396ad..2b85992 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 @@ -24,8 +24,8 @@ static JavaVM *g_jvm = NULL; static jobject g_obj_postListener = NULL; -static jobject g_obj_discoverListener = NULL; static jobject g_obj_syncListener = NULL; +static jobject g_obj_discoverListener = NULL; static jobject g_obj_acceptListener = NULL; jclass g_cls_Message; @@ -35,7 +35,7 @@ jclass g_cls_SyncType; jclass g_cls_MediaContents; jclass g_cls_TopicState; jclass g_cls_Message_Type; -jclass g_cls_Response; +jclass g_cls_ProviderState; jclass g_cls_Topic; jclass g_cls_TopicsList; @@ -66,33 +66,39 @@ static JNIEnv *GetJNIEnv(jint *ret) } } -jobject getJavaResponse(JNIEnv *env, OIC::Service::NSResponse response) +jobject getJavaProviderState(JNIEnv *env, OIC::Service::NSProviderState state) { - LOGD ("ConsumerService_getJavaResponse - IN"); - switch (response) + LOGD ("ConsumerService_getJavaProviderState - IN"); + switch (state) { - case OIC::Service::NSResponse::ALLOW: + case OIC::Service::NSProviderState::ALLOW: + { + static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState, + "ALLOW", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;"); + return env->GetStaticObjectField(g_cls_ProviderState, fieldID); + } + case OIC::Service::NSProviderState::DENY: { - static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response, - "ALLOW", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;"); - return env->GetStaticObjectField(g_cls_Response, fieldID); + static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState, + "DENY", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;"); + return env->GetStaticObjectField(g_cls_ProviderState, fieldID); } - case OIC::Service::NSResponse::DENY: + case OIC::Service::NSProviderState::TOPIC: { - static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response, - "DENY", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;"); - return env->GetStaticObjectField(g_cls_Response, fieldID); + static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState, + "TOPIC", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;"); + return env->GetStaticObjectField(g_cls_ProviderState, fieldID); } - case OIC::Service::NSResponse::TOPIC: + case OIC::Service::NSProviderState::STOPPED: { - static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response, - "TOPIC", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;"); - return env->GetStaticObjectField(g_cls_Response, fieldID); + static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState, + "STOPPED", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;"); + return env->GetStaticObjectField(g_cls_ProviderState, fieldID); } default: return NULL; } - LOGD ("ConsumerService_getJavaResponse - OUT"); + LOGD ("ConsumerService_getJavaProviderState - OUT"); return NULL; } @@ -427,15 +433,6 @@ jobject getJavaProvider(JNIEnv *env, OIC::Service::NSProvider *provider) } env->SetLongField(obj_provider, nativeHandle, pProvider); - jfieldID fid_topic = env->GetFieldID(cls_provider, "mTopicsList", - "Lorg/iotivity/service/ns/common/TopicsList;"); - if (!fid_topic) - { - LOGE("Failed to get TopicList for Provider"); - return NULL; - } - jobject topicList = getJavaTopicsList(env, provider->getTopicList()); - env->SetObjectField(obj_provider, fid_topic, topicList); env->DeleteLocalRef(cls_provider); LOGD ("ConsumerService_getJavaProvider - OUT"); return obj_provider; @@ -666,9 +663,9 @@ void onDiscoverProvider(OIC::Service::NSProvider *provider) return ; } -void onProviderChanged(OIC::Service::NSProvider *provider, OIC::Service::NSResponse response) +void onProviderState( OIC::Service::NSProviderState state) { - LOGD ("ConsumerService_onProviderChanged -IN"); + LOGD ("ConsumerService_onProviderState -IN"); jint envRet; JNIEnv *env = GetJNIEnv(&envRet); @@ -681,10 +678,10 @@ void onProviderChanged(OIC::Service::NSProvider *provider, OIC::Service::NSRespo if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); return ; } - jobject obj_provider = getJavaProvider(env, provider); - if (!obj_provider) + jobject obj_state = getJavaProviderState(env, state); + if (!obj_state) { - LOGE ("Failed to Get Provider Object"); + LOGE ("Failed to Get ProviderState Object"); if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); return ; } @@ -698,20 +695,19 @@ void onProviderChanged(OIC::Service::NSProvider *provider, OIC::Service::NSRespo } jmethodID mid = env->GetMethodID( cls, - "onProviderChanged", - "(Lorg/iotivity/service/ns/consumer/Provider;Lorg/iotivity/service/ns/consumer/ConsumerService$Response;)V"); + "onProviderStateReceived", + "(Lorg/iotivity/service/ns/consumer/Provider$ProviderState;)V"); if (!mid) { - LOGE ("Failed to Get MethodID for onProviderChanged"); + LOGE ("Failed to Get MethodID for onProviderState"); if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); return ; } - jobject obj_response = getJavaResponse(env, response); - env->CallVoidMethod(jAcceptListener, mid, obj_provider, obj_response); + env->CallVoidMethod(jAcceptListener, mid, obj_state); env->DeleteLocalRef(jAcceptListener); if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - LOGD ("ConsumerService_onProviderChanged -OUT"); + LOGD ("ConsumerService_onProviderState -OUT"); return ; } @@ -849,32 +845,21 @@ void onSyncInfoReceived(OIC::Service::NSSyncInfo *sync) } JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStart -(JNIEnv *env, jobject jObj, jobject jDiscoverListener, jobject jAccpetListener) +(JNIEnv *env, jobject jObj, jobject jDiscoverListener) { LOGD ("ConsumerService_StartConsumer - IN"); - if (!jDiscoverListener || !jAccpetListener) + if (!jDiscoverListener) { ThrowNSException(NS_ERROR, "Listener cannot be null"); return ; } - if (g_obj_discoverListener != NULL) { env->DeleteGlobalRef(g_obj_discoverListener); } - if (g_obj_acceptListener != NULL) - { - env->DeleteGlobalRef(g_obj_acceptListener); - } - g_obj_discoverListener = (jobject) env->NewGlobalRef(jDiscoverListener); - g_obj_acceptListener = (jobject) env->NewGlobalRef(jAccpetListener); - OIC::Service::NSConsumerService::ConsumerConfig cfg; - cfg.m_discoverCb = onDiscoverProvider; - cfg.m_changedCb = onProviderChanged; - - OIC::Service::NSConsumerService::getInstance()->Start(cfg); + OIC::Service::NSConsumerService::getInstance()->start(onDiscoverProvider); LOGD ("ConsumerService_StartConsumer - OUT"); return; @@ -886,14 +871,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nat LOGD ("ConsumerService_StopConsumer - IN"); env->DeleteGlobalRef(g_obj_postListener); - env->DeleteGlobalRef(g_obj_discoverListener); env->DeleteGlobalRef(g_obj_syncListener); + env->DeleteGlobalRef(g_obj_discoverListener); env->DeleteGlobalRef(g_obj_acceptListener); g_obj_postListener = NULL; - g_obj_discoverListener = NULL; g_obj_syncListener = NULL; + g_obj_discoverListener = NULL; g_obj_acceptListener = NULL; - OIC::Service::NSConsumerService::getInstance()->Stop(); + OIC::Service::NSConsumerService::getInstance()->stop(); LOGD ("ConsumerService_StopConsumer - OUT"); return; } @@ -910,7 +895,7 @@ Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService } const char *serverAddress = env->GetStringUTFChars(jServerAddress, 0); OIC::Service::NSResult res = - OIC::Service::NSConsumerService::getInstance()->EnableRemoteService(std::string(serverAddress)); + OIC::Service::NSConsumerService::getInstance()->enableRemoteService(std::string(serverAddress)); env->ReleaseStringUTFChars(jServerAddress, serverAddress); LOGD ("ConsumerService_EnableRemoteService - OUT"); return (jint) res; @@ -920,87 +905,12 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nat (JNIEnv *env, jobject jObj) { LOGD ("ConsumerService_RescanProvider - IN"); - OIC::Service::NSConsumerService::getInstance()->RescanProvider(); + OIC::Service::NSConsumerService::getInstance()->rescanProvider(); LOGD ("ConsumerService_RescanProvider - OUT"); return; } -JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetProvider -(JNIEnv *env, jobject jObj, jstring jProviderId) -{ - LOGD ("ConsumerService_GetProvider - IN"); - if (!jProviderId) - { - ThrowNSException(NS_ERROR, "ProviderId cannot be null"); - return NULL; - } - - const char *providerId = env->GetStringUTFChars(jProviderId, 0); - LOGD ("java_ProviderId : %s\n", providerId); - - OIC::Service::NSProvider *provider = - OIC::Service::NSConsumerService::getInstance()->getProvider(std::string(providerId)); - if (provider == nullptr) - { - ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist"); - return NULL; - } - LOGD ("native_ProviderId : %s\n", provider->getProviderId().c_str()); - - jProviderId = env->NewStringUTF(provider->getProviderId().c_str()); - jlong pProvider = (long)provider; - - jclass cls_provider = (jclass) (env->NewLocalRef(g_cls_Provider)); - if (!cls_provider) - { - LOGE ("Failed to Get ObjectClass for Provider"); - ThrowNSException(NS_ERROR, "Couldn't find objectClass for Provider"); - return NULL; - } - jmethodID mid_provider = env->GetMethodID( - cls_provider, "", "(Ljava/lang/String;)V"); - if (!mid_provider) - { - LOGE ("Failed to Get MethodID for Provider"); - ThrowNSException(NS_ERROR, "Couldn't find MethodID for Provider"); - return NULL; - } - jobject obj_provider = env->NewObject(cls_provider, mid_provider, - jProviderId); - - jfieldID nativeHandle = env->GetFieldID(cls_provider, "mNativeHandle", "J"); - if (!nativeHandle) - { - ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider"); - return NULL; - } - env->SetLongField(obj_provider, nativeHandle, pProvider); - - env->DeleteLocalRef(cls_provider); - env->ReleaseStringUTFChars(jProviderId, providerId); - LOGD ("ConsumerService_GetProvider - OUT"); - return obj_provider; -} - -JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetMessage -(JNIEnv *env, jobject jObj, jlong jMsgId) -{ - LOGI("JNIConsumerService: nativeGetMessage - IN"); - - OIC::Service::NSMessage *msg = - OIC::Service::NSConsumerService::getInstance()->getMessage((uint64_t)jMsgId); - if (msg == nullptr) - { - ThrowNSException(NS_ERROR, "Message doesn't exist"); - return NULL; - } - - jobject obj_msg = getJavaMessage(env, msg); - - LOGI("JNIConsumerService: nativeGetMessage - OUT"); - return obj_msg; -} JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSubscribe (JNIEnv *env, jobject jObj) { @@ -1040,46 +950,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSubs return; } -JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUnsubscribe -(JNIEnv *env, jobject jObj) -{ - LOGD ("Provider_Unsubscribe - IN"); - - jclass providerClass = env->GetObjectClass(jObj); - if (!providerClass) - { - ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider"); - return ; - } - - jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J"); - if (!nativeHandle) - { - ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider"); - return ; - } - jlong jProvider = env->GetLongField(jObj, nativeHandle); - if (jProvider) - { - LOGD ("calling unSubscribe on mNativeHandle"); - OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider); - provider->unSubscribe(); - } - else - { - OIC::Service::NSProvider *provider = getNativeProvider(env, jObj); - if (provider == nullptr) - { - ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist"); - return; - } - LOGD ("calling unSubscribe on ProviderID"); - provider->unSubscribe(); - } - LOGD ("Provider_Unsubscribe - IN"); - return; -} - JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSendSyncInfo (JNIEnv *env, jobject jObj, jlong jMessageId, jint jSyncType) { @@ -1113,7 +983,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSend { LOGD ("calling SendSyncInfo on mNativeHandle"); OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider); - provider->SendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType); + provider->sendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType); } else { @@ -1124,7 +994,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSend return; } LOGD ("calling SendSyncInfo on ProviderID"); - provider->SendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType); + provider->sendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType); } LOGD ("Provider_SendSyncInfo - OUT"); return; @@ -1132,10 +1002,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSend JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetListener -(JNIEnv *env, jobject jObj, jobject jPostListener, jobject jSyncListener) +(JNIEnv *env, jobject jObj, jobject jAcceptListener, jobject jPostListener, jobject jSyncListener) { LOGD ("Provider_SetListener - IN"); - if (!jPostListener || !jSyncListener) + if (!jPostListener || !jSyncListener || !jAcceptListener) { ThrowNSException(NS_ERROR, "Listener cannot be null"); return ; @@ -1158,6 +1028,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetL if (jProvider) { LOGD ("calling SetListener on mNativeHandle"); + if (g_obj_acceptListener != NULL) + { + env->DeleteGlobalRef(g_obj_acceptListener); + } if (g_obj_postListener != NULL) { env->DeleteGlobalRef(g_obj_postListener); @@ -1166,11 +1040,12 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetL { env->DeleteGlobalRef(g_obj_syncListener); } + g_obj_acceptListener = (jobject) env->NewGlobalRef(jAcceptListener); g_obj_postListener = (jobject) env->NewGlobalRef(jPostListener); g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener); OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider); - provider->setListener(onMessagePosted, onSyncInfoReceived); + provider->setListener(onProviderState, onMessagePosted, onSyncInfoReceived); } else { @@ -1181,6 +1056,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetL return; } LOGD ("calling SetListener on ProviderID"); + if (g_obj_acceptListener != NULL) + { + env->DeleteGlobalRef(g_obj_acceptListener); + } if (g_obj_postListener != NULL) { env->DeleteGlobalRef(g_obj_postListener); @@ -1189,22 +1068,71 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetL { env->DeleteGlobalRef(g_obj_syncListener); } + g_obj_acceptListener = (jobject) env->NewGlobalRef(jAcceptListener); g_obj_postListener = (jobject) env->NewGlobalRef(jPostListener); g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener); - provider->setListener(onMessagePosted, onSyncInfoReceived); + provider->setListener(onProviderState, onMessagePosted, onSyncInfoReceived); } LOGD ("Provider_SetListener - OUT"); return; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSelectInterestTopics +JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetTopicList +(JNIEnv *env, jobject jObj) +{ + LOGD("Provider_nativeGetTopicList - IN"); + jclass providerClass = env->GetObjectClass(jObj); + if (!providerClass) + { + ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider"); + return NULL; + } + + jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J"); + if (!nativeHandle) + { + ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider"); + return NULL; + } + jlong jProvider = env->GetLongField(jObj, nativeHandle); + OIC::Service::NSTopicsList *topicList; + if (jProvider) + { + LOGD ("calling subscribe on mNativeHandle"); + OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider); + topicList = provider->getTopicList(); + } + else + { + OIC::Service::NSProvider *provider = getNativeProvider(env, jObj); + if (provider == nullptr) + { + ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist"); + return NULL; + } + LOGD ("calling subscribe on ProviderID"); + topicList = provider->getTopicList(); + } + if (topicList == nullptr) + { + ThrowNSException(NS_ERROR, "Topic List doesn't exist"); + return NULL; + } + + jobject obj_topicList = getJavaTopicsList(env, topicList); + + LOGD("Provider_nativeGetTopicList - OUT"); + return obj_topicList; +} + +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpdateTopicList (JNIEnv *env, jobject jObj, jobject jTopicsList) { - LOGD("Provider_SelectInterestTopics -IN"); + LOGD("Provider_nativeUpdateTopicList -IN"); if (!jTopicsList) { - LOGI("Fail to select Interest Topics - Topic List is null"); + LOGI("Fail to update Interest Topics - Topic List is null"); ThrowNSException(NS_ERROR, "TopicList cannot be null"); return (jint) OIC::Service::NSResult::ERROR; } @@ -1234,7 +1162,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSele { LOGD ("calling subscribe on mNativeHandle"); OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider); - result = provider->selectInterestTopics(nsTopicsList); + result = provider->updateTopicList(nsTopicsList); } else { @@ -1245,15 +1173,95 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSele return (jint) OIC::Service::NSResult::ERROR; } LOGD ("calling subscribe on ProviderID"); - result = provider->selectInterestTopics(nsTopicsList); + result = provider->updateTopicList(nsTopicsList); } if (result != OIC::Service::NSResult::OK) { - LOGI("Fail to select Interest Topics"); + LOGI("Fail to Update Interest Topics"); } - LOGD("Provider_SelectInterestTopics -OUT"); + LOGD("Provider_nativeUpdateTopicList -OUT"); return (jint) result; } + +JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetProviderState +(JNIEnv *env, jobject jObj) +{ + LOGD("Provider_nativeGetProviderState - IN"); + jclass providerClass = env->GetObjectClass(jObj); + if (!providerClass) + { + ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider"); + return NULL; + } + + jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J"); + if (!nativeHandle) + { + ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider"); + return NULL; + } + jlong jProvider = env->GetLongField(jObj, nativeHandle); + OIC::Service::NSProviderState state; + if (jProvider) + { + LOGD ("calling getProviderState on mNativeHandle"); + OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider); + state = provider->getProviderState(); + } + else + { + OIC::Service::NSProvider *provider = getNativeProvider(env, jObj); + if (provider == nullptr) + { + ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist"); + return NULL; + } + LOGD ("calling getProviderState on ProviderID"); + state = provider->getProviderState(); + } + jobject obj_state = getJavaProviderState(env,state); + + LOGD("Provider_nativeGetProviderState - OUT"); + return obj_state; +} + +JNIEXPORT jboolean JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeIsSubscribed +(JNIEnv *env, jobject jObj) +{ + LOGD("nativeIsSubscribed - IN"); + jclass providerClass = env->GetObjectClass(jObj); + if (!providerClass) + { + ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider"); + return (jboolean)false; + } + + jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J"); + if (!nativeHandle) + { + ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider"); + return (jboolean)false; + } + jlong jProvider = env->GetLongField(jObj, nativeHandle); + if (jProvider) + { + LOGD ("calling isSubscribe on mNativeHandle"); + OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider); + return (jboolean) provider->isSubscribed(); + } + else + { + OIC::Service::NSProvider *provider = getNativeProvider(env, jObj); + if (provider == nullptr) + { + ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist"); + return (jboolean)false; + } + LOGD ("calling isSubscribe on ProviderID"); + return (jboolean) provider->isSubscribed(); + } +} + // JNI OnLoad JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { @@ -1378,17 +1386,17 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) return JNI_ERR; } - jclass localResponse = env->FindClass( - "org/iotivity/service/ns/consumer/ConsumerService$Response"); - if (!localResponse) + jclass localProviderState = env->FindClass( + "org/iotivity/service/ns/consumer/Provider$ProviderState"); + if (!localProviderState) { - LOGE("Failed to get localResponse Type class"); + LOGE("Failed to get localProviderState Type class"); return JNI_ERR; } - g_cls_Response = (jclass) (env->NewGlobalRef(localResponse)); - if (!g_cls_Response) + g_cls_ProviderState = (jclass) (env->NewGlobalRef(localProviderState)); + if (!g_cls_ProviderState) { - LOGE("Failed to set Global Response Type reference"); + LOGE("Failed to set Global ProviderState Type reference"); return JNI_ERR; } @@ -1412,7 +1420,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) env->DeleteLocalRef(localMediaContents); env->DeleteLocalRef(localTopicState); env->DeleteLocalRef(localMessageType); - env->DeleteLocalRef(localResponse); + env->DeleteLocalRef(localProviderState); env->DeleteLocalRef(localTopic); env->DeleteLocalRef(localTopicsList); @@ -1437,7 +1445,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved) env->DeleteGlobalRef(g_cls_MediaContents); env->DeleteGlobalRef(g_cls_TopicState); env->DeleteGlobalRef(g_cls_Message_Type); - env->DeleteGlobalRef(g_cls_Response); + env->DeleteGlobalRef(g_cls_ProviderState); env->DeleteGlobalRef(g_cls_Topic); env->DeleteGlobalRef(g_cls_TopicsList); } 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 4fae3eb..97ae3d8 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 @@ -31,10 +31,10 @@ extern "C" { /* * Class: org_iotivity_service_ns_consumer_ConsumerService * Method: nativeStart - * Signature: (Lorg/iotivity/service/ns/consumer/ConsumerService/OnProviderDiscoveredListner;Lorg/iotivity/service/ns/consumer/ConsumerService/OnSubscriptionAcceptedListener;)V + * Signature: (Lorg/iotivity/service/ns/consumer/ConsumerService/OnProviderDiscoveredListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStart -(JNIEnv *, jobject, jobject, jobject); +(JNIEnv *, jobject, jobject); /* * Class: org_iotivity_service_ns_consumer_ConsumerService @@ -62,22 +62,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nat (JNIEnv *, jobject); /* - * Class: org_iotivity_service_ns_consumer_ConsumerService - * Method: nativeGetProvider - * Signature: (Ljava/lang/String;)Lorg/iotivity/service/ns/consumer/Provider; - */ -JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetProvider -(JNIEnv *, jobject, jstring); - -/* - * Class: org_iotivity_service_ns_consumer_ConsumerService - * Method: nativeGetMessage - * Signature: (J)Lorg/iotivity/service/ns/common/Message; - */ -JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetMessage -(JNIEnv *, jobject, jlong); - -/* * Class: org_iotivity_service_ns_consumer_Provider * Method: nativeSubscribe * Signature: ()V @@ -87,14 +71,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSubs /* * Class: org_iotivity_service_ns_consumer_Provider - * Method: nativeUnsubscribe - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUnsubscribe -(JNIEnv *, jobject); - -/* - * Class: org_iotivity_service_ns_consumer_Provider * Method: nativeSendSyncInfo * Signature: (JI)V */ @@ -104,19 +80,43 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSend /* * Class: org_iotivity_service_ns_consumer_Provider * Method: nativeSetListener - * Signature: (Lorg/iotivity/service/ns/consumer/Provider/OnMessageReceivedListner;Lorg/iotivity/service/ns/consumer/Provider/OnSyncInfoReceivedListner;)V + * Signature: (Lorg/iotivity/service/ns/consumer/Provider/OnProviderStateListener;Lorg/iotivity/service/ns/consumer/Provider/OnMessageReceivedListner;Lorg/iotivity/service/ns/consumer/Provider/OnSyncInfoReceivedListner;)V */ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetListener -(JNIEnv *, jobject, jobject, jobject); +(JNIEnv *, jobject, jobject, jobject, jobject); /* * Class: org_iotivity_service_ns_consumer_Provider - * Method: nativeSelectInterestTopics + * Method: nativeGetTopicList + * Signature: ()Lorg/iotivity/service/ns/common/TopicsList; + */ +JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetTopicList +(JNIEnv *, jobject); + +/* + * Class: org_iotivity_service_ns_consumer_Provider + * Method: nativeUpdateTopicList * Signature: (Lorg/iotivity/service/ns/common/TopicsList;)I */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSelectInterestTopics +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpdateTopicList (JNIEnv *, jobject, jobject); +/* + * Class: org_iotivity_service_ns_consumer_Provider + * Method: nativeGetProviderState + * Signature: ()Lorg/iotivity/service/ns/consumer/Provider$ProviderState; + */ +JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetProviderState +(JNIEnv *, jobject); + +/* + * Class: org_iotivity_service_ns_consumer_Provider + * Method: nativeIsSubscribed + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeIsSubscribed +(JNIEnv *, jobject); + #ifdef __cplusplus } #endif 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 7b1f9b3..f1a744a 100644 --- a/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp +++ b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp @@ -242,7 +242,7 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg) LOGD("iconImage: %s\n", iconImage); OIC::Service::NSMediaContents *media = new OIC::Service::NSMediaContents(std::string(iconImage)); - OIC::Service::NSMessage *nsMsg = OIC::Service::NSProviderService::getInstance()->CreateMessage(); + OIC::Service::NSMessage *nsMsg = OIC::Service::NSProviderService::getInstance()->createMessage(); nsMsg->setType(type); nsMsg->setTime(std::string(time)); @@ -715,7 +715,7 @@ void onSyncInfoListenerCb(OIC::Service::NSSyncInfo *sync) } jmethodID mid = env->GetMethodID( cls, - "onSyncInfoReceived", + "onMessageSynchronized", "(Lorg/iotivity/service/ns/common/SyncInfo;)V"); if (!mid) { @@ -735,7 +735,7 @@ void onSyncInfoListenerCb(OIC::Service::NSSyncInfo *sync) } JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart -(JNIEnv *env, jobject jObj, jboolean jPolicy, jobject jSubscriptionListener, jobject jSyncListener) +(JNIEnv *env, jobject jObj, jobject jSubscriptionListener, jobject jSyncListener, jboolean jPolicy, jstring jUserInfo) { LOGD("JNIProviderService: nativeStart - IN"); if (!jSubscriptionListener || !jSyncListener) @@ -762,9 +762,15 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat OIC::Service::NSProviderService::ProviderConfig cfg; cfg.m_subscribeRequestCb = onSubscribeListenerCb; cfg.m_syncInfoCb = onSyncInfoListenerCb; - cfg.policy = (bool) jPolicy; + cfg.subControllability = (bool) jPolicy; + if (!jUserInfo) + { + const char *info = env->GetStringUTFChars( jUserInfo, NULL); + std::string userInfo(info); + cfg.userInfo = userInfo; + } - OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->Start(cfg); + OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->start(cfg); if (result != OIC::Service::NSResult::OK) { LOGE("Fail to start NSProviderService"); @@ -780,7 +786,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat { LOGD("JNIProviderService: nativeStop - IN"); - OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->Stop(); + OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->stop(); if (result != OIC::Service::NSResult::OK) { LOGD("Fail to stop NSProvider service"); @@ -813,7 +819,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat return (jint) OIC::Service::NSResult::ERROR; } - OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->SendMessage(nsMsg); + OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->sendMessage(nsMsg); if (result != OIC::Service::NSResult::OK) { LOGD("Fail to send NSProvider Message"); @@ -826,7 +832,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat (JNIEnv *env, jobject jObj, jlong messageId , jint syncState) { LOGD("JNIProviderService: nativeSendSyncInfo - IN"); - OIC::Service::NSProviderService::getInstance()->SendSyncInfo( messageId, + OIC::Service::NSProviderService::getInstance()->sendSyncInfo( messageId, (OIC::Service::NSSyncInfo::NSSyncType) syncState); LOGD("JNIProviderService: nativeSendSyncInfo - OUT"); return; @@ -837,7 +843,7 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_ { LOGD("JNIProviderService: nativeCreateMessage - IN"); OIC::Service::NSMessage* message = - OIC::Service::NSProviderService::getInstance()->CreateMessage(); + OIC::Service::NSProviderService::getInstance()->createMessage(); if(message == nullptr) { ThrowNSException(NS_ERROR, "Couldn't get Native Message"); @@ -866,7 +872,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat const char *address = env->GetStringUTFChars( jstr, NULL); std::string servAddress(address); OIC::Service::NSResult result = - OIC::Service::NSProviderService::getInstance()->EnableRemoteService( + OIC::Service::NSProviderService::getInstance()->enableRemoteService( servAddress); if (result != OIC::Service::NSResult::OK) { @@ -890,7 +896,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat const char *address = env->GetStringUTFChars( jstr, NULL); std::string servAddress(address); OIC::Service::NSResult result = - OIC::Service::NSProviderService::getInstance()->DisableRemoteService( + OIC::Service::NSProviderService::getInstance()->disableRemoteService( servAddress); if (result != OIC::Service::NSResult::OK) { @@ -901,10 +907,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat return (jint) result; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeAddTopic +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic (JNIEnv *env, jobject jObj, jstring jTopicName) { - LOGD("JNIProviderService: nativeAddTopic - IN"); + LOGD("JNIProviderService: nativeRegisterTopic - IN"); if (!jTopicName) { ThrowNSException(NS_ERROR, "Topic Name Can't be NULL"); @@ -912,20 +918,20 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat } const char *name = env->GetStringUTFChars( jTopicName, NULL); std::string topicName(name); - OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->AddTopic( + OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->registerTopic( topicName); if (result != OIC::Service::NSResult::OK) { - LOGE("Fail to Add Topic"); + LOGE("Fail to Register Topic"); } env->ReleaseStringUTFChars(jTopicName, name); - LOGD("JNIProviderService: nativeAddTopic - OUT"); + LOGD("JNIProviderService: nativeRegisterTopic - OUT"); return (jint) result; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeDeleteTopic +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic (JNIEnv *env, jobject jObj, jstring jTopicName) { - LOGD("JNIProviderService: nativeDeleteTopic - IN"); + LOGD("JNIProviderService: nativeUnregisterTopic - IN"); if (!jTopicName) { ThrowNSException(NS_ERROR, "Topic Name Can't be NULL"); @@ -933,24 +939,24 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat } const char *name = env->GetStringUTFChars( jTopicName, NULL); std::string topicName(name); - OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->DeleteTopic( + OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->unregisterTopic( topicName); if (result != OIC::Service::NSResult::OK) { - LOGE("Fail to Add Topic"); + LOGE("Fail to Unregister Topic"); } env->ReleaseStringUTFChars(jTopicName, name); - LOGD("JNIProviderService: nativeDeleteTopic - OUT"); + LOGD("JNIProviderService: nativeUnregisterTopic - OUT"); return (jint) result; } -JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeGetTopics +JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeGetRegisteredTopicList (JNIEnv *env, jobject jObj) { - LOGD("JNIProviderService: nativeGetTopics - IN"); + LOGD("JNIProviderService: nativeGetRegisteredTopicList - IN"); OIC::Service::NSTopicsList *topicList = - OIC::Service::NSProviderService::getInstance()->GetTopics(); + OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList(); if (topicList == nullptr) { ThrowNSException(NS_ERROR, "Topic List doesn't exist"); @@ -959,56 +965,36 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_ jobject obj_topicList = getJavaTopicsList(env, topicList); - LOGD("JNIProviderService: nativeGetTopics - OUT"); + LOGD("JNIProviderService: nativeGetRegisteredTopicList - OUT"); return obj_topicList; } JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription -(JNIEnv *env, jobject jObj, jobject jConsumer, jboolean jAccepted) +(JNIEnv *env, jobject jObj, jstring jConsumerId, jboolean jAccepted) { LOGD("JNIProviderService: nativeAcceptSubscription - IN"); - - jclass consumerClass = env->GetObjectClass( jConsumer); - if (!consumerClass) - { - ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Consumer"); - return (jint) OIC::Service::NSResult::ERROR; - } - - // Consumer ID - jfieldID fid_id = env->GetFieldID(consumerClass, "mConsumerId", "Ljava/lang/String;"); - if (fid_id == NULL) - { - LOGE("Error: jfieldID for mConsumerId is null"); - ThrowNSException(NS_ERROR, "ConsumerId not found"); - return (jint) OIC::Service::NSResult::ERROR; - } - - jstring jconId = (jstring)env->GetObjectField( jConsumer, fid_id); - if (!jconId) + if (!jConsumerId) { - ThrowNSException(NS_ERROR, "ProviderId cannot be null"); + ThrowNSException(NS_ERROR, "ConsumerId Can't be NULL"); return (jint) OIC::Service::NSResult::ERROR; } - const char *conId = env->GetStringUTFChars( jconId, NULL); - std::string consumerId(conId); - env->ReleaseStringUTFChars(jconId, conId); - + const char *id = env->GetStringUTFChars( jConsumerId, NULL); + std::string consumerId(id); LOGD("Consumer ID: %s\n", consumerId.c_str()); OIC::Service::NSConsumer *consumer = OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId); if (consumer) - return (jint) consumer->acceptSubscription(consumer, (bool)jAccepted); + return (jint) consumer->acceptSubscription((bool)jAccepted); LOGE("Couldn't find consumer"); LOGD("JNIProviderService: nativeAcceptSubscription - OUT"); return (jint) OIC::Service::NSResult::ERROR; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSelectTopic +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName) { - LOGD("JNIProviderService: nativeSelectTopic - IN"); + LOGD("JNIProviderService: nativeSetConsumerTopic - IN"); if (!jConsumerId || !jTopicName) { ThrowNSException(NS_ERROR, "Topic Name or ConsumerId Can't be NULL"); @@ -1025,7 +1011,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSele ThrowNSException(NS_ERROR, "Consumer does exists"); return (jint) OIC::Service::NSResult::ERROR; } - OIC::Service::NSResult result = nsConsumer->selectTopic(topicName); + OIC::Service::NSResult result = nsConsumer->setTopic(topicName); if (result != OIC::Service::NSResult::OK) { @@ -1033,13 +1019,13 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSele } env->ReleaseStringUTFChars(jTopicName, name); env->ReleaseStringUTFChars(jConsumerId, id); - LOGD("JNIProviderService: nativeSelectTopic - OUT"); + LOGD("JNIProviderService: nativeSetConsumerTopic - OUT"); return (jint) result; } -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnselectTopic +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName) { - LOGD("JNIProviderService: nativeUnselectTopic - IN"); + LOGD("JNIProviderService: nativeUnsetConsumerTopic - IN"); if (!jConsumerId || !jTopicName) { ThrowNSException(NS_ERROR, "Topic Name or ConsumerId Can't be NULL"); @@ -1056,7 +1042,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnse ThrowNSException(NS_ERROR, "Consumer does exists"); return (jint) OIC::Service::NSResult::ERROR; } - OIC::Service::NSResult result = nsConsumer->unselectTopic(topicName); + OIC::Service::NSResult result = nsConsumer->unsetTopic(topicName); if (result != OIC::Service::NSResult::OK) { @@ -1064,14 +1050,14 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnse } env->ReleaseStringUTFChars(jTopicName, name); env->ReleaseStringUTFChars(jConsumerId, id); - LOGD("JNIProviderService: nativeUnselectTopic - OUT"); + LOGD("JNIProviderService: nativeUnsetConsumerTopic - OUT"); return (jint) result; } -JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeGetConsumerTopics +JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeGetConsumerTopicList (JNIEnv *env, jobject jObj, jstring jConsumerId) { - LOGD("JNIProviderService: nativeGetConsumerTopics - IN"); + LOGD("JNIProviderService: nativeGetConsumerTopicList - IN"); if (!jConsumerId) { ThrowNSException(NS_ERROR, "Topic Name or ConsumerId Can't be NULL"); @@ -1087,14 +1073,14 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeG return NULL; } env->ReleaseStringUTFChars(jConsumerId, id); - OIC::Service::NSTopicsList *topicList = nsConsumer->getConsumerTopics(); + OIC::Service::NSTopicsList *topicList = nsConsumer->getConsumerTopicList(); if (topicList == nullptr) { ThrowNSException(NS_ERROR, "Topic List doesn't exist"); return NULL; } jobject obj_topicList = getJavaTopicsList(env, topicList); - LOGD("JNIProviderService: nativeGetConsumerTopics - OUT"); + LOGD("JNIProviderService: nativeGetConsumerTopicList - OUT"); return obj_topicList; } 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 ed7bdb6..64b7b8b 100644 --- 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,10 +30,10 @@ extern "C" { /* * Class: org_iotivity_service_ns_provider_ProviderService * Method: nativeStart - * Signature: (ZLorg/iotivity/service/ns/provider/ProviderService/OnSubscriptionListener;Lorg/iotivity/service/ns/provider/ProviderService/OnSyncInfoListener;)I + * Signature: (Lorg/iotivity/service/ns/provider/ProviderService/OnConsumerSubscribedListener;Lorg/iotivity/service/ns/provider/ProviderService/OnMessageSynchronizedListener;ZLjava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart -(JNIEnv *, jobject, jboolean, jobject, jobject); +(JNIEnv *, jobject, jobject, jobject, jboolean, jstring); /* * Class: org_iotivity_service_ns_provider_ProviderService @@ -85,59 +85,59 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat /* * Class: org_iotivity_service_ns_provider_ProviderService - * Method: nativeAddTopic + * Method: nativeRegisterTopic * Signature: (Ljava/lang/String;)I */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeAddTopic +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic (JNIEnv *, jobject, jstring); /* * Class: org_iotivity_service_ns_provider_ProviderService - * Method: nativeDeleteTopic + * Method: nativeUnregisterTopic * Signature: (Ljava/lang/String;)I */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeDeleteTopic +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic (JNIEnv *, jobject, jstring); /* * Class: org_iotivity_service_ns_provider_ProviderService - * Method: nativeGetTopics + * Method: nativeGetRegisteredTopicList * Signature: ()Lorg/iotivity/service/ns/common/TopicsList; */ -JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeGetTopics +JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeGetRegisteredTopicList (JNIEnv *, jobject); /* * Class: org_iotivity_service_ns_provider_Consumer * Method: nativeAcceptSubscription - * Signature: (Lorg/iotivity/service/ns/provider/Consumer;Z)I + * Signature: (Ljava/lang/String;Z)I */ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription -(JNIEnv *, jobject, jobject, jboolean); +(JNIEnv *, jobject, jstring, jboolean); /* * Class: org_iotivity_service_ns_provider_Consumer - * Method: nativeSelectTopic + * Method: nativeSetConsumerTopic * Signature: (Ljava/lang/String;Ljava/lang/String;)I */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSelectTopic +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic (JNIEnv *, jobject, jstring, jstring); /* * Class: org_iotivity_service_ns_provider_Consumer - * Method: nativeUnselectTopic + * Method: nativeUnsetConsumerTopic * Signature: (Ljava/lang/String;Ljava/lang/String;)I */ -JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnselectTopic +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic (JNIEnv *, jobject, jstring, jstring); /* * Class: org_iotivity_service_ns_provider_Consumer - * Method: nativeGetConsumerTopics + * Method: nativeGetConsumerTopicList * Signature: (Ljava/lang/String;)Lorg/iotivity/service/ns/common/TopicsList; */ JNIEXPORT jobject JNICALL -Java_org_iotivity_service_ns_provider_Consumer_nativeGetConsumerTopics +Java_org_iotivity_service_ns_provider_Consumer_nativeGetConsumerTopicList (JNIEnv *, jobject, jstring); #ifdef __cplusplus