Replace glib threadpool usage with a 'dumb' thread implementation.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caedradapter.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 EDR adapters.
25  */
26
27 #ifndef __CA_EDRADAPTER_H_
28 #define __CA_EDRADAPTER_H_
29
30 /**
31  * EDR Interface AP
32  **/
33 #include "cacommon.h"
34 #include "caadapterinterface.h"
35 #include "cathreadpool.h" /* for thread pool */
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41
42 /**
43  * @brief  Initialize EDR Interface.
44  * @param  registerCallback  [IN] Callback to register EDR interface to Connectivity
45  *                                Abstraction Layer
46  * @param  reqRespCallback   [IN] Callback to notify request and response messages from server(s)
47  *                                started at Connectivity Abstraction Layer.
48  * @param  netCallback       [IN] Callback to notify the network additions to Connectivity
49  *                                Abstraction Layer.
50  * @param  handle            [IN] Threadpool Handle
51  * @return #CA_STATUS_OK or Appropriate error code
52  * @retval  #CA_STATUS_OK  Successful
53  * @retval  #CA_STATUS_INVALID_PARAM  Invalid input parameters
54  * @retval  #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
55  *                                  not enabled
56  * @retval  #CA_STATUS_FAILED Operation failed
57  */
58 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
59                            CANetworkPacketReceivedCallback reqRespCallback,
60                            CANetworkChangeCallback netCallback,
61                            ca_thread_pool_t handle);
62
63 /**
64  * @brief  Starts EDR connectivity adapters. As its peer to peer it doesnot require to start
65  *         any servers.
66  * @return #CA_STATUS_OK or Appropriate error code
67  * @retval  #CA_STATUS_OK  Successful
68  * @retval  #CA_ADAPTER_NOT_ENABLED Bluetooth adapter is not enabled
69  * @retval  #CA_STATUS_FAILED Operation failed
70  *
71  */
72 CAResult_t CAStartEDR();
73
74 /**
75  * @brief  Starts listening server for receiving multicast search requests.
76  * Starts  RFCOMM Server with prefixed UUID as per OIC specification.
77  *
78  * @return #CA_STATUS_OK or Appropriate error code
79  * @retval #CA_STATUS_OK  Successful
80  * @retval #CA_SERVER_STARTED_ALREADY  Server is already started and running for the predefined
81  *                                     service UUID
82  * @retval #CA_STATUS_FAILED Operation failed
83  *
84  */
85 CAResult_t CAStartEDRListeningServer();
86
87 /**
88  * @brief  Starting discovery server for receiving multicast advertisements.
89  * Starts  RFCOMM Server with prefixed UUID as per OIC specification.
90  *
91  * @return #CA_STATUS_OK or Appropriate error code
92  * @retval #CA_STATUS_OK  Successful
93  * @retval #CA_SERVER_STARTED_ALREADY  Server is already started and running for the predefined
94  *                                     service UUID
95  * @retval #CA_STATUS_FAILED Operation failed
96  */
97 CAResult_t CAStartEDRDiscoveryServer();
98
99 /**
100  * @brief  Sends data to the peer bluetooth OIC device using the adapter connectivity.
101  * @param  remoteEndpoint  [IN] Remote Endpoint information (like ipaddress, port, reference uri and
102  *                              connectivity type) to which the unicast data has to be sent.
103  * @param  data            [IN] Data to be sent.
104  * @param  dataLength      [IN] Size of data to be sent.
105  * @return The number of bytes sent on the network. Returns -1 on error.
106  *
107  */
108 int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
109                               uint32_t dataLength);
110
111 /**
112  * @brief  Sends multicast data to all discovered bluetooth OIC devices using the adapter
113  *         connectivity.
114  * @param  data         [IN]  Data which needs to be sent to all discovered bluetooth OIC device.
115  * @param  dataLength   [IN]  Length of data in bytes.
116  * @return Number of bytes sent on the network. Returns -1 on error.
117  */
118 int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength);
119
120 /**
121  * @brief  Get EDR Connectivity network information.
122  *
123  * @param  info [OUT] Array of local connectivity information structures.
124  * @param  size [OUT] Size of the array @info.
125  *
126  * @return #CA_STATUS_OK or Appropriate error code
127  * @retval #CA_STATUS_OK  Successful
128  * @retval #CA_STATUS_INVALID_PARAM  Invalid input parameters
129  * @retval #CA_MEMORY_ALLOC_FAILED  Failed to allocate memory
130  * @retval #CA_STATUS_FAILED Operation failed
131  * @remarks info is allocated in this API and should be freed by the caller.
132  */
133 CAResult_t CAGetEDRInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
134
135 /**
136  * @brief  Read Synchronous API callback.
137  * @return #CA_STATUS_OK on success otherwise proper error code.
138  * @retval #CA_STATUS_OK  Successful
139  * @retval #CA_STATUS_FAILED Operation failed
140  */
141 CAResult_t CAReadEDRData();
142
143 /**
144  * @brief  EDR Stops all RFCOMM servers and close sockets.
145  * @return #CA_STATUS_OK or Appropriate error code
146  */
147 CAResult_t CAStopEDR();
148
149 /**
150  * @brief  Terminate the EDR connectivity adapter.
151  * Configuration information will be deleted from further use.
152  * @return NONE
153  */
154 void CATerminateEDR();
155
156 /**
157  * @brief  Initializes the adapter queues.
158  * This will initiates both server and receiver adapter queues.
159  * @return #CA_STATUS_OK or Appropriate error code
160  * @retval #CA_STATUS_OK  Successful
161  * @retval #CA_STATUS_INVALID_PARAM  Invalid input parameters
162  * @retval #CA_MEMORY_ALLOC_FAILED  Failed to allocate memory
163  * @retval #CA_STATUS_FAILED Operation failed
164  */
165 CAResult_t CAAdapterStartQueue();
166
167 #ifdef __cplusplus
168 } /* extern "C" */
169 #endif
170
171 #endif  //__CA_EDRADAPTER_H_
172