1 /* ****************************************************************
3 * Copyright 2014 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 ******************************************************************/
24 * This file contains the APIs for BT EDR communications.
27 #ifndef __CA_EDRCORE_H_
28 #define __CA_EDRCORE_H_
33 #include "cathreadpool.h"
42 typedef void (*CAPacketReceiveCallback)(const char *address, const char *data);
46 * @brief Initialize JNI object
47 * @param env [IN] JNI interface pointer
48 * @param jvm [IN] java virtual machine pointer
51 void CAEDRServerJniInit(JNIEnv *env, JavaVM *jvm);
54 * @brief Initialize server for EDR
55 * @param handle [IN] thread pool handle object
58 void CAEDRServerInitialize(ca_thread_pool_t handle);
61 * @brief Start unicast server
62 * @param address [IN] remote address
63 * @param isSecured [IN] unicast server type
64 * @return Returns -1 on error and 0 on success
66 int32_t CAEDRStartUnicastServer(const char *address, bool isSecured);
69 * @brief Start multicast server
70 * @param isSecured [IN] multicst server type
71 * @return Returns -1 on error and 0 on success
73 int32_t CAEDRStartMulticastServer(bool isSecured);
76 * @brief Stop unicast server
77 * @param serverID [IN] unicast server id
78 * @return Returns -1 on error and 0 on success
80 int32_t CAEDRStopUnicastServer(int32_t serverID);
83 * @brief Stop multicast server
84 * @param serverID [IN] multicast server id
85 * @return Returns -1 on error and 0 on success
87 int32_t CAEDRStopMulticastServer(int32_t serverID);
94 * @brief This function will read the data from remote device.
95 * @param env [IN] JNI interface pointer
96 * @param id [IN] index of remote address
97 * @param type [IN] EDR server type
98 * @return #CA_STATUS_OK or Appropriate error code
100 CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id, CAAdapterServerType_t type);
103 * @brief This function will listen the connection from remote device.
104 * @param env [IN] JNI interface pointer
105 * @return server socket object or NULL
107 jobject CAEDRNativeListen(JNIEnv *env);
110 * @brief This function will accept the connection from remote device.
111 * @param env [IN] JNI interface pointer
112 * @param severSocketObject [IN] server socket object
115 void CAEDRNativeAccept(JNIEnv *env, jobject severSocketObject);
118 * @brief This function will accept the connection from remote device.
119 * @param env [IN] JNI interface pointer
120 * @param address [IN] remote address
121 * @param id [IN] index of remote address
124 void CAEDRNativeServerSocketClose(JNIEnv *env, const char *address, uint32_t id);
131 * @brief This function will create the device state list.
134 void CAEDRServerNativeCreateDeviceStateList();
137 * @brief Update connection state of device
138 * @param state [IN] connection state
139 * @param address [IN] remote address
142 void CAEDRServerUpdateDeviceState(uint32_t state, const char *address);
145 * @brief Add device object to the list
146 * @param state [IN] connection state object
149 void CAEDRServerNativeAddDeviceStateToList(state_t *state);
152 * @brief Check whether the device exist in the list or not
153 * @param remoteAddress [IN] remote address
154 * @return TRUE or FALSE
156 jboolean CAEDRServerNativeIsDeviceInList(const char *remoteAddress);
159 * @brief Remove all device objects in the list
162 void CAEDRServerNativeRemoveAllDeviceState();
165 * @brief Remove target device in the list
166 * @param remoteAddress [IN] remote address
169 void CAEDRServerNativeRemoveDevice(const char *remoteAddress);
172 * @brief Check whether the state is connected or disconnected
173 * @param remoteAddress [IN] remote address
174 * @return TRUE or FALSE
176 jboolean CAEDRServerIsConnectedDevice(const char *remoteAddress);
179 * @brief Reordering for the list
180 * @param index [IN] index of device list that want to reordering
183 void CAEDRServerReorderingDeviceList(uint32_t index);
186 * Bluetooth Socket Object List
190 * @brief This function will create the device socket list.
193 void CAEDRServerNativeCreateDeviceSocketList();
196 * @brief Add device object to the list
197 * @param env [IN] JNI interface pointer
198 * @param deviceSocket [IN] device socket object
201 void CAEDRServerNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket);
204 * @brief Add device object to the list
205 * @param env [IN] JNI interface pointer
206 * @param remoteAddress [IN] remote address
207 * @return TRUE or FALSE
209 jboolean CAEDRServerNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress);
212 * @brief Add device object to the list
213 * @param env [IN] JNI interface pointer
216 void CAEDRServerNativeRemoveAllDeviceSocket(JNIEnv *env);
219 * @brief Add device object to the list
220 * @param env [IN] JNI interface pointer
221 * @param deviceSocket [IN] device socket object
224 void CAEDRServerNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket);
227 * @brief Get device socket object from the list
228 * @param idx [IN] index of device list
229 * @return Device socket object or NULL
231 jobject CAEDRServerNativeGetDeviceSocket(uint32_t idx);
234 * @brief Get length of device socket list
235 * @return length of list
237 uint32_t CAEDRServerGetSocketListLength();
240 * @brief Reordering for the list
241 * @param index [IN] index of device list that want to reordering
244 void CAEDRServerReorderingDeviceSocketList(uint32_t index);