1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 package org.iotivity.service.ns.consumer;
23 import android.util.Log;
24 import org.iotivity.service.ns.common.*;
25 import java.util.Vector;
29 * This class provides a set of Java APIs for Notification ConsumerService.
32 public class ConsumerService {
34 private static final String LOG_TAG = "ConsumerService";
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");
49 private static ConsumerService instance;
51 instance = new ConsumerService();
55 * API for getting instance of ConsumerService
57 * @return ConsumerService singleton instance created
59 public static ConsumerService getInstance() {
64 * This API will Start ConsumerService
66 * @param onProviderDiscoveredListener
67 * OnProviderDiscoveredListener Callback Interface
70 * if the parameter passed is null
72 public void start(OnProviderDiscoveredListener onProviderDiscoveredListener)
74 nativeStart(onProviderDiscoveredListener);
78 * This API will Stop ConsumerService
80 public void stop() throws NSException {
85 * Request to publish resource to cloud server
87 * @param serverAddress
88 * serverAddress combined with IP address and port number using
91 public void enableRemoteService(String serverAddress) throws NSException {
92 nativeEnableRemoteService(serverAddress);
96 * Request to subscribe to MQ server
99 * servAdd combined with IP address and port number and MQ broker
100 * uri using delimiter
102 * the interest Topic name for subscription
104 * @throws NSException failed to subscribe to MQ server
106 public void subscribeMQService(String servAdd, String topicName)
108 nativeSubscribeMQService(servAdd, topicName);
112 * This API is called to request discovery manually
114 public void rescanProvider() throws NSException {
115 nativeRescanProvider();
119 * Interface to implement callback function to receive provider on discovery
121 public interface OnProviderDiscoveredListener {
124 * Callback function to receive provider on discovery
129 public void onProviderDiscovered(Provider provider);
132 private native void nativeStart(
133 OnProviderDiscoveredListener onProviderDiscoveredListener)
136 private native void nativeStop() throws NSException;
138 private native void nativeEnableRemoteService(String serverAddress)
141 private native void nativeSubscribeMQService(String servAdd,
142 String topicName) throws NSException;
144 private native void nativeRescanProvider() throws NSException;