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 <nikhil.a7@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11355
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
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
{
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;
}
{
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)
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
}
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;
+
}
{
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
{
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;
}
static JavaVM *g_jvm = NULL;\r
\r
static jobject g_obj_postListener = NULL;\r
-static jobject g_obj_discoverListener = NULL;\r
static jobject g_obj_syncListener = NULL;\r
+static jobject g_obj_discoverListener = NULL;\r
static jobject g_obj_acceptListener = NULL;\r
\r
jclass g_cls_Message;\r
jclass g_cls_MediaContents;\r
jclass g_cls_TopicState;\r
jclass g_cls_Message_Type;\r
-jclass g_cls_Response;\r
+jclass g_cls_ProviderState;\r
jclass g_cls_Topic;\r
jclass g_cls_TopicsList;\r
\r
}\r
}\r
\r
-jobject getJavaResponse(JNIEnv *env, OIC::Service::NSResponse response)\r
+jobject getJavaProviderState(JNIEnv *env, OIC::Service::NSProviderState state)\r
{\r
- LOGD ("ConsumerService_getJavaResponse - IN");\r
- switch (response)\r
+ LOGD ("ConsumerService_getJavaProviderState - IN");\r
+ switch (state)\r
{\r
- case OIC::Service::NSResponse::ALLOW:\r
+ case OIC::Service::NSProviderState::ALLOW:\r
+ {\r
+ static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState,\r
+ "ALLOW", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;");\r
+ return env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+ }\r
+ case OIC::Service::NSProviderState::DENY:\r
{\r
- static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response,\r
- "ALLOW", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;");\r
- return env->GetStaticObjectField(g_cls_Response, fieldID);\r
+ static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState,\r
+ "DENY", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;");\r
+ return env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
}\r
- case OIC::Service::NSResponse::DENY:\r
+ case OIC::Service::NSProviderState::TOPIC:\r
{\r
- static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response,\r
- "DENY", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;");\r
- return env->GetStaticObjectField(g_cls_Response, fieldID);\r
+ static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState,\r
+ "TOPIC", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;");\r
+ return env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
}\r
- case OIC::Service::NSResponse::TOPIC:\r
+ case OIC::Service::NSProviderState::STOPPED:\r
{\r
- static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response,\r
- "TOPIC", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;");\r
- return env->GetStaticObjectField(g_cls_Response, fieldID);\r
+ static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState,\r
+ "STOPPED", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;");\r
+ return env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
}\r
default:\r
return NULL;\r
}\r
- LOGD ("ConsumerService_getJavaResponse - OUT");\r
+ LOGD ("ConsumerService_getJavaProviderState - OUT");\r
return NULL;\r
}\r
\r
}\r
env->SetLongField(obj_provider, nativeHandle, pProvider);\r
\r
- jfieldID fid_topic = env->GetFieldID(cls_provider, "mTopicsList",\r
- "Lorg/iotivity/service/ns/common/TopicsList;");\r
- if (!fid_topic)\r
- {\r
- LOGE("Failed to get TopicList for Provider");\r
- return NULL;\r
- }\r
- jobject topicList = getJavaTopicsList(env, provider->getTopicList());\r
- env->SetObjectField(obj_provider, fid_topic, topicList);\r
env->DeleteLocalRef(cls_provider);\r
LOGD ("ConsumerService_getJavaProvider - OUT");\r
return obj_provider;\r
return ;\r
}\r
\r
-void onProviderChanged(OIC::Service::NSProvider *provider, OIC::Service::NSResponse response)\r
+void onProviderState( OIC::Service::NSProviderState state)\r
{\r
- LOGD ("ConsumerService_onProviderChanged -IN");\r
+ LOGD ("ConsumerService_onProviderState -IN");\r
\r
jint envRet;\r
JNIEnv *env = GetJNIEnv(&envRet);\r
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
return ;\r
}\r
- jobject obj_provider = getJavaProvider(env, provider);\r
- if (!obj_provider)\r
+ jobject obj_state = getJavaProviderState(env, state);\r
+ if (!obj_state)\r
{\r
- LOGE ("Failed to Get Provider Object");\r
+ LOGE ("Failed to Get ProviderState Object");\r
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
return ;\r
}\r
}\r
jmethodID mid = env->GetMethodID(\r
cls,\r
- "onProviderChanged",\r
- "(Lorg/iotivity/service/ns/consumer/Provider;Lorg/iotivity/service/ns/consumer/ConsumerService$Response;)V");\r
+ "onProviderStateReceived",\r
+ "(Lorg/iotivity/service/ns/consumer/Provider$ProviderState;)V");\r
if (!mid)\r
{\r
- LOGE ("Failed to Get MethodID for onProviderChanged");\r
+ LOGE ("Failed to Get MethodID for onProviderState");\r
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
return ;\r
}\r
- jobject obj_response = getJavaResponse(env, response);\r
- env->CallVoidMethod(jAcceptListener, mid, obj_provider, obj_response);\r
+ env->CallVoidMethod(jAcceptListener, mid, obj_state);\r
\r
env->DeleteLocalRef(jAcceptListener);\r
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
- LOGD ("ConsumerService_onProviderChanged -OUT");\r
+ LOGD ("ConsumerService_onProviderState -OUT");\r
return ;\r
\r
}\r
}\r
\r
JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStart\r
-(JNIEnv *env, jobject jObj, jobject jDiscoverListener, jobject jAccpetListener)\r
+(JNIEnv *env, jobject jObj, jobject jDiscoverListener)\r
{\r
LOGD ("ConsumerService_StartConsumer - IN");\r
- if (!jDiscoverListener || !jAccpetListener)\r
+ if (!jDiscoverListener)\r
{\r
ThrowNSException(NS_ERROR, "Listener cannot be null");\r
return ;\r
}\r
-\r
if (g_obj_discoverListener != NULL)\r
{\r
env->DeleteGlobalRef(g_obj_discoverListener);\r
}\r
- if (g_obj_acceptListener != NULL)\r
- {\r
- env->DeleteGlobalRef(g_obj_acceptListener);\r
- }\r
-\r
g_obj_discoverListener = (jobject) env->NewGlobalRef(jDiscoverListener);\r
- g_obj_acceptListener = (jobject) env->NewGlobalRef(jAccpetListener);\r
\r
- OIC::Service::NSConsumerService::ConsumerConfig cfg;\r
- cfg.m_discoverCb = onDiscoverProvider;\r
- cfg.m_changedCb = onProviderChanged;\r
-\r
- OIC::Service::NSConsumerService::getInstance()->Start(cfg);\r
+ OIC::Service::NSConsumerService::getInstance()->start(onDiscoverProvider);\r
LOGD ("ConsumerService_StartConsumer - OUT");\r
return;\r
\r
LOGD ("ConsumerService_StopConsumer - IN");\r
\r
env->DeleteGlobalRef(g_obj_postListener);\r
- env->DeleteGlobalRef(g_obj_discoverListener);\r
env->DeleteGlobalRef(g_obj_syncListener);\r
+ env->DeleteGlobalRef(g_obj_discoverListener);\r
env->DeleteGlobalRef(g_obj_acceptListener);\r
g_obj_postListener = NULL;\r
- g_obj_discoverListener = NULL;\r
g_obj_syncListener = NULL;\r
+ g_obj_discoverListener = NULL;\r
g_obj_acceptListener = NULL;\r
- OIC::Service::NSConsumerService::getInstance()->Stop();\r
+ OIC::Service::NSConsumerService::getInstance()->stop();\r
LOGD ("ConsumerService_StopConsumer - OUT");\r
return;\r
}\r
}\r
const char *serverAddress = env->GetStringUTFChars(jServerAddress, 0);\r
OIC::Service::NSResult res =\r
- OIC::Service::NSConsumerService::getInstance()->EnableRemoteService(std::string(serverAddress));\r
+ OIC::Service::NSConsumerService::getInstance()->enableRemoteService(std::string(serverAddress));\r
env->ReleaseStringUTFChars(jServerAddress, serverAddress);\r
LOGD ("ConsumerService_EnableRemoteService - OUT");\r
return (jint) res;\r
(JNIEnv *env, jobject jObj)\r
{\r
LOGD ("ConsumerService_RescanProvider - IN");\r
- OIC::Service::NSConsumerService::getInstance()->RescanProvider();\r
+ OIC::Service::NSConsumerService::getInstance()->rescanProvider();\r
LOGD ("ConsumerService_RescanProvider - OUT");\r
return;\r
\r
}\r
\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetProvider\r
-(JNIEnv *env, jobject jObj, jstring jProviderId)\r
-{\r
- LOGD ("ConsumerService_GetProvider - IN");\r
- if (!jProviderId)\r
- {\r
- ThrowNSException(NS_ERROR, "ProviderId cannot be null");\r
- return NULL;\r
- }\r
-\r
- const char *providerId = env->GetStringUTFChars(jProviderId, 0);\r
- LOGD ("java_ProviderId : %s\n", providerId);\r
-\r
- OIC::Service::NSProvider *provider =\r
- OIC::Service::NSConsumerService::getInstance()->getProvider(std::string(providerId));\r
- if (provider == nullptr)\r
- {\r
- ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
- return NULL;\r
- }\r
- LOGD ("native_ProviderId : %s\n", provider->getProviderId().c_str());\r
-\r
- jProviderId = env->NewStringUTF(provider->getProviderId().c_str());\r
- jlong pProvider = (long)provider;\r
-\r
- jclass cls_provider = (jclass) (env->NewLocalRef(g_cls_Provider));\r
- if (!cls_provider)\r
- {\r
- LOGE ("Failed to Get ObjectClass for Provider");\r
- ThrowNSException(NS_ERROR, "Couldn't find objectClass for Provider");\r
- return NULL;\r
- }\r
- jmethodID mid_provider = env->GetMethodID(\r
- cls_provider, "<init>", "(Ljava/lang/String;)V");\r
- if (!mid_provider)\r
- {\r
- LOGE ("Failed to Get MethodID for Provider<init>");\r
- ThrowNSException(NS_ERROR, "Couldn't find MethodID for Provider<init>");\r
- return NULL;\r
- }\r
- jobject obj_provider = env->NewObject(cls_provider, mid_provider,\r
- jProviderId);\r
-\r
- jfieldID nativeHandle = env->GetFieldID(cls_provider, "mNativeHandle", "J");\r
- if (!nativeHandle)\r
- {\r
- ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
- return NULL;\r
- }\r
- env->SetLongField(obj_provider, nativeHandle, pProvider);\r
-\r
- env->DeleteLocalRef(cls_provider);\r
- env->ReleaseStringUTFChars(jProviderId, providerId);\r
- LOGD ("ConsumerService_GetProvider - OUT");\r
- return obj_provider;\r
-}\r
-\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetMessage\r
-(JNIEnv *env, jobject jObj, jlong jMsgId)\r
-{\r
- LOGI("JNIConsumerService: nativeGetMessage - IN");\r
-\r
- OIC::Service::NSMessage *msg =\r
- OIC::Service::NSConsumerService::getInstance()->getMessage((uint64_t)jMsgId);\r
- if (msg == nullptr)\r
- {\r
- ThrowNSException(NS_ERROR, "Message doesn't exist");\r
- return NULL;\r
- }\r
-\r
- jobject obj_msg = getJavaMessage(env, msg);\r
-\r
- LOGI("JNIConsumerService: nativeGetMessage - OUT");\r
- return obj_msg;\r
-}\r
JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSubscribe\r
(JNIEnv *env, jobject jObj)\r
{\r
return;\r
}\r
\r
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUnsubscribe\r
-(JNIEnv *env, jobject jObj)\r
-{\r
- LOGD ("Provider_Unsubscribe - IN");\r
-\r
- jclass providerClass = env->GetObjectClass(jObj);\r
- if (!providerClass)\r
- {\r
- ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
- return ;\r
- }\r
-\r
- jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");\r
- if (!nativeHandle)\r
- {\r
- ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
- return ;\r
- }\r
- jlong jProvider = env->GetLongField(jObj, nativeHandle);\r
- if (jProvider)\r
- {\r
- LOGD ("calling unSubscribe on mNativeHandle");\r
- OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
- provider->unSubscribe();\r
- }\r
- else\r
- {\r
- OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);\r
- if (provider == nullptr)\r
- {\r
- ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
- return;\r
- }\r
- LOGD ("calling unSubscribe on ProviderID");\r
- provider->unSubscribe();\r
- }\r
- LOGD ("Provider_Unsubscribe - IN");\r
- return;\r
-}\r
-\r
JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSendSyncInfo\r
(JNIEnv *env, jobject jObj, jlong jMessageId, jint jSyncType)\r
{\r
{\r
LOGD ("calling SendSyncInfo on mNativeHandle");\r
OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
- provider->SendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType);\r
+ provider->sendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType);\r
}\r
else\r
{\r
return;\r
}\r
LOGD ("calling SendSyncInfo on ProviderID");\r
- provider->SendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType);\r
+ provider->sendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType);\r
}\r
LOGD ("Provider_SendSyncInfo - OUT");\r
return;\r
\r
\r
JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetListener\r
-(JNIEnv *env, jobject jObj, jobject jPostListener, jobject jSyncListener)\r
+(JNIEnv *env, jobject jObj, jobject jAcceptListener, jobject jPostListener, jobject jSyncListener)\r
{\r
LOGD ("Provider_SetListener - IN");\r
- if (!jPostListener || !jSyncListener)\r
+ if (!jPostListener || !jSyncListener || !jAcceptListener)\r
{\r
ThrowNSException(NS_ERROR, "Listener cannot be null");\r
return ;\r
if (jProvider)\r
{\r
LOGD ("calling SetListener on mNativeHandle");\r
+ if (g_obj_acceptListener != NULL)\r
+ {\r
+ env->DeleteGlobalRef(g_obj_acceptListener);\r
+ }\r
if (g_obj_postListener != NULL)\r
{\r
env->DeleteGlobalRef(g_obj_postListener);\r
{\r
env->DeleteGlobalRef(g_obj_syncListener);\r
}\r
+ g_obj_acceptListener = (jobject) env->NewGlobalRef(jAcceptListener);\r
g_obj_postListener = (jobject) env->NewGlobalRef(jPostListener);\r
g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener);\r
\r
OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
- provider->setListener(onMessagePosted, onSyncInfoReceived);\r
+ provider->setListener(onProviderState, onMessagePosted, onSyncInfoReceived);\r
}\r
else\r
{\r
return;\r
}\r
LOGD ("calling SetListener on ProviderID");\r
+ if (g_obj_acceptListener != NULL)\r
+ {\r
+ env->DeleteGlobalRef(g_obj_acceptListener);\r
+ }\r
if (g_obj_postListener != NULL)\r
{\r
env->DeleteGlobalRef(g_obj_postListener);\r
{\r
env->DeleteGlobalRef(g_obj_syncListener);\r
}\r
+ g_obj_acceptListener = (jobject) env->NewGlobalRef(jAcceptListener);\r
g_obj_postListener = (jobject) env->NewGlobalRef(jPostListener);\r
g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener);\r
\r
- provider->setListener(onMessagePosted, onSyncInfoReceived);\r
+ provider->setListener(onProviderState, onMessagePosted, onSyncInfoReceived);\r
}\r
LOGD ("Provider_SetListener - OUT");\r
return;\r
}\r
\r
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSelectInterestTopics\r
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetTopicList\r
+(JNIEnv *env, jobject jObj)\r
+{\r
+ LOGD("Provider_nativeGetTopicList - IN");\r
+ jclass providerClass = env->GetObjectClass(jObj);\r
+ if (!providerClass)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
+ return NULL;\r
+ }\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
+ return NULL;\r
+ }\r
+ jlong jProvider = env->GetLongField(jObj, nativeHandle);\r
+ OIC::Service::NSTopicsList *topicList;\r
+ if (jProvider)\r
+ {\r
+ LOGD ("calling subscribe on mNativeHandle");\r
+ OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
+ topicList = provider->getTopicList();\r
+ }\r
+ else\r
+ {\r
+ OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return NULL;\r
+ }\r
+ LOGD ("calling subscribe on ProviderID");\r
+ topicList = provider->getTopicList();\r
+ }\r
+ if (topicList == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Topic List doesn't exist");\r
+ return NULL;\r
+ }\r
+\r
+ jobject obj_topicList = getJavaTopicsList(env, topicList);\r
+\r
+ LOGD("Provider_nativeGetTopicList - OUT");\r
+ return obj_topicList;\r
+}\r
+\r
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpdateTopicList\r
(JNIEnv *env, jobject jObj, jobject jTopicsList)\r
{\r
- LOGD("Provider_SelectInterestTopics -IN");\r
+ LOGD("Provider_nativeUpdateTopicList -IN");\r
if (!jTopicsList)\r
{\r
- LOGI("Fail to select Interest Topics - Topic List is null");\r
+ LOGI("Fail to update Interest Topics - Topic List is null");\r
ThrowNSException(NS_ERROR, "TopicList cannot be null");\r
return (jint) OIC::Service::NSResult::ERROR;\r
}\r
{\r
LOGD ("calling subscribe on mNativeHandle");\r
OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
- result = provider->selectInterestTopics(nsTopicsList);\r
+ result = provider->updateTopicList(nsTopicsList);\r
}\r
else\r
{\r
return (jint) OIC::Service::NSResult::ERROR;\r
}\r
LOGD ("calling subscribe on ProviderID");\r
- result = provider->selectInterestTopics(nsTopicsList);\r
+ result = provider->updateTopicList(nsTopicsList);\r
}\r
if (result != OIC::Service::NSResult::OK)\r
{\r
- LOGI("Fail to select Interest Topics");\r
+ LOGI("Fail to Update Interest Topics");\r
}\r
- LOGD("Provider_SelectInterestTopics -OUT");\r
+ LOGD("Provider_nativeUpdateTopicList -OUT");\r
return (jint) result;\r
}\r
+\r
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetProviderState\r
+(JNIEnv *env, jobject jObj)\r
+{\r
+ LOGD("Provider_nativeGetProviderState - IN");\r
+ jclass providerClass = env->GetObjectClass(jObj);\r
+ if (!providerClass)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
+ return NULL;\r
+ }\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
+ return NULL;\r
+ }\r
+ jlong jProvider = env->GetLongField(jObj, nativeHandle);\r
+ OIC::Service::NSProviderState state;\r
+ if (jProvider)\r
+ {\r
+ LOGD ("calling getProviderState on mNativeHandle");\r
+ OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
+ state = provider->getProviderState();\r
+ }\r
+ else\r
+ {\r
+ OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return NULL;\r
+ }\r
+ LOGD ("calling getProviderState on ProviderID");\r
+ state = provider->getProviderState();\r
+ }\r
+ jobject obj_state = getJavaProviderState(env,state);\r
+\r
+ LOGD("Provider_nativeGetProviderState - OUT");\r
+ return obj_state;\r
+}\r
+\r
+JNIEXPORT jboolean JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeIsSubscribed\r
+(JNIEnv *env, jobject jObj)\r
+{\r
+ LOGD("nativeIsSubscribed - IN");\r
+ jclass providerClass = env->GetObjectClass(jObj);\r
+ if (!providerClass)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");\r
+ return (jboolean)false;\r
+ }\r
+\r
+ jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");\r
+ if (!nativeHandle)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");\r
+ return (jboolean)false;\r
+ }\r
+ jlong jProvider = env->GetLongField(jObj, nativeHandle);\r
+ if (jProvider)\r
+ {\r
+ LOGD ("calling isSubscribe on mNativeHandle");\r
+ OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);\r
+ return (jboolean) provider->isSubscribed();\r
+ }\r
+ else\r
+ {\r
+ OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);\r
+ if (provider == nullptr)\r
+ {\r
+ ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");\r
+ return (jboolean)false;\r
+ }\r
+ LOGD ("calling isSubscribe on ProviderID");\r
+ return (jboolean) provider->isSubscribed();\r
+ }\r
+}\r
+\r
// JNI OnLoad\r
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)\r
{\r
return JNI_ERR;\r
}\r
\r
- jclass localResponse = env->FindClass(\r
- "org/iotivity/service/ns/consumer/ConsumerService$Response");\r
- if (!localResponse)\r
+ jclass localProviderState = env->FindClass(\r
+ "org/iotivity/service/ns/consumer/Provider$ProviderState");\r
+ if (!localProviderState)\r
{\r
- LOGE("Failed to get localResponse Type class");\r
+ LOGE("Failed to get localProviderState Type class");\r
return JNI_ERR;\r
}\r
- g_cls_Response = (jclass) (env->NewGlobalRef(localResponse));\r
- if (!g_cls_Response)\r
+ g_cls_ProviderState = (jclass) (env->NewGlobalRef(localProviderState));\r
+ if (!g_cls_ProviderState)\r
{\r
- LOGE("Failed to set Global Response Type reference");\r
+ LOGE("Failed to set Global ProviderState Type reference");\r
return JNI_ERR;\r
}\r
\r
env->DeleteLocalRef(localMediaContents);\r
env->DeleteLocalRef(localTopicState);\r
env->DeleteLocalRef(localMessageType);\r
- env->DeleteLocalRef(localResponse);\r
+ env->DeleteLocalRef(localProviderState);\r
env->DeleteLocalRef(localTopic);\r
env->DeleteLocalRef(localTopicsList);\r
\r
env->DeleteGlobalRef(g_cls_MediaContents);\r
env->DeleteGlobalRef(g_cls_TopicState);\r
env->DeleteGlobalRef(g_cls_Message_Type);\r
- env->DeleteGlobalRef(g_cls_Response);\r
+ env->DeleteGlobalRef(g_cls_ProviderState);\r
env->DeleteGlobalRef(g_cls_Topic);\r
env->DeleteGlobalRef(g_cls_TopicsList);\r
}\r
/*\r
* Class: org_iotivity_service_ns_consumer_ConsumerService\r
* Method: nativeStart\r
- * Signature: (Lorg/iotivity/service/ns/consumer/ConsumerService/OnProviderDiscoveredListner;Lorg/iotivity/service/ns/consumer/ConsumerService/OnSubscriptionAcceptedListener;)V\r
+ * Signature: (Lorg/iotivity/service/ns/consumer/ConsumerService/OnProviderDiscoveredListener;)V\r
*/\r
JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStart\r
-(JNIEnv *, jobject, jobject, jobject);\r
+(JNIEnv *, jobject, jobject);\r
\r
/*\r
* Class: org_iotivity_service_ns_consumer_ConsumerService\r
(JNIEnv *, jobject);\r
\r
/*\r
- * Class: org_iotivity_service_ns_consumer_ConsumerService\r
- * Method: nativeGetProvider\r
- * Signature: (Ljava/lang/String;)Lorg/iotivity/service/ns/consumer/Provider;\r
- */\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetProvider\r
-(JNIEnv *, jobject, jstring);\r
-\r
-/*\r
- * Class: org_iotivity_service_ns_consumer_ConsumerService\r
- * Method: nativeGetMessage\r
- * Signature: (J)Lorg/iotivity/service/ns/common/Message;\r
- */\r
-JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetMessage\r
-(JNIEnv *, jobject, jlong);\r
-\r
-/*\r
* Class: org_iotivity_service_ns_consumer_Provider\r
* Method: nativeSubscribe\r
* Signature: ()V\r
\r
/*\r
* Class: org_iotivity_service_ns_consumer_Provider\r
- * Method: nativeUnsubscribe\r
- * Signature: ()V\r
- */\r
-JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUnsubscribe\r
-(JNIEnv *, jobject);\r
-\r
-/*\r
- * Class: org_iotivity_service_ns_consumer_Provider\r
* Method: nativeSendSyncInfo\r
* Signature: (JI)V\r
*/\r
/*\r
* Class: org_iotivity_service_ns_consumer_Provider\r
* Method: nativeSetListener\r
- * Signature: (Lorg/iotivity/service/ns/consumer/Provider/OnMessageReceivedListner;Lorg/iotivity/service/ns/consumer/Provider/OnSyncInfoReceivedListner;)V\r
+ * Signature: (Lorg/iotivity/service/ns/consumer/Provider/OnProviderStateListener;Lorg/iotivity/service/ns/consumer/Provider/OnMessageReceivedListner;Lorg/iotivity/service/ns/consumer/Provider/OnSyncInfoReceivedListner;)V\r
*/\r
JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetListener\r
-(JNIEnv *, jobject, jobject, jobject);\r
+(JNIEnv *, jobject, jobject, jobject, jobject);\r
\r
/*\r
* Class: org_iotivity_service_ns_consumer_Provider\r
- * Method: nativeSelectInterestTopics\r
+ * Method: nativeGetTopicList\r
+ * Signature: ()Lorg/iotivity/service/ns/common/TopicsList;\r
+ */\r
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetTopicList\r
+(JNIEnv *, jobject);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_Provider\r
+ * Method: nativeUpdateTopicList\r
* Signature: (Lorg/iotivity/service/ns/common/TopicsList;)I\r
*/\r
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSelectInterestTopics\r
+JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUpdateTopicList\r
(JNIEnv *, jobject, jobject);\r
\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_Provider\r
+ * Method: nativeGetProviderState\r
+ * Signature: ()Lorg/iotivity/service/ns/consumer/Provider$ProviderState;\r
+ */\r
+JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeGetProviderState\r
+(JNIEnv *, jobject);\r
+\r
+/*\r
+ * Class: org_iotivity_service_ns_consumer_Provider\r
+ * Method: nativeIsSubscribed\r
+ * Signature: ()Z\r
+ */\r
+JNIEXPORT jboolean JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeIsSubscribed\r
+(JNIEnv *, jobject);\r
+\r
#ifdef __cplusplus\r
}\r
#endif\r
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));
}
jmethodID mid = env->GetMethodID(
cls,
- "onSyncInfoReceived",
+ "onMessageSynchronized",
"(Lorg/iotivity/service/ns/common/SyncInfo;)V");
if (!mid)
{
}
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)
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");
{
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");
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");
(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;
{
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");
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)
{
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)
{
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");
}
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");
}
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");
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");
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)
{
}
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");
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)
{
}
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");
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;
}
/*
* 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
/*
* 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