3dda268778a44cee1d202ade824b466931e1ed75
[platform/upstream/iotivity.git] / service / notification / android / notification-service / src / main / java / org / iotivity / service / ns / consumer / Provider.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
21 package org.iotivity.service.ns.consumer;
22
23 import android.util.Log;
24 import org.iotivity.service.ns.common.*;
25 import java.util.Vector;
26
27 /**
28   * @class   Provider
29   * @brief   This class provides implementation of Notification Provider object.
30   */
31 public class Provider
32 {
33     private static final String LOG_TAG = "ConsumerService_Provider";
34
35     /**
36       * ProviderState of Notification resource
37       */
38     public enum ProviderState
39     {
40         ALLOW(1),
41         DENY(2),
42         TOPIC(3),
43         STOPPED(12);
44         private int state;
45
46         private ProviderState(int state)
47         {
48             this.state = state;
49         }
50
51         public int getProviderState()
52         {
53             return this.state;
54         }
55     };
56
57     public String mProviderId        = null;
58     private long mNativeHandle       = 0;
59
60     /**
61       * Constructor of Provider.
62       * @param providerId - providerId of Provider.
63       */
64     public Provider(String providerId)
65     {
66         Log.i (LOG_TAG, "Provider()");
67
68         mProviderId = providerId;
69     }
70
71     /**
72       * API for getting providerId.
73       * @return ConsumerId as string.
74       */
75     public String getProviderId()
76     {
77         return mProviderId ;
78     }
79
80     /**
81       * API for getting for getting Topic List.
82       * @return TopicsList.
83       */
84     public TopicsList getTopicList() throws NSException
85     {
86         return nativeGetTopicList();
87     }
88
89     /**
90       * API for getting for getting ProviderState.
91       * @return ProviderState.
92       */
93     public ProviderState getProviderState() throws NSException
94     {
95         return nativeGetProviderState();
96     }
97
98     /**
99       * API for for requesting subscription of Notification service.
100       */
101     public void subscribe() throws NSException
102     {
103         nativeSubscribe();
104     }
105
106     /**
107       * API for for requesting subscription status from Provider of Notification service.
108       */
109     public boolean isSubscribed () throws NSException
110     {
111         return nativeIsSubscribed();
112     }
113
114     /**
115       * This method is for Sending SyncInfo of Notification service.
116       * @param messageId - id of  message.
117       * @param syncType - SyncType of Notification service.
118       */
119     public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException
120     {
121         nativeSendSyncInfo(messageId, syncType.ordinal());
122     }
123
124     /**
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.
129       */
130     public void setListener(OnProviderStateListener onProviderStateListener,
131                             OnMessageReceivedListner onMessageReceivedListner,
132                             OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException
133     {
134         nativeSetListener(onProviderStateListener, onMessageReceivedListner, onSyncInfoReceivedListner);
135     }
136
137     /**
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
141       */
142     public int updateTopicList(TopicsList topicsList) throws NSException
143     {
144         return nativeUpdateTopicList(topicsList);
145     }
146
147     /**
148       * Interface to implement callback function to receive provider state information
149       */
150     public interface OnProviderStateListener
151     {
152         /**
153           * Callback function to receive provider state information
154           * @param state - ProviderState
155           */
156         public void onProviderStateReceived(ProviderState state);
157     }
158
159     /**
160       * Interface to implement callback function to receive Notification Message
161       */
162     public interface OnMessageReceivedListner
163     {
164         /**
165           * Callback function to receive Notification Message
166           * @param message - Notification Message
167           */
168         public void onMessageReceived(Message message);
169     }
170
171     /**
172       * Interface to implement callback function to receive message read synchronization
173       */
174     public interface OnSyncInfoReceivedListner
175     {
176         /**
177           * Callback function to receive message read synchronization
178           * @param sync - SyncInfo
179           */
180         public void onSyncInfoReceived(SyncInfo sync);
181     }
182
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;
192
193 }