Merge branch 'notification-service'
[platform/upstream/iotivity.git] / service / notification / android / notification-service / src / main / java / org / iotivity / service / ns / consumer / ConsumerService.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   ConsumerService
28   * @brief   This class provides a set of Java APIs for Notification Consumer.
29   */
30 public class ConsumerService
31 {
32     private static final String LOG_TAG = "ConsumerService";
33
34     static
35     {
36         System.loadLibrary("gnustl_shared");
37         System.loadLibrary("oc_logger");
38         System.loadLibrary("connectivity_abstraction");
39         System.loadLibrary("ca-interface");
40         System.loadLibrary("octbstack");
41         System.loadLibrary("oc");
42         System.loadLibrary("ocstack-jni");
43         System.loadLibrary("notification_consumer");
44         System.loadLibrary("notification_consumer_wrapper");
45         System.loadLibrary("notification_consumer_jni");
46     }
47
48     private static ConsumerService instance;
49     static
50     {
51         instance = new ConsumerService();
52     }
53     public static ConsumerService getInstance()
54     {
55         return instance;
56     }
57
58     public ConsumerService()
59     {
60         Log.i (LOG_TAG, "ConsumerService()");
61     }
62
63     public void Start(
64         OnProviderDiscoveredListner onProviderDiscoveredListner,
65         OnSubscriptionAcceptedListener onSubscriptionAcceptedListener
66     ) throws NSException
67     {
68         nativeStart(onProviderDiscoveredListner, onSubscriptionAcceptedListener);
69     }
70
71     public void Stop() throws NSException
72     {
73         nativeStop();
74     }
75
76     public void EnableRemoteService(String serverAddress) throws NSException
77     {
78         nativeEnableRemoteService(serverAddress);
79     }
80
81     public void RescanProvider() throws NSException
82     {
83         nativeRescanProvider();
84     }
85
86     public Provider GetProvider(String providerId) throws NSException
87     {
88         return nativeGetProvider(providerId);
89     }
90
91     public interface OnProviderDiscoveredListner
92     {
93         public void onProviderDiscovered(Provider provider);
94     }
95
96     public interface OnSubscriptionAcceptedListener
97     {
98         public void onSubscriptionAccepted(Provider provider);
99     }
100
101     private native void nativeStart (
102         OnProviderDiscoveredListner onProviderDiscoveredListner,
103         OnSubscriptionAcceptedListener onSubscriptionAcceptedListener
104     ) throws NSException;
105
106     private native void nativeStop() throws NSException;
107     private native void nativeEnableRemoteService(String serverAddress) throws NSException;
108     private native void nativeRescanProvider() throws NSException;
109     private native Provider nativeGetProvider(String providerId) throws NSException;
110 }