replace : iotivity -> iotivity-sec
[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 import java.util.Vector;
26
27 /**
28  *
29  * This class provides a set of Java APIs for Notification ConsumerService.
30  *
31  */
32 public class ConsumerService {
33
34     private static final String LOG_TAG = "ConsumerService";
35
36     static {
37         System.loadLibrary("gnustl_shared");
38         System.loadLibrary("oc_logger");
39         System.loadLibrary("connectivity_abstraction");
40         System.loadLibrary("ca-interface");
41         System.loadLibrary("octbstack");
42         System.loadLibrary("oc");
43         System.loadLibrary("ocstack-jni");
44         System.loadLibrary("notification_consumer");
45         System.loadLibrary("notification_consumer_wrapper");
46         System.loadLibrary("notification_consumer_jni");
47     }
48
49     private static ConsumerService instance;
50     static {
51         instance = new ConsumerService();
52     }
53
54     /**
55      * API for getting instance of ConsumerService
56      *
57      * @return ConsumerService singleton instance created
58      */
59     public static ConsumerService getInstance() {
60         return instance;
61     }
62
63     /**
64      * This API will Start ConsumerService
65      *
66      * @param onProviderDiscoveredListener
67      *            OnProviderDiscoveredListener Callback Interface
68      *
69      * @throws NSException
70      *             if the parameter passed is null
71      */
72     public void start(OnProviderDiscoveredListener onProviderDiscoveredListener)
73             throws NSException {
74         nativeStart(onProviderDiscoveredListener);
75     }
76
77     /**
78      * This API will Stop ConsumerService
79      */
80     public void stop() throws NSException {
81         nativeStop();
82     }
83
84     /**
85      * Request to publish resource to cloud server
86      *
87      * @param serverAddress
88      *            serverAddress combined with IP address and port number using
89      *            delimiter
90      */
91     public void enableRemoteService(String serverAddress) throws NSException {
92         nativeEnableRemoteService(serverAddress);
93     }
94
95     /**
96      * Request to subscribe to MQ server
97      *
98      * @param servAdd
99      *            servAdd combined with IP address and port number and MQ broker
100      *            uri using delimiter
101      * @param topicName
102      *            the interest Topic name for subscription
103      *
104      * @throws NSException failed to subscribe to MQ server
105      */
106     public void subscribeMQService(String servAdd, String topicName)
107             throws NSException {
108         nativeSubscribeMQService(servAdd, topicName);
109     }
110
111     /**
112      * This API is called to request discovery manually
113      */
114     public void rescanProvider() throws NSException {
115         nativeRescanProvider();
116     }
117
118     /**
119      * Interface to implement callback function to receive provider on discovery
120      */
121     public interface OnProviderDiscoveredListener {
122
123         /**
124          * Callback function to receive provider on discovery
125          *
126          * @param provider
127          *            Provider object
128          */
129         public void onProviderDiscovered(Provider provider);
130     }
131
132     private native void nativeStart(
133             OnProviderDiscoveredListener onProviderDiscoveredListener)
134             throws NSException;
135
136     private native void nativeStop() throws NSException;
137
138     private native void nativeEnableRemoteService(String serverAddress)
139             throws NSException;
140
141     private native void nativeSubscribeMQService(String servAdd,
142             String topicName) throws NSException;
143
144     private native void nativeRescanProvider() throws NSException;
145 }