Replace glib threadpool usage with a 'dumb' thread implementation.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caedrserver.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 typedef void (*CAPacketReceiveCallback)(const char *address, const char *data);
43
44
45 /**
46  * @brief   Initialize JNI object
47  * @param   env              [IN] JNI interface pointer
48  * @param   jvm              [IN] java virtual machine pointer
49  * @return  None
50  */
51 void CAEDRServerJniInit(JNIEnv *env, JavaVM *jvm);
52
53 /**
54  * @brief  Initialize server for EDR
55  * @param   handle           [IN] thread pool handle object
56  * @return  None
57  */
58 void CAEDRServerInitialize(ca_thread_pool_t handle);
59
60 /**
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
65  */
66 int32_t CAEDRStartUnicastServer(const char *address, bool isSecured);
67
68 /**
69  * @brief   Start multicast server
70  * @param   isSecured       [IN] multicst server type
71  * @return  Returns -1 on error and 0 on success
72  */
73 int32_t CAEDRStartMulticastServer(bool isSecured);
74
75 /**
76  * @brief   Stop unicast server
77  * @param   serverID        [IN] unicast server id
78  * @return  Returns -1 on error and 0 on success
79  */
80 int32_t CAEDRStopUnicastServer(int32_t serverID);
81
82 /**
83  * @brief   Stop multicast server
84  * @param   serverID        [IN] multicast server id
85  * @return  Returns -1 on error and 0 on success
86  */
87 int32_t CAEDRStopMulticastServer(int32_t serverID);
88
89 /**
90  * EDR Method
91  */
92
93 /**
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
99  */
100 CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id, CAAdapterServerType_t type);
101
102 /**
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
106  */
107 jobject CAEDRNativeListen(JNIEnv *env);
108
109 /**
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
113  * @return None
114  */
115 void CAEDRNativeAccept(JNIEnv *env, jobject severSocketObject);
116
117 /**
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
122  * @return None
123  */
124 void CAEDRNativeServerSocketClose(JNIEnv *env, const char *address, uint32_t id);
125
126 /**
127  * BT State List
128  */
129
130 /**
131  * @brief  This function will create the device state list.
132  * @return None
133  */
134 void CAEDRServerNativeCreateDeviceStateList();
135
136 /**
137  * @brief  Update connection state of device
138  * @param  state            [IN] connection state
139  * @param  address          [IN] remote address
140  * @return None
141  */
142 void CAEDRServerUpdateDeviceState(uint32_t state, const char *address);
143
144 /**
145  * @brief  Add device object to the list
146  * @param  state            [IN] connection state object
147  * @return None
148  */
149 void CAEDRServerNativeAddDeviceStateToList(state_t *state);
150
151 /**
152  * @brief  Check whether the device exist in the list or not
153  * @param  remoteAddress    [IN] remote address
154  * @return TRUE or FALSE
155  */
156 jboolean CAEDRServerNativeIsDeviceInList(const char *remoteAddress);
157
158 /**
159  * @brief   Remove all device objects in the list
160  * @return  None
161  */
162 void CAEDRServerNativeRemoveAllDeviceState();
163
164 /**
165  * @brief   Remove target device in the list
166  * @param   remoteAddress    [IN] remote address
167  * @return  None
168  */
169 void CAEDRServerNativeRemoveDevice(const char *remoteAddress);
170
171 /**
172  * @brief  Check whether the state is connected or disconnected
173  * @param  remoteAddress    [IN] remote address
174  * @return TRUE or FALSE
175  */
176 jboolean CAEDRServerIsConnectedDevice(const char *remoteAddress);
177
178 /**
179  * @brief   Reordering for the list
180  * @param   index           [IN] index of device list that want to reordering
181  * @return  None
182  */
183 void CAEDRServerReorderingDeviceList(uint32_t index);
184
185 /**
186  * Bluetooth Socket Object List
187  */
188
189 /**
190  * @brief  This function will create the device socket list.
191  * @return None
192  */
193 void CAEDRServerNativeCreateDeviceSocketList();
194
195 /**
196  * @brief  Add device object to the list
197  * @param  env              [IN] JNI interface pointer
198  * @param  deviceSocket     [IN] device socket object
199  * @return None
200  */
201 void CAEDRServerNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket);
202
203 /**
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
208  */
209 jboolean CAEDRServerNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress);
210
211 /**
212  * @brief  Add device object to the list
213  * @param  env              [IN] JNI interface pointer
214  * @return None
215  */
216 void CAEDRServerNativeRemoveAllDeviceSocket(JNIEnv *env);
217
218 /**
219  * @brief  Add device object to the list
220  * @param  env              [IN] JNI interface pointer
221  * @param  deviceSocket     [IN] device socket object
222  * @return None
223  */
224 void CAEDRServerNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket);
225
226 /**
227  * @brief  Get device socket object from the list
228  * @param  idx              [IN] index of device list
229  * @return Device socket object or NULL
230  */
231 jobject CAEDRServerNativeGetDeviceSocket(uint32_t idx);
232
233 /**
234  * @brief  Get length of device socket list
235  * @return length of list
236  */
237 uint32_t CAEDRServerGetSocketListLength();
238
239 /**
240  * @brief   Reordering for the list
241  * @param   index           [IN] index of device list that want to reordering
242  * @return  None
243  */
244 void CAEDRServerReorderingDeviceSocketList(uint32_t index);
245
246
247 #ifdef __cplusplus
248 } /* extern "C" */
249 #endif
250
251 #endif
252