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
80 * if any callback parameter passed is null
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);
91 * Stop ProviderService
93 * @throws NSException failed to stop ProviderService
95 public void stop() throws NSException {
100 * Send notification message to all subscribers
103 * Notification message including id, title, contentText
105 * @throws NSException failed to send notification message
107 public void sendMessage(Message message) throws NSException {
108 nativeSendMessage(message);
112 * Send read-check to provider in order to synchronize notification status
113 * with other consumers
116 * unique Id of Notification message to synchronize the status
118 * SyncType of the SyncInfo message
120 public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType)
122 nativeSendSyncInfo(messageId, syncType.ordinal());
126 * Initialize Message class, Mandatory fields which are messge id and
127 * provider(device) id are filled with
131 public Message createMessage() throws NSException {
132 return nativeCreateMessage();
136 * Request to publish resource to cloud server
139 * servAdd combined with IP address and port number using
142 * @throws NSException failed to publish resource
144 public void enableRemoteService(String servAdd) throws NSException {
145 nativeEnableRemoteService(servAdd);
149 * Request to cancel remote service using cloud server
152 * servAdd combined with IP address and port number using
155 * @throws NSException failed to publish resource
157 public void disableRemoteService(String servAdd) throws NSException {
158 nativeDisableRemoteService(servAdd);
162 * Request to subscribe to MQ server
165 * servAdd combined with IP address and port number and MQ broker
166 * uri using delimiter
168 * the interest Topic name for subscription
170 * @throws NSException failed to subscribe to MQ server
172 public void subscribeMQService(String servAdd, String topicName)
174 nativeSubscribeMQService(servAdd, topicName);
178 * Add topic to topic list
183 * @throws NSException failed to add topic
185 public void registerTopic(String topicName) throws NSException {
186 nativeRegisterTopic(topicName);
190 * Delete topic from topic list
195 * @throws NSException failed to delete topic
197 public void unregisterTopic(String topicName) throws NSException {
198 nativeUnregisterTopic(topicName);
202 * Request topics list already registered by provider user
204 * @throws NSException failed to get topics list
206 public TopicsList getRegisteredTopicList() throws NSException {
207 return nativeGetRegisteredTopicList();
211 * Interface to implement callback function to receive subscription request
214 public interface OnConsumerSubscribedListener {
217 * Callback function to receive subscription request of consumer
220 * Consumer who subscribes the notification message resource
222 public void onConsumerSubscribed(Consumer consumer);
226 * Interface to implement callback function to receive the status of the
227 * message synchronization
229 public interface OnMessageSynchronizedListener {
232 * Callback function to receive the status of the message
236 * Synchronization information of the notification message
238 public void onMessageSynchronized(SyncInfo syncInfo);
241 private native void nativeStart(
242 OnConsumerSubscribedListener subscribedListener,
243 OnMessageSynchronizedListener messageSynchronized,
244 boolean subControllability, String userInfo,
245 boolean resourceSecurity) throws NSException;
247 private native void nativeStop() throws NSException;
249 private native void nativeSendMessage(Message message) throws NSException;
251 private native void nativeSendSyncInfo(long messageId, int type)
254 private native Message nativeCreateMessage() throws NSException;
256 private native void nativeEnableRemoteService(String servAdd)
259 private native void nativeDisableRemoteService(String servAdd)
262 private native void nativeSubscribeMQService(String servAdd, String topicName)
265 private native void nativeRegisterTopic(String topicName) throws NSException;
267 private native void nativeUnregisterTopic(String topicName)
270 private native TopicsList nativeGetRegisteredTopicList() throws NSException;