replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / android / notification-service / src / main / java / org / iotivity / service / ns / provider / ProviderService.java
old mode 100644 (file)
new mode 100755 (executable)
index b15ba46..b7ae317
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 package org.iotivity.service.ns.provider;
+
 import org.iotivity.service.ns.common.*;
 import java.util.Vector;
+
 /**
-  * @class   ProviderService
-  * @brief   This class provides a set of Java APIs for Notification ProviderService.
-  */
-public class ProviderService
-{
-
-    static
-    {
+ *
+ * This class provides a set of Java APIs for Notification ProviderService.
+ *
+ */
+public class ProviderService {
+
+    static {
         System.loadLibrary("gnustl_shared");
         System.loadLibrary("oc_logger");
         System.loadLibrary("connectivity_abstraction");
@@ -43,166 +44,228 @@ public class ProviderService
 
     private static ProviderService instance;
 
-    static
-    {
+    static {
         instance = new ProviderService();
     }
 
     /**
-      * API for getting instance of ProviderService
-      * @return ProviderService singleton instance created
-      */
-    public static ProviderService getInstance()
-    {
+     * 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 resourceSecurity) throws NSException
-    {
-        return nativeStart(subscribedListener, messageSynchronized,
-                            subControllability, userInfo, resourceSecurity);
+     * 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
+     *
+     * @throws NSException
+     *             if any callback parameter passed is null
+     */
+    public void start(OnConsumerSubscribedListener subscribedListener,
+            OnMessageSynchronizedListener messageSynchronized,
+            boolean subControllability, String userInfo,
+            boolean resourceSecurity) throws NSException {
+        nativeStart(subscribedListener, messageSynchronized,
+                subControllability, userInfo, resourceSecurity);
     }
 
     /**
-      * Stop ProviderService
-      * @return :: result code
-      */
-    public int stop() throws NSException
-    {
-        return nativeStop();
+     * Stop ProviderService
+     *
+     * @throws NSException failed to stop ProviderService
+     */
+    public void stop() throws NSException {
+        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 notification message to all subscribers
+     *
+     * @param message
+     *            Notification message including id, title, contentText
+     *
+     * @throws NSException failed to send notification message
+     */
+    public void sendMessage(Message message) throws NSException {
+        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
-    {
+     * Send read-check to provider in order to synchronize notification status
+     * with other consumers
+     *
+     * @param messageId
+     *            unique 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
-    {
+     * 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 publish resource to cloud server
+     *
+     * @param servAdd
+     *            servAdd combined with IP address and port number using
+     *            delimiter
+     *
+     * @throws NSException failed to publish resource
+     */
+    public void enableRemoteService(String servAdd) throws NSException {
+        nativeEnableRemoteService(servAdd);
+    }
+
+    /**
+     * Request to cancel remote service using cloud server
+     *
+     * @param servAdd
+     *            servAdd combined with IP address and port number using
+     *            delimiter
+     *
+     * @throws NSException failed to publish resource
+     */
+    public void disableRemoteService(String servAdd) throws NSException {
+        nativeDisableRemoteService(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);
+     * Request to subscribe to MQ server
+     *
+     * @param servAdd
+     *            servAdd combined with IP address and port number and MQ broker
+     *            uri using delimiter
+     * @param topicName
+     *            the interest Topic name for subscription
+     *
+     * @throws NSException failed to subscribe to MQ server
+     */
+    public void subscribeMQService(String servAdd, String topicName)
+            throws NSException {
+        nativeSubscribeMQService(servAdd, topicName);
     }
 
     /**
-      * Add topic to topic list
-      * @param  topicName - Topic name to add
-      * @return :: result code
-      */
-    public int registerTopic(String topicName) throws NSException
-    {
-        return nativeRegisterTopic(topicName);
+     * Add topic to topic list
+     *
+     * @param topicName
+     *            Topic name to add
+     *
+     * @throws NSException failed to add topic
+     */
+    public void registerTopic(String topicName) throws NSException {
+        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);
+     * Delete topic from topic list
+     *
+     * @param topicName
+     *            Topic name to add
+     *
+     * @throws NSException failed to delete topic
+     */
+    public void unregisterTopic(String topicName) throws NSException {
+        nativeUnregisterTopic(topicName);
     }
 
     /**
-      * Request topics list already registered by provider user
-      * @return :: Topic list
-      */
-    public TopicsList getRegisteredTopicList() throws NSException
-    {
+     * Request topics list already registered by provider user
+     *
+     * @throws NSException failed to get topics list
+     */
+    public TopicsList getRegisteredTopicList() throws NSException {
         return nativeGetRegisteredTopicList();
     }
 
     /**
-      * Interface to implement callback function to receive subscription request of consumer
-      */
-    public interface OnConsumerSubscribedListener
-    {
+     * 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
-          */
+         * 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
-    {
+     * 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
-          */
+         * 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 resourceSecurity) 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;
+    private native void nativeStart(
+            OnConsumerSubscribedListener subscribedListener,
+            OnMessageSynchronizedListener messageSynchronized,
+            boolean subControllability, String userInfo,
+            boolean resourceSecurity) throws NSException;
+
+    private native void nativeStop() throws NSException;
+
+    private native void nativeSendMessage(Message message) throws NSException;
+
+    private native void nativeSendSyncInfo(long messageId, int type)
+            throws NSException;
+
+    private native Message nativeCreateMessage() throws NSException;
+
+    private native void nativeEnableRemoteService(String servAdd)
+            throws NSException;
+
+    private native void nativeDisableRemoteService(String servAdd)
+            throws NSException;
+
+    private native void nativeSubscribeMQService(String servAdd, String topicName)
+            throws NSException;
+
+    private native void nativeRegisterTopic(String topicName) throws NSException;
+
+    private native void nativeUnregisterTopic(String topicName)
+            throws NSException;
+
+    private native TopicsList nativeGetRegisteredTopicList() throws NSException;
 }