Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_edr_adapter / tizen / caedrdevicelist.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 provides APIs to manage discovered bluetooth device list.
25  */
26
27 #ifndef CA_EDR_DEVICE_LIST_H_
28 #define CA_EDR_DEVICE_LIST_H_
29
30 #include "cacommon.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 /**
38  * Structure to maintain the data needs to send to peer Bluetooth device.
39  */
40 typedef struct
41 {
42     void *data;             /**< Data to be sent to peer Bluetooth device. */
43     uint32_t dataLength;    /**< Length of the data. */
44 } EDRData;
45
46 /**
47  * Structure to maintain list of data needs to send to peer Bluetooth device.
48  */
49 typedef struct _EDRDataList
50 {
51     EDRData *data;            /**< Data to be sent to peer Bluetooth device. */
52     struct _EDRDataList *next;/**< Reference to next data in list. */
53 } EDRDataList;
54
55 /**
56  * Structure to maintain information of peer Bluetooth device.
57  */
58 typedef struct
59 {
60     char *remoteAddress;        /**< Address of peer Bluetooth device. */
61     char *serviceUUID;          /**< OIC service UUID running in peer Bluetooth device. */
62     int socketFD;           /**< RfComm connection socket FD. */
63     EDRDataList *pendingDataList;/**< List of data needs to send to peer Bluetooth device. */
64     bool serviceSearched;   /**< Flag to indicate the status of service search. */
65 } EDRDevice;
66
67 /**
68  * Structure to maintain list of peer Bluetooth device information.
69  */
70 typedef struct _EDRDeviceList
71 {
72     EDRDevice *device;            /**< Bluetooth device information. */
73     struct _EDRDeviceList *next;  /**< Reference to next device information. */
74 } EDRDeviceList;
75
76 /**
77  * Creates ::EDRDevice for specified remote address and uuid and to device list.
78  *
79  * @param[in/out]  deviceList       Device list which created device add to.
80  * @param[in]      deviceAddress    Bluetooth device address.
81  * @param[in]      uuid             Service uuid.
82  * @param[in]      device           Created ::EDRDevice.
83  *
84  * @return ::CA_STATUS_OK or Appropriate error code.
85  * @retval ::CA_STATUS_OK  Successful.
86  * @retval ::CA_STATUS_INVALID_PARAM Invalid input parameters.
87  * @retval ::CA_STATUS_FAILED Failed to create device and add to list.
88  */
89 CAResult_t CACreateAndAddToDeviceList(EDRDeviceList **deviceList, const char *deviceAddress,
90                                       const char *uuid, EDRDevice **device);
91
92 /**
93  * Insert device to specified list.
94  *
95  * @param[in/out]  deviceList        Device list to which specifed @device to be added.
96  * @param[in]      device            Device to be added to list.
97  *
98  * @return ::CA_STATUS_OK or Appropriate error code.
99  * @retval ::CA_STATUS_OK  Successful.
100  * @retval ::CA_STATUS_INVALID_PARAM Invalid input parameters.
101  * @retval ::CA_MEMORY_ALLOC_FAILED Memory allocation failed.
102  */
103 CAResult_t CAAddEDRDeviceToList(EDRDeviceList **deviceList, EDRDevice *device);
104
105 /**
106  * Get the device from list which matches specified device address.
107  *
108  * @param[in]   deviceList     Device list to search for the device.
109  * @param[in]   deviceAddress  Device address used for matching.
110  * @param[out]  device         ::EDRDevice which has matching device address.
111  *
112  * @return ::CA_STATUS_OK or Appropriate error code.
113  * @retval ::CA_STATUS_OK  Successful.
114  * @retval ::CA_STATUS_INVALID_PARAM Invalid input parameters.
115  * @retval ::CA_STATUS_FAILED Device is not found in the list.
116  */
117 CAResult_t CAGetEDRDevice(EDRDeviceList *deviceList,
118                            const char *deviceAddress, EDRDevice **device);
119
120 /**
121  * Get the device from list which matches specified RFCOMM socket id.
122  *
123  * @param[in]   deviceList  Device list to search for the device.
124  * @param[in]   socketID    RFCOMM socket id.
125  * @param[out]  device      ::EDRDevice which has matching RFCOMM socket id .
126  *
127  * @return ::CA_STATUS_OK or Appropriate error code.
128  * @retval ::CA_STATUS_OK  Successful.
129  * @retval ::CA_STATUS_INVALID_PARAM Invalid input parameters.
130  * @retval ::CA_STATUS_FAILED Device is not found in the list.
131  */
132 CAResult_t CAGetEDRDeviceBySocketId(EDRDeviceList *deviceList, int32_t socketID,
133                                     EDRDevice **device);
134
135 /**
136  * Remove and delete the device matching specified device address from list.
137  *
138  * @param[in/out]  deviceList        Device list to search for the device.
139  * @param[in]      deviceAddress     Bluetooth device address.
140  *
141  * @return ::CA_STATUS_OK or Appropriate error code.
142  * @retval ::CA_STATUS_OK  Successful.
143  * @retval ::CA_STATUS_INVALID_PARAM Invalid input parameters.
144  * @retval ::CA_STATUS_FAILED Device is not found in the list.
145  */
146 CAResult_t CARemoveEDRDeviceFromList(EDRDeviceList **deviceList,
147                                     const char *deviceAddress);
148
149 /**
150  * Destroy the specified device list. Removes and delete all the devices in the list.
151  * @param[in/out]  deviceList      Device list to be destroyed.
152  */
153 void CADestroyEDRDeviceList(EDRDeviceList **deviceList);
154
155 /**
156  * Insert data to specified list.
157  *
158  * @param[in]  dataList        Data list to which data will be add.
159  * @param[in]  data            Data to be stored.
160  * @param[in]  dataLength      Length of the data.
161  *
162  * @return ::CA_STATUS_OK or Appropriate error code.
163  * @retval ::CA_STATUS_OK  Successful.
164  * @retval ::CA_STATUS_INVALID_PARAM Invalid input parameters.
165  * @retval ::CA_MEMORY_ALLOC_FAILED Memory allocation failed.
166  */
167 CAResult_t CAAddEDRDataToList(EDRDataList **dataList, const void *data, uint32_t dataLength);
168
169 /**
170  * Remove and delete data from front end of list.
171  * @param[in/out]  dataList      Data list from which data will be removed.
172  *
173  * @return ::CA_STATUS_OK or Appropriate error code.
174  * @retval ::CA_STATUS_OK  Successful.
175  * @retval ::CA_STATUS_INVALID_PARAM Invalid input parameters.
176  */
177 CAResult_t CARemoveEDRDataFromList(EDRDataList **dataList);
178
179 /**
180  * Destroy the specified data list. Removes and deletes all the data in the list.
181  * @param[in]  dataList      Data list to be destroyed.
182  */
183 void CADestroyEDRDataList(EDRDataList **dataList);
184
185 #ifdef __cplusplus
186 } /* extern "C" */
187 #endif
188
189 #endif /* CA_EDR_DEVICE_LIST_H_ */
190
191