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;
21 import org.iotivity.service.ns.common.*;
22 import java.util.Vector;
24 * @class ProviderService
25 * @brief This class provides a set of Java APIs for Notification ProviderService.
27 public class ProviderService
32 System.loadLibrary("gnustl_shared");
33 System.loadLibrary("oc_logger");
34 System.loadLibrary("connectivity_abstraction");
35 System.loadLibrary("ca-interface");
36 System.loadLibrary("octbstack");
37 System.loadLibrary("oc");
38 System.loadLibrary("ocstack-jni");
39 System.loadLibrary("notification_provider");
40 System.loadLibrary("notification_provider_wrapper");
41 System.loadLibrary("notification_provider_jni");
44 private static ProviderService instance;
48 instance = new ProviderService();
52 * API for getting instance of ProviderService
53 * @return ProviderService singleton instance created
55 public static ProviderService getInstance()
61 * Start ProviderService
62 * @param subscribedListener - OnConsumerSubscribedListener Callback
63 * @param messageSynchronized - OnMessageSynchronizedListener Callback
64 * @param subControllability - Set the policy for notification servcie which checks whether
65 * provider is capable of denying the subscription of notification message from consumer and
66 * getting controllabliity to set consumer topic list.
67 * If true, provider is able to control subscription request and consumer topic list.
68 * Otherwise(policy is false), consumer can do the same.
69 * @param userInfo - User defined information such as device friendly name
70 * @param resourceSecurity - Set on/off for secure resource channel setting
71 * @return :: result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
73 public int start(OnConsumerSubscribedListener subscribedListener,
74 OnMessageSynchronizedListener messageSynchronized,
75 boolean subControllability, String userInfo,
76 boolean resourceSecurity) throws NSException
78 return nativeStart(subscribedListener, messageSynchronized,
79 subControllability, userInfo, resourceSecurity);
83 * Stop ProviderService
84 * @return :: result code
86 public int stop() throws NSException
92 * Send notification message to all subscribers
93 * @param message - Notification message including id, title, contentText
94 * @return :: result code
96 public int sendMessage(Message message) throws NSException
98 return nativeSendMessage(message);
102 * Send read-check to provider in order to synchronize notification status with other consumers
103 * @param messageId - ID of Notification message to synchronize the status
104 * @param syncType - SyncType of the SyncInfo message
106 public void sendSyncInfo ( long messageId , SyncInfo.SyncType syncType) throws NSException
108 nativeSendSyncInfo(messageId, syncType.ordinal());
112 * Initialize Message class, Mandatory fields which are messge id and provider(device) id are filled with.
115 public Message createMessage () throws NSException
117 return nativeCreateMessage();
121 * Request to publish resource to cloud server
122 * @param[in] servAdd combined with IP address and port number using delimiter :
123 * @return result code
125 public int enableRemoteService(String servAdd) throws NSException
127 return nativeEnableRemoteService(servAdd);
131 * Request to cancel remote service using cloud server
132 * @param[in] servAdd combined with IP address and port number using delimiter :
133 * @return result code
135 public int disableRemoteService(String servAdd) throws NSException
137 return nativeDisableRemoteService(servAdd);
141 * Add topic to topic list
142 * @param topicName - Topic name to add
143 * @return :: result code
145 public int registerTopic(String topicName) throws NSException
147 return nativeRegisterTopic(topicName);
151 * Delete topic from topic list
152 * @param topicName - Topic name to add
153 * @return :: result code
155 public int unregisterTopic(String topicName) throws NSException
157 return nativeUnregisterTopic(topicName);
161 * Request topics list already registered by provider user
162 * @return :: Topic list
164 public TopicsList getRegisteredTopicList() throws NSException
166 return nativeGetRegisteredTopicList();
170 * Interface to implement callback function to receive subscription request of consumer
172 public interface OnConsumerSubscribedListener
176 * Callback function to receive subscription request of consumer
177 * @param consumer - Consumer who subscribes the notification message resource
179 public void onConsumerSubscribed(Consumer consumer);
183 * Interface to implement callback function to receive the status of the message synchronization
185 public interface OnMessageSynchronizedListener
189 * Callback function to receive the status of the message synchronization
190 * @param syncInfo - Synchronization information of the notification message
192 public void onMessageSynchronized(SyncInfo syncInfo);
195 public native int nativeStart(OnConsumerSubscribedListener subscribedListener,
196 OnMessageSynchronizedListener messageSynchronized,
197 boolean subControllability, String userInfo,
198 boolean resourceSecurity) throws NSException;
199 public native int nativeStop() throws NSException;
200 public native int nativeSendMessage(Message message) throws NSException;
201 public native void nativeSendSyncInfo( long messageId , int type) throws NSException;
202 public native Message nativeCreateMessage() throws NSException;
203 public native int nativeEnableRemoteService(String servAdd) throws NSException;
204 public native int nativeDisableRemoteService(String servAdd) throws NSException;
205 public native int nativeRegisterTopic(String topicName) throws NSException;
206 public native int nativeUnregisterTopic(String topicName) throws NSException;
207 public native TopicsList nativeGetRegisteredTopicList() throws NSException;