Added CreateMessage API in Android APIs
[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 void Start(
78         OnProviderDiscoveredListner onProviderDiscoveredListner,
79         OnProviderChangedListener onProviderChangedListener
80     ) throws NSException
81     {
82         nativeStart(onProviderDiscoveredListner, onProviderChangedListener);
83     }
84
85     public void Stop() throws NSException
86     {
87         nativeStop();
88     }
89
90     public void EnableRemoteService(String serverAddress) throws NSException
91     {
92         nativeEnableRemoteService(serverAddress);
93     }
94
95     public void RescanProvider() throws NSException
96     {
97         nativeRescanProvider();
98     }
99
100     public Provider GetProvider(String providerId) throws NSException
101     {
102         return nativeGetProvider(providerId);
103     }
104
105     public Message GetMessage(long  messageId) throws NSException
106     {
107         return nativeGetMessage(messageId);
108     }
109
110     public interface OnProviderDiscoveredListner
111     {
112         public void onProviderDiscovered(Provider provider);
113     }
114
115     public interface OnProviderChangedListener
116     {
117         public void onProviderChanged(Provider provider , Response response);
118     }
119
120     private native void nativeStart (
121         OnProviderDiscoveredListner onProviderDiscoveredListner,
122         OnProviderChangedListener onProviderChangedListener
123     ) throws NSException;
124
125     private native void nativeStop() throws NSException;
126     private native void nativeEnableRemoteService(String serverAddress) throws NSException;
127     private native void nativeRescanProvider() throws NSException;
128     private native Provider nativeGetProvider(String providerId) throws NSException;
129     private native Message nativeGetMessage(long messageId) throws NSException;
130 }