b15ba46dc5db84203eff530013bc753382ba230f
[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 import org.iotivity.service.ns.common.*;
22 import java.util.Vector;
23 /**
24   * @class   ProviderService
25   * @brief   This class provides a set of Java APIs for Notification ProviderService.
26   */
27 public class ProviderService
28 {
29
30     static
31     {
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");
42     }
43
44     private static ProviderService instance;
45
46     static
47     {
48         instance = new ProviderService();
49     }
50
51     /**
52       * API for getting instance of ProviderService
53       * @return ProviderService singleton instance created
54       */
55     public static ProviderService getInstance()
56     {
57         return instance;
58     }
59
60     /**
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
72       */
73     public int start(OnConsumerSubscribedListener  subscribedListener,
74                      OnMessageSynchronizedListener  messageSynchronized,
75                      boolean subControllability, String userInfo,
76                      boolean resourceSecurity) throws NSException
77     {
78         return nativeStart(subscribedListener, messageSynchronized,
79                             subControllability, userInfo, resourceSecurity);
80     }
81
82     /**
83       * Stop ProviderService
84       * @return :: result code
85       */
86     public int stop() throws NSException
87     {
88         return nativeStop();
89     }
90
91     /**
92       * Send notification message to all subscribers
93       * @param  message - Notification message including id, title, contentText
94       * @return :: result code
95       */
96     public int   sendMessage(Message message) throws NSException
97     {
98         return nativeSendMessage(message);
99     }
100
101     /**
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
105       */
106     public void sendSyncInfo ( long messageId , SyncInfo.SyncType syncType) throws NSException
107     {
108         nativeSendSyncInfo(messageId, syncType.ordinal());
109     }
110
111     /**
112       * Initialize Message class, Mandatory fields which are messge id and provider(device) id are filled with.
113       * @return Message
114       */
115     public Message createMessage () throws NSException
116     {
117         return nativeCreateMessage();
118     }
119
120     /**
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
124       */
125     public int   enableRemoteService(String servAdd) throws NSException
126     {
127         return nativeEnableRemoteService(servAdd);
128     }
129
130     /**
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
134       */
135     public int  disableRemoteService(String servAdd) throws NSException
136     {
137         return nativeDisableRemoteService(servAdd);
138     }
139
140     /**
141       * Add topic to topic list
142       * @param  topicName - Topic name to add
143       * @return :: result code
144       */
145     public int registerTopic(String topicName) throws NSException
146     {
147         return nativeRegisterTopic(topicName);
148     }
149
150     /**
151       * Delete topic from topic list
152       * @param  topicName - Topic name to add
153       * @return :: result code
154       */
155     public int unregisterTopic(String topicName) throws NSException
156     {
157         return nativeUnregisterTopic(topicName);
158     }
159
160     /**
161       * Request topics list already registered by provider user
162       * @return :: Topic list
163       */
164     public TopicsList getRegisteredTopicList() throws NSException
165     {
166         return nativeGetRegisteredTopicList();
167     }
168
169     /**
170       * Interface to implement callback function to receive subscription request of consumer
171       */
172     public interface OnConsumerSubscribedListener
173     {
174
175         /**
176           * Callback function to receive subscription request of consumer
177           * @param consumer - Consumer who subscribes the notification message resource
178           */
179         public void onConsumerSubscribed(Consumer consumer);
180     }
181
182     /**
183       * Interface to implement callback function to receive the status of the message synchronization
184       */
185     public interface OnMessageSynchronizedListener
186     {
187
188         /**
189           * Callback function to receive the status of the message synchronization
190           * @param syncInfo - Synchronization information of the notification message
191           */
192         public void onMessageSynchronized(SyncInfo syncInfo);
193     }
194
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;
208 }