Merge branch 'notification-service'
[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     public enum ProviderState
36     {
37         ALLOW(1),
38         DENY(2),
39         TOPIC(3),
40         STOPPED(12);
41         private int state;
42
43         private ProviderState(int state)
44         {
45             this.state = state;
46         }
47
48         public int getProviderState()
49         {
50             return this.state;
51         }
52     };
53
54     public String mProviderId        = null;
55     private long mNativeHandle       = 0;
56
57     public Provider(String providerId)
58     {
59         Log.i (LOG_TAG, "Provider()");
60
61         mProviderId = providerId;
62     }
63
64     public String getProviderId()
65     {
66         return mProviderId ;
67     }
68
69     public TopicsList getTopicList() throws NSException
70     {
71         return nativeGetTopicList();
72     }
73
74     public ProviderState getProviderState() throws NSException
75     {
76         return nativeGetProviderState();
77     }
78
79     public void subscribe() throws NSException
80     {
81         nativeSubscribe();
82     }
83
84     public boolean isSubscribed () throws NSException
85     {
86         return nativeIsSubscribed();
87     }
88
89     public void sendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException
90     {
91         nativeSendSyncInfo(messageId, syncType.ordinal());
92     }
93
94     public void setListener(OnProviderStateListener onProviderStateListener,
95                             OnMessageReceivedListner onMessageReceivedListner,
96                             OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException
97     {
98         nativeSetListener(onProviderStateListener, onMessageReceivedListner, onSyncInfoReceivedListner);
99     }
100
101     public int updateTopicList(TopicsList topicsList) throws NSException
102     {
103         return nativeUpdateTopicList(topicsList);
104     }
105
106     public interface OnProviderStateListener
107     {
108         public void onProviderStateReceived(ProviderState state);
109     }
110
111     public interface OnMessageReceivedListner
112     {
113         public void onMessageReceived(Message message);
114     }
115
116     public interface OnSyncInfoReceivedListner
117     {
118         public void onSyncInfoReceived(SyncInfo sync);
119     }
120
121     private native void nativeSubscribe() throws NSException;
122     private native void nativeSendSyncInfo(long messageId, int syncType) throws NSException;
123     private native void nativeSetListener(OnProviderStateListener onProviderStateListener,
124                                       OnMessageReceivedListner onMessageReceivedListner,
125                                       OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException;
126     public native TopicsList  nativeGetTopicList() throws NSException;
127     private native int nativeUpdateTopicList(TopicsList topicsList) throws NSException;
128     private native ProviderState nativeGetProviderState() throws NSException;
129     public native boolean  nativeIsSubscribed() throws NSException;
130
131 }