Updated JAVA and JNI API's for Topic Resource
[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   * @class   ConsumerService
29   * @brief   This class provides a set of Java APIs for Notification Consumer.
30   */
31 public class ConsumerService
32 {
33     private static final String LOG_TAG = "ConsumerService";
34
35     static
36     {
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     public enum Response
50     {
51         ALLOW(1),
52         DENY(2),
53         TOPIC(3);
54         private int type;
55
56         private Response(int type)
57         {
58             this.type = type;
59         }
60
61         public int getResponseType()
62         {
63             return this.type;
64         }
65     };
66
67     private static ConsumerService instance;
68     static
69     {
70         instance = new ConsumerService();
71     }
72     public static ConsumerService getInstance()
73     {
74         return instance;
75     }
76
77     public ConsumerService()
78     {
79         Log.i (LOG_TAG, "ConsumerService()");
80     }
81
82     public void Start(
83         OnProviderDiscoveredListner onProviderDiscoveredListner,
84         OnProviderChangedListener onProviderChangedListener
85     ) throws NSException
86     {
87         nativeStart(onProviderDiscoveredListner, onProviderChangedListener);
88     }
89
90     public void Stop() throws NSException
91     {
92         nativeStop();
93     }
94
95     public void EnableRemoteService(String serverAddress) throws NSException
96     {
97         nativeEnableRemoteService(serverAddress);
98     }
99
100     public void RescanProvider() throws NSException
101     {
102         nativeRescanProvider();
103     }
104
105     public Provider GetProvider(String providerId) throws NSException
106     {
107         return nativeGetProvider(providerId);
108     }
109
110     public Message GetMessage(long  messageId) throws NSException
111     {
112         return nativeGetMessage(messageId);
113     }
114
115     public interface OnProviderDiscoveredListner
116     {
117         public void onProviderDiscovered(Provider provider);
118     }
119
120     public interface OnProviderChangedListener
121     {
122         public void onProviderChanged(Provider provider , Response response);
123     }
124
125     private native void nativeStart (
126         OnProviderDiscoveredListner onProviderDiscoveredListner,
127         OnProviderChangedListener onProviderChangedListener
128     ) throws NSException;
129
130     private native void nativeStop() throws NSException;
131     private native void nativeEnableRemoteService(String serverAddress) throws NSException;
132     private native void nativeRescanProvider() throws NSException;
133     private native Provider nativeGetProvider(String providerId) throws NSException;
134     private native Message nativeGetMessage(long messageId) throws NSException;
135 }