Replace glib threadpool usage with a 'dumb' thread implementation.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caedrclient.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  *
24  * This file contains the APIs for BT EDR communications.
25  */
26
27 #ifndef __CA_EDRCORE_H_
28 #define __CA_EDRCORE_H_
29
30 #include <stdbool.h>
31
32 #include "cacommon.h"
33 #include "cathreadpool.h"
34 #include "jni.h"
35
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41
42 /**
43 * @brief   Set context of application
44 * @param   context          [IN] context of application
45 * @return  None
46 */
47 void CAEDRJniSetContext(jobject context);
48
49 /**
50 * @brief   Create JNI Object
51 * @param   context          [IN] context of application
52 * @return  None
53 */
54 void CAEDRCreateJNIInterfaceObject(jobject context);
55
56 /**
57  * @brief   Initialize client for EDR
58  * @param   handle           [IN] thread pool handle object
59  * @return  None
60  */
61 void CAEDRInitialize(ca_thread_pool_t handle);
62
63 /**
64  * @brief   Terminate server for EDR
65  * @return  None
66  */
67 void CAEDRTerminate();
68
69 /**
70  * @brief   Initialize JNI object
71  * @param   env              [IN] JNI interface pointer
72  * @param   jvm              [IN] java virtual machine pointer
73  * @return  None
74  */
75 void CAEDRCoreJniInit(JNIEnv *env, JavaVM *jvm);
76
77 /**
78  * @brief   Send data for unicast
79  * @param   address         [IN] remote address
80  * @param   data            [IN] data for transmission
81  * @param   dataLen         [IN] data length
82  * @return  #CA_STATUS_OK or Appropriate error code
83  * @retval  #CA_STATUS_OK  Successful
84  * @retval  #CA_STATUS_FAILED Operation failed
85  */
86 CAResult_t CAEDRSendUnicastMessage(const char *address,
87                             const char *data, uint32_t dataLen);
88
89 /**
90  * @brief   Send data for multicast
91  * @param   data            [IN] data for transmission
92  * @param   dataLen         [IN] data length
93  * @return  #CA_STATUS_OK or Appropriate error code
94  * @retval  #CA_STATUS_OK  Successful
95  * @retval  #CA_STATUS_FAILED Operation failed
96  */
97 CAResult_t CAEDRSendMulticastMessage(const char *data, uint32_t dataLen);
98
99 /**
100  * @brief   Get Local EDR Address
101  * @param   address         [OUT] local address
102  * @return  #CA_STATUS_OK or Appropriate error code
103  * @retval  #CA_STATUS_OK  Successful
104  * @retval  #CA_STATUS_FAILED Operation failed
105  */
106 CAResult_t CAEDRGetInterfaceInfo(char **address);
107
108 /**
109  * @brief   Get address from a local device
110  * @param   address         [OUT] local address
111  * @return  None
112  */
113 void CAEDRGetLocalAddress(char **address);
114
115 /**
116  * @brief   Send data for unicast (implement)
117  * @param   address         [IN] remote address
118  * @param   data            [IN] data for transmission
119  * @param   dataLen         [IN] data length
120  * @return  #CA_STATUS_OK or Appropriate error code
121  * @retval  #CA_STATUS_OK  Successful
122  * @retval  #CA_STATUS_FAILED Operation failed
123  */
124 CAResult_t CAEDRSendUnicastMessageImpl(const char *address,
125                         const char *data, uint32_t dataLen);
126
127 /**
128  * @brief   Send data for multicast (implement)
129  * @param   env             [IN] JNI interface pointer
130  * @param   data            [IN] data for transmission
131  * @param   dataLen         [IN] data length
132  * @return  #CA_STATUS_OK or Appropriate error code
133  * @retval  #CA_STATUS_OK  Successful
134  * @retval  #CA_STATUS_FAILED Operation failed
135  */
136 CAResult_t CAEDRSendMulticastMessageImpl(JNIEnv *env, const char *data, uint32_t dataLen);
137
138 /**
139  * EDR Method
140  */
141
142 /**
143  * @brief  This function will send the data to remote device.
144  * @param  env              [IN] JNI interface pointer
145  * @param  address          [IN] Remote Address
146  * @param  data             [IN] Data to be transmitted from EDR
147  * @param  id               [IN] index of remote address
148  * @return None
149  */
150 void CAEDRNativeSendData(JNIEnv *env, const char *address, const char *data, uint32_t id);
151
152 /**
153  * @brief  This function will connect to remote device.
154  * @param  env              [IN] JNI interface pointer
155  * @param  address          [IN] Remote Address
156  * @param  id               [IN] index of remote address
157  * @return None
158  */
159 void CAEDRNativeConnect(JNIEnv *env, const char *address, uint32_t id);
160
161 /**
162  * @brief  This function will close socket.
163  * @param  env              [IN] JNI interface pointer
164  * @param  address          [IN] Remote Address
165  * @param  id               [IN] index of remote address
166  * @return None
167  */
168 void CAEDRNativeSocketClose(JNIEnv *env, const char *address, uint32_t id);
169
170 /**
171  * BT State List
172  */
173
174 /**
175  * @brief  This function will create the device state list.
176  * @return None
177  */
178 void CAEDRNativeCreateDeviceStateList();
179
180 /**
181  * @brief  Update connection state of device
182  * @param  state            [IN] connection state
183  * @param  address          [IN] remote address
184  * @return None
185  */
186 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address);
187
188 /**
189  * @brief  Add device object to the list
190  * @param  state            [IN] connection state object
191  * @return None
192  */
193 void CAEDRNativeAddDeviceStateToList(state_t *state);
194
195 /**
196  * @brief  Check whether the device exist in the list or not
197  * @param  remoteAddress    [IN] remote address
198  * @return TRUE or FALSE
199  */
200 jboolean CAEDRNativeIsDeviceInList(const char *remoteAddress);
201
202 /**
203  * @brief   Remove all device objects in the list
204  * @return  None
205  */
206 void CAEDRNativeRemoveAllDeviceState();
207
208 /**
209  * @brief   Remove target device in the list
210  * @param   remoteAddress    [IN] remote address
211  * @return  None
212  */
213 void CAEDRNativeRemoveDevice(const char *remoteAddress);
214
215 /**
216  * @brief  Get current device connection state
217  * @param  remoteAddress    [IN] remote address
218  * @return STATE_DISCONNECTED or STATE_CONNECTED
219  */
220 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress);
221
222 /**
223  * @brief   Reordering for the list
224  * @param   index           [IN] index of device list that want to reordering
225  * @return  None
226  */
227 void CAEDRReorderingDeviceList(uint32_t index);
228
229 /**
230  * Bluetooth Socket Object List
231  */
232
233 /**
234  * @brief  This function will create the device socket list.
235  * @return None
236  */
237 void CAEDRNativeCreateDeviceSocketList();
238
239 /**
240  * @brief  Add device object to the list
241  * @param  env              [IN] JNI interface pointer
242  * @param  deviceSocket     [IN] device socket object
243  * @return None
244  */
245 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket);
246
247 /**
248  * @brief  Add device object to the list
249  * @param  env              [IN] JNI interface pointer
250  * @param  remoteAddress    [IN] remote address
251  * @return TRUE or FALSE
252  */
253 jboolean CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress);
254
255 /**
256  * @brief  Add device object to the list
257  * @param  env              [IN] JNI interface pointer
258  * @return None
259  */
260 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env);
261
262 /**
263  * @brief  Add device object to the list
264  * @param  env              [IN] JNI interface pointer
265  * @param  deviceSocket     [IN] device socket object
266  * @return None
267  */
268 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket);
269
270 /**
271  * @brief  Get device socket object from the list
272  * @param  idx              [IN] index of device list
273  * @return Device socket object or NULL
274  */
275 jobject CAEDRNativeGetDeviceSocket(uint32_t idx);
276
277 /**
278  * @brief  Get length of device socket list
279  * @return length of list
280  */
281 uint32_t CAEDRGetSocketListLength();
282
283 /**
284  * @brief   Reordering for the list
285  * @param   index           [IN] index of device list that want to reordering
286  * @return  None
287  */
288 void CAEDRReorderingDeviceSocketList(uint32_t index);
289
290 #ifdef __cplusplus
291 } /* extern "C" */
292 #endif
293
294 #endif
295