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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 package org.iotivity.service.ns.consumer;
23 import android.util.Log;
24 import org.iotivity.service.ns.common.*;
25 import java.util.Vector;
29 * This class provides implementation of Notification Provider object.
32 public class Provider {
34 private static final String LOG_TAG = "ConsumerService_Provider";
37 * Enum for defining different state of provider object
39 public enum ProviderState {
47 private ProviderState(int state) {
51 public int getProviderState() {
56 private String mProviderId = null;
57 private long mNativeHandle = 0;
60 * Constructor of Provider.
63 * unique Id of Provider
65 public Provider(String providerId) {
66 Log.i(LOG_TAG, "Provider()");
68 mProviderId = providerId;
72 protected void finalize() throws Throwable {
75 } catch (Throwable t) {
82 * API for getting providerId
84 * @return ConsumerId as string
86 public String getProviderId() {
91 * API for getting for getting Topic List
95 public TopicsList getTopicList() throws NSException {
96 return nativeGetTopicList();
100 * API for getting for getting ProviderState
102 * @return ProviderState
104 public ProviderState getProviderState() throws NSException {
105 return nativeGetProviderState();
109 * API for requesting subscription of Notification service
110 * This API should be called with a valid Provider object obtained from Discovery callback.
111 * The API should not be called when the Provider is in STOPPED state.
113 * Discovery APIs to discover Providers are as below.
114 * Start/rescanProvider for D2D,
115 * enableRemoteService for D2S,
117 * @throws NSException failure to subscribe
119 public void subscribe() throws NSException {
124 * API for requesting unsubscription of Notification service
126 * This API should be called with a valid Provider object obtained from Discovery callback.
127 * The API should not be called when the Provider is in STOPPED state.
129 * @throws NSException failure to subscribe
131 public void unsubscribe() throws NSException {
136 * API for requesting subscription status from Provider of Notification
139 public boolean isSubscribed() throws NSException {
140 return nativeIsSubscribed();
144 * This method is for Sending SyncInfo of Notification service.
147 * unique Id of message
149 * SyncType of Notification service
151 public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType)
153 nativeSendSyncInfo(messageId, syncType.ordinal());
157 * This method is for registering for listeners of Notification .
159 * @param onProviderStateListener
160 * OnProviderStateListener callback Interface
161 * @param onMessageReceivedListner
162 * OnMessageReceivedListner callback Interface
163 * @param onSyncInfoReceivedListner
164 * OnSyncInfoReceivedListner callback Interface
166 public void setListener(OnProviderStateListener onProviderStateListener,
167 OnMessageReceivedListener onMessageReceivedListener,
168 OnSyncInfoReceivedListener onSyncInfoReceivedListener)
170 nativeSetListener(onProviderStateListener, onMessageReceivedListener,
171 onSyncInfoReceivedListener);
175 * Update Topic list that is wanted to be subscribed from provider
178 * TopicsList of interested Topics
180 * @throws NSException failure to update topic list.
182 public void updateTopicList(TopicsList topicsList) throws NSException {
183 nativeUpdateTopicList(topicsList);
187 * Interface to implement callback function to receive provider state
190 public interface OnProviderStateListener {
193 * Callback function to receive provider state information
198 public void onProviderStateReceived(ProviderState state);
202 * Interface to implement callback function to receive Notification Message
204 public interface OnMessageReceivedListener {
207 * Callback function to receive Notification Message.
210 * Notification Message
212 public void onMessageReceived(Message message);
216 * Interface to implement callback function to receive message read
219 public interface OnSyncInfoReceivedListener {
222 * Callback function to receive message read synchronization
227 public void onSyncInfoReceived(SyncInfo sync);
230 private native void nativeSubscribe() throws NSException;
231 private native void nativeUnsubscribe() throws NSException;
233 private native void nativeSendSyncInfo(long messageId, int syncType)
236 private native void nativeSetListener(
237 OnProviderStateListener onProviderStateListener,
238 OnMessageReceivedListener onMessageReceivedListener,
239 OnSyncInfoReceivedListener onSyncInfoReceivedListener)
242 private native TopicsList nativeGetTopicList() throws NSException;
244 private native void nativeUpdateTopicList(TopicsList topicsList)
247 private native ProviderState nativeGetProviderState() throws NSException;
249 private native boolean nativeIsSubscribed() throws NSException;
251 private native void nativeDispose();