1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 package org.iotivity.service.ns.provider;
22 import org.iotivity.service.ns.common.*;
23 import java.util.Vector;
27 * This class provides a set of Java APIs for Notification ProviderService.
30 public class ProviderService {
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");
45 private static ProviderService instance;
48 instance = new ProviderService();
52 * API for getting instance of ProviderService
54 * @return ProviderService singleton instance created
56 public static ProviderService getInstance() {
61 * Start ProviderService
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.
75 * User defined information such as device friendly name
76 * @param resourceSecurity
77 * Set on/off for secure resource channel setting
79 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
82 * if any callback parameter passed is null
84 public int start(OnConsumerSubscribedListener subscribedListener,
85 OnMessageSynchronizedListener messageSynchronized,
86 boolean subControllability, String userInfo,
87 boolean resourceSecurity) throws NSException {
88 return nativeStart(subscribedListener, messageSynchronized,
89 subControllability, userInfo, resourceSecurity);
93 * Stop ProviderService
95 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
97 * @throws NSException failed to stop ProviderService
99 public int stop() throws NSException {
104 * Send notification message to all subscribers
107 * Notification message including id, title, contentText
109 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
111 * @throws NSException failed to send notification message
113 public int sendMessage(Message message) throws NSException {
114 return nativeSendMessage(message);
118 * Send read-check to provider in order to synchronize notification status
119 * with other consumers
122 * unique Id of Notification message to synchronize the status
124 * SyncType of the SyncInfo message
125 * @throws NSException failed to send read-check
127 public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType)
129 nativeSendSyncInfo(messageId, syncType.ordinal());
133 * Initialize Message class, Mandatory fields which are messge id and
134 * provider(device) id are filled
138 * @throws NSException failed to initialized message class
140 public Message createMessage() throws NSException {
141 return nativeCreateMessage();
145 * Request to publish resource to cloud server
148 * servAdd combined with IP address and port number using
151 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
153 * @throws NSException failed to publish resource
155 public int enableRemoteService(String servAdd) throws NSException {
156 return nativeEnableRemoteService(servAdd);
160 * Request to cancel remote service using cloud server
163 * servAdd combined with IP address and port number using
166 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
168 * @throws NSException failed to publish resource
170 public int disableRemoteService(String servAdd) throws NSException {
171 return nativeDisableRemoteService(servAdd);
175 * Request to subscribe to MQ server
178 * servAdd combined with IP address and port number and MQ broker
179 * uri using delimiter
181 * the interest Topic name for subscription
183 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
185 * @throws NSException failed to subscribe to MQ server
187 public int subscribeMQService(String servAdd, String topicName)
189 return nativeSubscribeMQService(servAdd, topicName);
193 * Add topic to topic list
198 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
200 * @throws NSException failed to add topic
202 public int registerTopic(String topicName) throws NSException {
203 return nativeRegisterTopic(topicName);
207 * Delete topic from topic list
212 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
214 * @throws NSException failed to delete topic
216 public int unregisterTopic(String topicName) throws NSException {
217 return nativeUnregisterTopic(topicName);
221 * Request topics list already registered by provider user
224 * @return result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
226 * @throws NSException failed to get topics list
228 public TopicsList getRegisteredTopicList() throws NSException {
229 return nativeGetRegisteredTopicList();
233 * Interface to implement callback function to receive subscription request
236 public interface OnConsumerSubscribedListener {
239 * Callback function to receive subscription request of consumer
242 * Consumer who subscribes the notification message resource
244 public void onConsumerSubscribed(Consumer consumer);
248 * Interface to implement callback function to receive the status of the
249 * message synchronization
251 public interface OnMessageSynchronizedListener {
254 * Callback function to receive the status of the message
258 * Synchronization information of the notification message
260 public void onMessageSynchronized(SyncInfo syncInfo);
263 public native int nativeStart(
264 OnConsumerSubscribedListener subscribedListener,
265 OnMessageSynchronizedListener messageSynchronized,
266 boolean subControllability, String userInfo,
267 boolean resourceSecurity) throws NSException;
269 public native int nativeStop() throws NSException;
271 public native int nativeSendMessage(Message message) throws NSException;
273 public native void nativeSendSyncInfo(long messageId, int type)
276 public native Message nativeCreateMessage() throws NSException;
278 public native int nativeEnableRemoteService(String servAdd)
281 public native int nativeDisableRemoteService(String servAdd)
284 public native int nativeSubscribeMQService(String servAdd, String topicName)
287 public native int nativeRegisterTopic(String topicName) throws NSException;
289 public native int nativeUnregisterTopic(String topicName)
292 public native TopicsList nativeGetRegisteredTopicList() throws NSException;