Merge branch 'master' into 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
26 /**
27   * @class   Provider
28   * @brief   This class provides implementation of Notification Provider object.
29   */
30 public class Provider
31 {
32     private static final String LOG_TAG = "ConsumerService_Provider";
33
34     public String mProviderId        = null;
35     private long mNativeHandle       = 0;
36
37     public Provider(String providerId)
38     {
39         Log.i (LOG_TAG, "Provider()");
40
41         mProviderId = providerId;
42     }
43
44     public String getProviderId()
45     {
46         return mProviderId ;
47     }
48
49     public void Subscribe() throws NSException
50     {
51         nativeSubscribe();
52     }
53
54     public void Unsubscribe() throws NSException
55     {
56         nativeUnsubscribe();
57     }
58
59     public void SendSyncInfo(long messageId, SyncInfo.SyncType syncType) throws NSException
60     {
61         nativeSendSyncInfo(messageId, syncType.ordinal());
62     }
63
64     public void SetListener(OnMessageReceivedListner onMessageReceivedListner,
65                             OnSyncInfoReceivedListner onSyncInfoReceivedListner) throws NSException
66     {
67         nativeSetListener(onMessageReceivedListner, onSyncInfoReceivedListner);
68     }
69
70     public interface OnMessageReceivedListner
71     {
72         public void onMessageReceived(Message message);
73     }
74
75     public interface OnSyncInfoReceivedListner
76     {
77         public void onSyncInfoReceived(SyncInfo sync);
78     }
79
80     private native void nativeSubscribe() throws NSException;
81     private native void nativeUnsubscribe() throws NSException;
82     private native void nativeSendSyncInfo(long messageId, int syncType) throws NSException;
83     private native void nativeSetListener(
84         OnMessageReceivedListner onMessageReceivedListner,
85         OnSyncInfoReceivedListner onSyncInfoReceivedListner
86     ) throws NSException;
87 }