{
instance = new ConsumerService();
}
+
+ /**
+ * API for getting instance of ConsumerService
+ * @return ConsumerService singleton instance created
+ */
public static ConsumerService getInstance()
{
return instance;
}
+ /**
+ * Start ConsumerService
+ * @param onProviderDiscoveredListener - OnProviderDiscoveredListener Callback Interface
+ */
public void start(
OnProviderDiscoveredListener onProviderDiscoveredListener
) throws NSException
nativeStart(onProviderDiscoveredListener);
}
+ /**
+ * Stop ConsumerService
+ */
public void stop() throws NSException
{
nativeStop();
}
+ /**
+ * Request to publish resource to cloud server
+ * @param[in] serverAddress combined with IP address and port number using delimiter :
+ * @return result code
+ */
public void enableRemoteService(String serverAddress) throws NSException
{
nativeEnableRemoteService(serverAddress);
}
+ /**
+ * Request discovery manually
+ */
public void rescanProvider() throws NSException
{
nativeRescanProvider();
}
+ /**
+ * Interface to implement callback function to receive provider on discovery
+ */
public interface OnProviderDiscoveredListener
{
+ /**
+ * Callback function to receive provider on discovery
+ * @param provider - Provider object
+ */
public void onProviderDiscovered(Provider provider);
}
{
private static final String LOG_TAG = "ConsumerService_Provider";
+ /**
+ * ProviderState of Notification resource
+ */
public enum ProviderState
{
ALLOW(1),
public String mProviderId = null;
private long mNativeHandle = 0;
+ /**
+ * Constructor of Provider.
+ * @param providerId - providerId of Provider.
+ */
public Provider(String providerId)
{
Log.i (LOG_TAG, "Provider()");
mProviderId = providerId;
}
+ /**
+ * API for getting providerId.
+ * @return ConsumerId as string.
+ */
public String getProviderId()
{
return mProviderId ;
}
+ /**
+ * API for getting for getting Topic List.
+ * @return TopicsList.
+ */
public TopicsList getTopicList() throws NSException
{
return nativeGetTopicList();
}
+ /**
+ * API for getting for getting ProviderState.
+ * @return ProviderState.
+ */
public ProviderState getProviderState() throws NSException
{
return nativeGetProviderState();
}
+ /**
+ * API for for requesting subscription of Notification service.
+ */
public void subscribe() throws NSException
{
nativeSubscribe();
}
+ /**
+ * API for for requesting subscription status from Provider of Notification service.
+ */
public boolean isSubscribed () throws NSException
{
return nativeIsSubscribed();
}
+ /**
+ * This method is for Sending SyncInfo of Notification service.
+ * @param messageId - id of message.
+ * @param syncType - SyncType of Notification service.
+ */
public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException
{
nativeSendSyncInfo(messageId, syncType.ordinal());
}
+ /**
+ * This method is for registering for listeners of Notification .
+ * @param onProviderStateListener - OnProviderStateListener callback Interface.
+ * @param onMessageReceivedListner - OnMessageReceivedListner callback Interface.
+ * @param onSyncInfoReceivedListner - OnSyncInfoReceivedListner callback Interface.
+ */
public void setListener(OnProviderStateListener onProviderStateListener,
OnMessageReceivedListner onMessageReceivedListner,
OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException
nativeSetListener(onProviderStateListener, onMessageReceivedListner, onSyncInfoReceivedListner);
}
+ /**
+ * Update Topic list that is wanted to be subscribed from provider
+ * @param topicsList - TopicsList of interested Topics.
+ * @return :: result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
+ */
public int updateTopicList(TopicsList topicsList) throws NSException
{
return nativeUpdateTopicList(topicsList);
}
+ /**
+ * Interface to implement callback function to receive provider state information
+ */
public interface OnProviderStateListener
{
+ /**
+ * Callback function to receive provider state information
+ * @param state - ProviderState
+ */
public void onProviderStateReceived(ProviderState state);
}
+ /**
+ * Interface to implement callback function to receive Notification Message
+ */
public interface OnMessageReceivedListner
{
+ /**
+ * Callback function to receive Notification Message
+ * @param message - Notification Message
+ */
public void onMessageReceived(Message message);
}
+ /**
+ * Interface to implement callback function to receive message read synchronization
+ */
public interface OnSyncInfoReceivedListner
{
+ /**
+ * Callback function to receive message read synchronization
+ * @param sync - SyncInfo
+ */
public void onSyncInfoReceived(SyncInfo sync);
}
public String mConsumerId = null;
+ /**
+ * Constructor of Consumer.
+ */
public Consumer(final String consumerId)
{
mConsumerId = consumerId;
}
+ /**
+ * API for getting consumerId
+ * @return ConsumerId as string
+ */
public String getConsumerId( )
{
return mConsumerId;
}
+ /**
+ * API for accepting Subscription request.
+ * This function is valid only when subControllability is set true.
+ * @param accepted - boolean variable representing Subscription response as TRUE/FALSE.
+ * @return :: result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
+ */
public int acceptSubscription(boolean accepted) throws NSException
{
return nativeAcceptSubscription(mConsumerId, accepted);
}
+ /**
+ * Select a topic for a consumer
+ * @param topicName - Topic name to select
+ * @return :: result code
+ */
public int setTopic(String topicName) throws NSException
{
return nativeSetConsumerTopic(mConsumerId, topicName);
}
+ /**
+ * Unselect a topic for a consumer
+ * @param topicName - Topic name to Unselect
+ * @return :: result code
+ */
public int unsetTopic(String topicName) throws NSException
{
return nativeUnsetConsumerTopic(mConsumerId, topicName);
}
+ /**
+ * Request topic list with selection state for the consumer
+ * @return :: Topic list
+ */
public TopicsList getConsumerTopicList() throws NSException
{
return nativeGetConsumerTopicList(mConsumerId);
instance = new ProviderService();
}
+ /**
+ * API for getting instance of ProviderService
+ * @return ProviderService singleton instance created
+ */
public static ProviderService getInstance()
{
return instance;
}
+ /**
+ * Start ProviderService
+ * @param subscribedListener - OnConsumerSubscribedListener Callback
+ * @param messageSynchronized - OnMessageSynchronizedListener Callback
+ * @param subControllability - Set the policy for notification servcie which checks whether
+ * provider is capable of denying the subscription of notification message from consumer and
+ * getting controllabliity to set consumer topic list.
+ * If true, provider is able to control subscription request and consumer topic list.
+ * Otherwise(policy is false), consumer can do the same.
+ * @param userInfo - User defined information such as device friendly name
+ * @param resourceSecurity - Set on/off for secure resource channel setting
+ * @return :: result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
+ */
public int start(OnConsumerSubscribedListener subscribedListener,
OnMessageSynchronizedListener messageSynchronized,
- boolean subControllability, String userInfo,
+ boolean subControllability, String userInfo,
boolean resourceSecurity) throws NSException
{
return nativeStart(subscribedListener, messageSynchronized,
subControllability, userInfo, resourceSecurity);
}
+ /**
+ * Stop ProviderService
+ * @return :: result code
+ */
public int stop() throws NSException
{
return nativeStop();
}
+ /**
+ * Send notification message to all subscribers
+ * @param message - Notification message including id, title, contentText
+ * @return :: result code
+ */
public int sendMessage(Message message) throws NSException
{
return nativeSendMessage(message);
}
+ /**
+ * Send read-check to provider in order to synchronize notification status with other consumers
+ * @param messageId - ID of Notification message to synchronize the status
+ * @param syncType - SyncType of the SyncInfo message
+ */
public void sendSyncInfo ( long messageId , SyncInfo.SyncType syncType) throws NSException
{
nativeSendSyncInfo(messageId, syncType.ordinal());
}
+ /**
+ * Initialize Message class, Mandatory fields which are messge id and provider(device) id are filled with.
+ * @return Message
+ */
public Message createMessage () throws NSException
{
return nativeCreateMessage();
}
+ /**
+ * Request to publish resource to cloud server
+ * @param[in] servAdd combined with IP address and port number using delimiter :
+ * @return result code
+ */
public int enableRemoteService(String servAdd) throws NSException
{
return nativeEnableRemoteService(servAdd);
}
+ /**
+ * Request to cancel remote service using cloud server
+ * @param[in] servAdd combined with IP address and port number using delimiter :
+ * @return result code
+ */
public int disableRemoteService(String servAdd) throws NSException
{
return nativeDisableRemoteService(servAdd);
}
+ /**
+ * Add topic to topic list
+ * @param topicName - Topic name to add
+ * @return :: result code
+ */
public int registerTopic(String topicName) throws NSException
{
return nativeRegisterTopic(topicName);
}
+ /**
+ * Delete topic from topic list
+ * @param topicName - Topic name to add
+ * @return :: result code
+ */
public int unregisterTopic(String topicName) throws NSException
{
return nativeUnregisterTopic(topicName);
}
+ /**
+ * Request topics list already registered by provider user
+ * @return :: Topic list
+ */
public TopicsList getRegisteredTopicList() throws NSException
{
return nativeGetRegisteredTopicList();
}
+ /**
+ * Interface to implement callback function to receive subscription request of consumer
+ */
public interface OnConsumerSubscribedListener
{
+
+ /**
+ * Callback function to receive subscription request of consumer
+ * @param consumer - Consumer who subscribes the notification message resource
+ */
public void onConsumerSubscribed(Consumer consumer);
}
+ /**
+ * Interface to implement callback function to receive the status of the message synchronization
+ */
public interface OnMessageSynchronizedListener
{
+
+ /**
+ * Callback function to receive the status of the message synchronization
+ * @param syncInfo - Synchronization information of the notification message
+ */
public void onMessageSynchronized(SyncInfo syncInfo);
}
public native int nativeStart(OnConsumerSubscribedListener subscribedListener,
OnMessageSynchronizedListener messageSynchronized,
- boolean subControllability, String userInfo,
+ boolean subControllability, String userInfo,
boolean resourceSecurity) throws NSException;
public native int nativeStop() throws NSException;
public native int nativeSendMessage(Message message) throws NSException;