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 * @brief This class provides implementation of Notification Provider object.
33 private static final String LOG_TAG = "ConsumerService_Provider";
36 * ProviderState of Notification resource
38 public enum ProviderState
46 private ProviderState(int state)
51 public int getProviderState()
57 public String mProviderId = null;
58 private long mNativeHandle = 0;
61 * Constructor of Provider.
62 * @param providerId - providerId of Provider.
64 public Provider(String providerId)
66 Log.i (LOG_TAG, "Provider()");
68 mProviderId = providerId;
72 * API for getting providerId.
73 * @return ConsumerId as string.
75 public String getProviderId()
81 * API for getting for getting Topic List.
84 public TopicsList getTopicList() throws NSException
86 return nativeGetTopicList();
90 * API for getting for getting ProviderState.
91 * @return ProviderState.
93 public ProviderState getProviderState() throws NSException
95 return nativeGetProviderState();
99 * API for for requesting subscription of Notification service.
101 public void subscribe() throws NSException
107 * API for for requesting subscription status from Provider of Notification service.
109 public boolean isSubscribed () throws NSException
111 return nativeIsSubscribed();
115 * This method is for Sending SyncInfo of Notification service.
116 * @param messageId - id of message.
117 * @param syncType - SyncType of Notification service.
119 public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException
121 nativeSendSyncInfo(messageId, syncType.ordinal());
125 * This method is for registering for listeners of Notification .
126 * @param onProviderStateListener - OnProviderStateListener callback Interface.
127 * @param onMessageReceivedListner - OnMessageReceivedListner callback Interface.
128 * @param onSyncInfoReceivedListner - OnSyncInfoReceivedListner callback Interface.
130 public void setListener(OnProviderStateListener onProviderStateListener,
131 OnMessageReceivedListner onMessageReceivedListner,
132 OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException
134 nativeSetListener(onProviderStateListener, onMessageReceivedListner, onSyncInfoReceivedListner);
138 * Update Topic list that is wanted to be subscribed from provider
139 * @param topicsList - TopicsList of interested Topics.
140 * @return :: result code 100 = OK , 200 = ERROR , 300 = SUCCESS , 400 = FAIL
142 public int updateTopicList(TopicsList topicsList) throws NSException
144 return nativeUpdateTopicList(topicsList);
148 * Interface to implement callback function to receive provider state information
150 public interface OnProviderStateListener
153 * Callback function to receive provider state information
154 * @param state - ProviderState
156 public void onProviderStateReceived(ProviderState state);
160 * Interface to implement callback function to receive Notification Message
162 public interface OnMessageReceivedListner
165 * Callback function to receive Notification Message
166 * @param message - Notification Message
168 public void onMessageReceived(Message message);
172 * Interface to implement callback function to receive message read synchronization
174 public interface OnSyncInfoReceivedListner
177 * Callback function to receive message read synchronization
178 * @param sync - SyncInfo
180 public void onSyncInfoReceived(SyncInfo sync);
183 private native void nativeSubscribe() throws NSException;
184 private native void nativeSendSyncInfo(long messageId, int syncType) throws NSException;
185 private native void nativeSetListener(OnProviderStateListener onProviderStateListener,
186 OnMessageReceivedListner onMessageReceivedListner,
187 OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException;
188 public native TopicsList nativeGetTopicList() throws NSException;
189 private native int nativeUpdateTopicList(TopicsList topicsList) throws NSException;
190 private native ProviderState nativeGetProviderState() throws NSException;
191 public native boolean nativeIsSubscribed() throws NSException;