replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / android / notification-service / src / main / java / org / iotivity / service / ns / provider / ProviderService.java
1 //******************************************************************
2 //
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 package org.iotivity.service.ns.provider;
21
22 import org.iotivity.service.ns.common.*;
23 import java.util.Vector;
24
25 /**
26  *
27  * This class provides a set of Java APIs for Notification ProviderService.
28  *
29  */
30 public class ProviderService {
31
32     static {
33         System.loadLibrary("gnustl_shared");
34         System.loadLibrary("oc_logger");
35         System.loadLibrary("connectivity_abstraction");
36         System.loadLibrary("ca-interface");
37         System.loadLibrary("octbstack");
38         System.loadLibrary("oc");
39         System.loadLibrary("ocstack-jni");
40         System.loadLibrary("notification_provider");
41         System.loadLibrary("notification_provider_wrapper");
42         System.loadLibrary("notification_provider_jni");
43     }
44
45     private static ProviderService instance;
46
47     static {
48         instance = new ProviderService();
49     }
50
51     /**
52      * API for getting instance of ProviderService
53      *
54      * @return ProviderService singleton instance created
55      */
56     public static ProviderService getInstance() {
57         return instance;
58     }
59
60     /**
61      * Start ProviderService
62      *
63      * @param subscribedListener
64      *            OnConsumerSubscribedListener Callback
65      * @param messageSynchronized
66      *            OnMessageSynchronizedListener Callback
67      * @param subControllability
68      *            Set the policy for notification servcie which checks whether
69      *            provider is capable of denying the subscription of
70      *            notification message from consumer and getting controllabliity
71      *            to set consumer topic list. If true, provider is able to
72      *            control subscription request and consumer topic list.
73      *            Otherwise(policy is false), consumer can do the same.
74      * @param userInfo
75      *            User defined information such as device friendly name
76      * @param resourceSecurity
77      *            Set on/off for secure resource channel setting
78      *
79      * @throws NSException
80      *             if any callback parameter passed is null
81      */
82     public void start(OnConsumerSubscribedListener subscribedListener,
83             OnMessageSynchronizedListener messageSynchronized,
84             boolean subControllability, String userInfo,
85             boolean resourceSecurity) throws NSException {
86         nativeStart(subscribedListener, messageSynchronized,
87                 subControllability, userInfo, resourceSecurity);
88     }
89
90     /**
91      * Stop ProviderService
92      *
93      * @throws NSException failed to stop ProviderService
94      */
95     public void stop() throws NSException {
96         nativeStop();
97     }
98
99     /**
100      * Send notification message to all subscribers
101      *
102      * @param message
103      *            Notification message including id, title, contentText
104      *
105      * @throws NSException failed to send notification message
106      */
107     public void sendMessage(Message message) throws NSException {
108         nativeSendMessage(message);
109     }
110
111     /**
112      * Send read-check to provider in order to synchronize notification status
113      * with other consumers
114      *
115      * @param messageId
116      *            unique Id of Notification message to synchronize the status
117      * @param syncType
118      *            SyncType of the SyncInfo message
119      */
120     public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType)
121             throws NSException {
122         nativeSendSyncInfo(messageId, syncType.ordinal());
123     }
124
125     /**
126      * Initialize Message class, Mandatory fields which are messge id and
127      * provider(device) id are filled with
128      *
129      * @return Message
130      */
131     public Message createMessage() throws NSException {
132         return nativeCreateMessage();
133     }
134
135     /**
136      * Request to publish resource to cloud server
137      *
138      * @param servAdd
139      *            servAdd combined with IP address and port number using
140      *            delimiter
141      *
142      * @throws NSException failed to publish resource
143      */
144     public void enableRemoteService(String servAdd) throws NSException {
145         nativeEnableRemoteService(servAdd);
146     }
147
148     /**
149      * Request to cancel remote service using cloud server
150      *
151      * @param servAdd
152      *            servAdd combined with IP address and port number using
153      *            delimiter
154      *
155      * @throws NSException failed to publish resource
156      */
157     public void disableRemoteService(String servAdd) throws NSException {
158         nativeDisableRemoteService(servAdd);
159     }
160
161     /**
162      * Request to subscribe to MQ server
163      *
164      * @param servAdd
165      *            servAdd combined with IP address and port number and MQ broker
166      *            uri using delimiter
167      * @param topicName
168      *            the interest Topic name for subscription
169      *
170      * @throws NSException failed to subscribe to MQ server
171      */
172     public void subscribeMQService(String servAdd, String topicName)
173             throws NSException {
174         nativeSubscribeMQService(servAdd, topicName);
175     }
176
177     /**
178      * Add topic to topic list
179      *
180      * @param topicName
181      *            Topic name to add
182      *
183      * @throws NSException failed to add topic
184      */
185     public void registerTopic(String topicName) throws NSException {
186         nativeRegisterTopic(topicName);
187     }
188
189     /**
190      * Delete topic from topic list
191      *
192      * @param topicName
193      *            Topic name to add
194      *
195      * @throws NSException failed to delete topic
196      */
197     public void unregisterTopic(String topicName) throws NSException {
198         nativeUnregisterTopic(topicName);
199     }
200
201     /**
202      * Request topics list already registered by provider user
203      *
204      * @throws NSException failed to get topics list
205      */
206     public TopicsList getRegisteredTopicList() throws NSException {
207         return nativeGetRegisteredTopicList();
208     }
209
210     /**
211      * Interface to implement callback function to receive subscription request
212      * of consumer
213      */
214     public interface OnConsumerSubscribedListener {
215
216         /**
217          * Callback function to receive subscription request of consumer
218          *
219          * @param consumer
220          *            Consumer who subscribes the notification message resource
221          */
222         public void onConsumerSubscribed(Consumer consumer);
223     }
224
225     /**
226      * Interface to implement callback function to receive the status of the
227      * message synchronization
228      */
229     public interface OnMessageSynchronizedListener {
230
231         /**
232          * Callback function to receive the status of the message
233          * synchronization
234          *
235          * @param syncInfo
236          *            Synchronization information of the notification message
237          */
238         public void onMessageSynchronized(SyncInfo syncInfo);
239     }
240
241     private native void nativeStart(
242             OnConsumerSubscribedListener subscribedListener,
243             OnMessageSynchronizedListener messageSynchronized,
244             boolean subControllability, String userInfo,
245             boolean resourceSecurity) throws NSException;
246
247     private native void nativeStop() throws NSException;
248
249     private native void nativeSendMessage(Message message) throws NSException;
250
251     private native void nativeSendSyncInfo(long messageId, int type)
252             throws NSException;
253
254     private native Message nativeCreateMessage() throws NSException;
255
256     private native void nativeEnableRemoteService(String servAdd)
257             throws NSException;
258
259     private native void nativeDisableRemoteService(String servAdd)
260             throws NSException;
261
262     private native void nativeSubscribeMQService(String servAdd, String topicName)
263             throws NSException;
264
265     private native void nativeRegisterTopic(String topicName) throws NSException;
266
267     private native void nativeUnregisterTopic(String topicName)
268             throws NSException;
269
270     private native TopicsList nativeGetRegisteredTopicList() throws NSException;
271 }