removed unnecessary BLE interface method
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / android / caleserver.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 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 /**
22  * @file
23  * This file contains the APIs for BT LE communications.
24  */
25 #ifndef CA_LESERVER_H_
26 #define CA_LESERVER_H_
27
28 #include "cacommon.h"
29 #include "cathreadpool.h"
30 #include "uarraylist.h"
31 #include "jni.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37
38 /**
39  * Callback to be notified on reception of any data from remote devices.
40  * @param[in]  address           MAC address of remote device.
41  * @param[in]  data              Data received from remote device.
42  * @pre  Callback must be registered using CALEServerSetCallback(CAPacketReceiveCallback callback).
43  */
44 typedef void (*CAPacketReceiveCallback)(const char *address, const uint8_t *data);
45
46 /**
47  * initialize server for BLE.
48  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
49  */
50 CAResult_t CALEServerInitialize();
51
52 /**
53  * terminate client for BLE.
54  */
55 void CALEServerTerminate();
56
57 /**
58  * send data for unicast (interface).
59  * @param[in]   address          remote address.
60  * @param[in]   data             data for transmission.
61  * @param[in]   dataLen          data length.
62  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
63  */
64 CAResult_t CALEServerSendUnicastMessage(const char *address, const uint8_t *data, uint32_t dataLen);
65
66 /**
67  * send data for multicast (interface).
68  * @param[in]   data             data for transmission.
69  * @param[in]   dataLen          data length.
70  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
71  */
72 CAResult_t CALEServerSendMulticastMessage(const uint8_t *data, uint32_t dataLen);
73
74 /**
75  * start multicast server (start advertise).
76  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
77  */
78 CAResult_t CALEServerStartMulticastServer();
79
80 /**
81  * stop multicast server (stop discovery).
82  * @return  None
83  */
84 CAResult_t CALEServerStopMulticastServer();
85
86 /**
87  * set this callback for receiving data packets from peer devices.
88  * @param[in]   callback         callback to be notified on reception of
89  *                               unicast/multicast data packets.
90  */
91 void CALEServerSetCallback(CAPacketReceiveCallback callback);
92
93 /**
94  * send data for unicast (implement).
95  * @param[in]   env              JNI interface pointer.
96  * @param[in]   address          remote address.
97  * @param[in]   data             data for transmission.
98  * @param[in]   dataLen          data length.
99  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
100  */
101 CAResult_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char *address, const uint8_t *data,
102                                             uint32_t dataLen);
103
104 /**
105  * send data for multicast (implement)
106  * @param[in]   env              JNI interface pointer
107  * @param[in]   data             data for transmission
108  * @param[in]   dataLen          data length
109  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
110  */
111 CAResult_t CALEServerSendMulticastMessageImpl(JNIEnv *env, const uint8_t *data, uint32_t dataLen);
112
113 /**
114  * set context of application.
115  */
116 void CALEServerJNISetContext();
117
118 /**
119  * initialize JNI object.
120  */
121 void CALeServerJniInit();
122
123 /**
124  * create interface object and initialize the object.
125  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
126  */
127 CAResult_t CALEServerCreateJniInterfaceObject();
128
129 /**
130  * start advertise in gatt server.
131  */
132 CAResult_t CALEStartAdvertise();
133
134 /**
135  * start advertise in gatt server.
136  * @param[in]   env                JNI interface pointer.
137  * @param[in]   advertiseCallback  callback to be notified on reception of
138  *                                 advertisement result.
139  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
140  */
141 CAResult_t CALEServerStartAdvertise(JNIEnv *env, jobject advertiseCallback);
142
143 /**
144  * stop advertise in gatt server.
145  * @param[in]   env                JNI interface pointer.
146  * @param[in]   advertiseCallback  callback to be notified on reception of
147  *                                 advertisement result.
148  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
149  */
150 CAResult_t CALEServerStopAdvertise(JNIEnv *env, jobject advertiseCallback);
151
152 /**
153  * open a gatt server.
154  * @param[in]   env                JNI interface pointer.
155  * @return  gatt server object.
156  */
157 jobject CALEServerOpenGattServer(JNIEnv *env);
158
159 /**
160  * create gatt service
161  * @param[in]   env                JNI interface pointer
162  * @return  gatt service object
163  */
164 jobject CALEServerCreateGattService(JNIEnv *env);
165
166 /**
167  * add a descriptor to the characteristic.
168  * @param[in]   env                JNI interface pointer.
169  * @param[in]   characteristic     Characteristic object.
170  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
171  */
172 CAResult_t CALEServerAddDescriptor(JNIEnv *env, jobject characteristic);
173
174 /**
175  * create gatt service.
176  * @param[in]   env                  JNI interface pointer.
177  * @param[in]   bluetoothGattServer  Bluetooth Gatt Server object.
178  * @param[in]   bluetoothGattService Bluetooth Gatt Service object.
179  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
180  */
181 CAResult_t CALEServerAddGattService(JNIEnv *env, jobject bluetoothGattServer,
182                                     jobject bluetoothGattService);
183
184 /**
185  * start gatt server.
186  * @param[in]   env                  JNI interface pointer.
187  * @param[in]   gattServerCallback   callback to be notified on reception of
188  *                                   state change of gatt server.
189  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
190  */
191 CAResult_t CALEServerStartGattServer(JNIEnv *env, jobject gattServerCallback);
192
193 /**
194  * close gatt server.
195  * @param[in]   env                  JNI interface pointer.
196  * @param[in]   bluetoothGattServer  Gatt Server object.
197  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
198  */
199 CAResult_t CALEServerGattClose(JNIEnv *env, jobject bluetoothGattServer);
200 /**
201  * send data.
202  * @param[in]   env                  JNI interface pointer.
203  * @param[in]   bluetoothDevice      bluetooth device object.
204  * @param[in]   data                 data which send.
205  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
206  */
207 CAResult_t CALEServerSend(JNIEnv *env, jobject bluetoothDevice, jstring data);
208
209 /**
210  * set data in BluetoothGattCharacteristic.
211  * @param[in]   env                  JNI interface pointer.
212  * @param[in]   responseData         data to set in characteristic object.
213  * @return  BluetoothGattCharacteristic object.
214  */
215 jobject CALEServerSetResponseData(JNIEnv *env, jbyteArray responseData);
216
217 /**
218  * send data through notifyCharacteristicChanged api of android.
219  * @param[in]   env                  JNI interface pointer.
220  * @param[in]   device               bluetooth device object.
221  * @param[in]   responseData         data which send.
222  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
223  */
224 CAResult_t CALEServerSendResponseData(JNIEnv *env, jobject device, jobject responseData);
225
226 /**
227  * send a response to a write request to a remote device.
228  * @param[in]   env                  JNI interface pointer.
229  * @param[in]   device               bluetooth device object.
230  * @param[in]   requestId            the id of request.
231  * @param[in]   status               the status of the request to be sent to the remote devices.
232  * @param[in]   offset               value offset for partial write response.
233  * @param[in]   value                the value of the attribute that written (optional).
234  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
235  */
236 CAResult_t CALEServerSendResponse(JNIEnv *env, jobject device, jint requestId, jint status,
237                                   jint offset, jbyteArray value);
238
239 /**
240  * connect BLE to remote device form gatt server.
241  * @param[in]   env                  JNI interface pointer.
242  * @param[in]   bluetoothDevice      bluetooth device object.
243  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
244  */
245 CAResult_t CALEServerConnect(JNIEnv *env, jobject bluetoothDevice);
246
247 /**
248  * disconnect LE for all devices.
249  * @param[in]   env                  JNI interface pointer.
250  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
251  */
252 CAResult_t CALEServerDisconnectAllDevices(JNIEnv *env);
253
254 /**
255  * disconnect LE to remote device form gatt server.
256  * @param[in]   env                  JNI interface pointer.
257  * @param[in]   bluetoothDevice      bluetooth device object.
258  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
259  */
260 CAResult_t CALEServerDisconnect(JNIEnv *env, jobject bluetoothDevice);
261
262 /**
263  * create connected device list.
264  */
265 void CALEServerCreateCachedDeviceList();
266
267 /**
268  * check whether the device exist in the list or not.
269  * @param[in]   env                   JNI interface pointer.
270  * @param[in]   remoteAddress         remote address.
271  * @return  true or false.
272  */
273 bool CALEServerIsDeviceInList(JNIEnv *env, const char* remoteAddress);
274
275 /**
276  * add device object to the list (connected device list).
277  * @param[in]   env                   JNI interface pointer.
278  * @param[in]   device                bluetooth device object.
279  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
280  */
281 CAResult_t CALEServerAddDeviceToList(JNIEnv *env, jobject device);
282
283 /**
284  * remove all devices objects in the list (connected device list).
285  * @param[in]   env                   JNI interface pointer.
286  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
287  */
288 CAResult_t CALEServerRemoveAllDevices(JNIEnv *env);
289
290 /**
291  * remove target device in the list (connected device list).
292  * @param[in]   env                   JNI interface pointer.
293  * @param[in]   address               target address to remove.
294  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
295  */
296 CAResult_t CALEServerRemoveDevice(JNIEnv *env, jstring address);
297
298 /**
299  * initialize mutex.
300  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
301  */
302 CAResult_t CALEServerInitMutexVaraibles();
303
304 /**
305  * terminate mutex.
306  */
307 void CALEServerTerminateMutexVaraibles();
308
309 /**
310  * initialize condition.
311  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
312  */
313 CAResult_t CALEServerInitConditionVaraibles();
314
315 /**
316  * terminate condition.
317  */
318 void CALEServerTerminateConditionVaraibles();
319
320 #ifdef __cplusplus
321 } /* extern "C" */
322 #endif
323
324 #endif /* CA_LESERVER_H_ */