1 /* ****************************************************************
3 * Copyright 2017 Samsung Electronics All Rights Reserved.
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 ******************************************************************/
23 * This file contains the APIs for BT LE communications.
25 #ifndef CA_LESERVER_H_
26 #define CA_LESERVER_H_
29 #include "cathreadpool.h"
30 #include "uarraylist.h"
32 #include "caleutils.h"
40 * Callback to be notified on reception of any data from remote devices.
41 * @param[in] address MAC address of remote device.
42 * @param[in] data Data received from remote device.
43 * @pre Callback must be registered using CALEServerSetCallback(CAPacketReceiveCallback callback).
45 typedef void (*CAPacketReceiveCallback)(const char *address, const uint8_t *data);
48 * initialize server for BLE.
49 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
51 CAResult_t CALEServerInitialize();
54 * terminate client for BLE.
56 void CALEServerTerminate();
59 * send data for unicast (interface).
60 * @param[in] address remote address.
61 * @param[in] data data for transmission.
62 * @param[in] dataLen data length.
63 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
65 CAResult_t CALEServerSendUnicastMessage(const char *address,
70 * send data for multicast (interface).
71 * @param[in] data data for transmission.
72 * @param[in] dataLen data length.
73 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
75 CAResult_t CALEServerSendMulticastMessage(const uint8_t *data, uint32_t dataLen);
78 * start multicast server (start advertise).
79 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
81 CAResult_t CALEServerStartMulticastServer();
84 * stop multicast server (stop discovery).
87 CAResult_t CALEServerStopMulticastServer();
90 * set this callback for receiving data packets from peer devices.
91 * @param[in] callback callback to be notified on reception of
92 * unicast/multicast data packets.
94 void CALEServerSetCallback(CAPacketReceiveCallback callback);
97 * send data for unicast (implement).
98 * @param[in] env JNI interface pointer.
99 * @param[in] address remote address.
100 * @param[in] data data for transmission.
101 * @param[in] dataLen data length.
102 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
104 CAResult_t CALEServerSendUnicastMessageImpl(const char *address,
109 * send data for multicast (implement)
110 * @param[in] env JNI interface pointer
111 * @param[in] data data for transmission
112 * @param[in] dataLen data length
113 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
115 CAResult_t CALEServerSendMulticastMessageImpl(const uint8_t *data,
119 * start advertise in gatt server.
121 CAResult_t CALEStartAdvertise();
124 * start advertise in gatt server.
125 * @param[in] env JNI interface pointer.
126 * @param[in] advertiseCallback callback to be notified on reception of
127 * advertisement result.
128 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
130 CAResult_t CALEServerStartAdvertise();
133 * stop advertise in gatt server.
134 * @param[in] env JNI interface pointer.
135 * @param[in] advertiseCallback callback to be notified on reception of
136 * advertisement result.
137 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
139 CAResult_t CALEServerStopAdvertise();
143 * @param[in] env JNI interface pointer.
144 * @param[in] gattServerCallback callback to be notified on reception of
145 * state change of gatt server.
146 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
148 CAResult_t CALEServerStartGattServer();
152 * @param[in] env JNI interface pointer.
153 * @param[in] bluetoothGattServer Gatt Server object.
154 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
156 //CAResult_t CALEServerGattClose();
159 * @param[in] env JNI interface pointer.
160 * @param[in] bluetoothDevice bluetooth device object.
161 * @param[in] data data which send.
162 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
164 CAResult_t CALEServerSend(CBCentral *central, const uint8_t *data, const uint32_t dataLen);
167 * disconnect LE for all devices.
168 * @param[in] env JNI interface pointer.
169 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
171 //CAResult_t CALEServerDisconnectAllDevices();
174 * create connected device list.
176 void CALEServerCreateCachedDeviceList();
179 * check whether the device exist in the list or not.
180 * @param[in] env JNI interface pointer.
181 * @param[in] remoteAddress remote address.
182 * @return true or false.
184 bool CALEServerIsDeviceInList(const char* remoteAddress);//, const char* serviceUUID);
187 * add device object to the list (connected device list).
188 * @param[in] env JNI interface pointer.
189 * @param[in] device bluetooth device object.
190 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
192 CAResult_t CALEServerAddDeviceToList(CBCentral *central);
195 * remove all devices objects in the list (connected device list).
196 * @param[in] env JNI interface pointer.
197 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
199 CAResult_t CALEServerRemoveAllDevices();
202 * remove target device in the list (connected device list).
203 * @param[in] env JNI interface pointer.
204 * @param[in] address target address to remove.
205 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
207 CAResult_t CALEServerRemoveDevice(const char *remoteAddr);
211 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
213 CAResult_t CALEServerInitMutexVaraibles();
218 void CALEServerTerminateMutexVaraibles();
221 * initialize condition.
222 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
224 CAResult_t CALEServerInitConditionVaraibles();
227 * terminate condition.
229 void CALEServerTerminateConditionVaraibles();
231 NSString *CALEServerGetAddressFromGattObj(CBCentral *central);
233 bool CALEServerIsEnableBTAdapter();
234 void CALEServerSetFlagBTAdapter(bool state);
240 #endif /* CA_LESERVER_H_ */