[TIZEN]Moved GMainloop to CSDK sample from network monitor[LE/EDR].
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / caleclient.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 functionalities of GATT Client. Functionalities
25  * like LE device discovery, connecting to the LE device with OIC service,
26  * registering to the service and there characteristics, registering to the
27  * change in the charateristics, setting the value of the characteristcs
28  * for the request and response will be done here.
29  */
30
31 #ifndef TZ_BLE_CLIENT_H_
32 #define TZ_BLE_CLIENT_H_
33
34 #include <bluetooth.h>
35 #include <bluetooth_type.h>
36 #include <bluetooth_type_internal.h>
37 #include <bluetooth_internal.h>
38
39 #include "cacommon.h"
40 #include "caadapterutils.h"
41 #include "caleutil.h"
42 #include "caadapterinterface.h"
43 #include "logger.h"
44 #include "cathreadpool.h"
45 #include "caleinterface.h"
46 #include "oic_malloc.h"
47
48
49 /**
50  * This callback is called when a characteristic value is changed by the GATT server.
51  *
52  * @param[in]  characteristic The attribute handle of characteristic.
53  * @param[in]  value          Value of the characteristics of a service.
54  * @param[in]  valueLen       Length of data.
55  * @param[in]  userData       The user data passed from the request function.
56  */
57 void CALEGattCharacteristicChangedCb(bt_gatt_h characteristic,
58                                      char *value, int valueLen, void *userData);
59 /**
60  * This callback will be called when the client write request is completed.
61  *
62  * @param[in]  result    Result of write value.
63  * @param[in]  reqHandle The request GATT handle.
64  * @param[in]  userData  User context
65  */
66 void CALEGattCharacteristicWriteCb(int result, bt_gatt_h reqHandle, void *userData);
67
68 /**
69  * This is the callback which will be called whenever there is change in gatt connection
70  * with server(Connected/Disconnected)
71  *
72  * @param[in]  connected     State of connection
73  * @param[in]  remoteAddress Mac address of the remote device in which we made connection.
74  */
75 void CALEGattConnectionStateChanged(bool connected, const char *remoteAddress);
76
77 /**
78  * This is the callback which will be called when LE advertisement is found.
79  *
80  * @param[in]  result         The result of Scanning
81  * @param[in]  scanInfo       Remote Device information.
82  * @param[in]  userData       The user data passed from the request function
83  */
84 void CALEAdapterScanResultCb(int result, bt_adapter_le_device_scan_result_info_s *scanInfo,
85                              void *userData);
86
87 /**
88  * This thread will be used to Start the timer for scanning.
89  *
90  * @param[in] data Currently it will be NULL(no parameter)
91  */
92 void CAStartTimerThread(void *data);
93
94 /**
95  * Used to initialize all required mutex variable for Gatt Client implementation.
96  *
97  * @return ::CA_STATUS_OK or Appropriate error code.
98  * @retval ::CA_STATUS_OK  Successful.
99  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
100  * @retval ::CA_STATUS_FAILED Operation failed.
101  */
102 CAResult_t CAInitGattClientMutexVariables();
103
104 /**
105  * Used to terminate all required mutex variable for Gatt Client implementation.
106  */
107 void CATerminateGattClientMutexVariables();
108
109 /**
110  * Used to register required callbacks to LE platform(connection, discovery, etc).
111  *
112  * @return ::CA_STATUS_OK or Appropriate error code.
113  * @retval ::CA_STATUS_OK  Successful.
114  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
115  * @retval ::CA_STATUS_FAILED Operation failed.
116  */
117 CAResult_t CALEGattSetCallbacks();
118
119 /**
120  * Used to unset all the registerd callbacks to BLE platform.
121  */
122 void CALEGattUnSetCallbacks();
123
124 /**
125  * Used to start LE Scanning.
126  *
127  * @return ::CA_STATUS_OK or Appropriate error code.
128  * @retval ::CA_STATUS_OK  Successful.
129  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
130  * @retval ::CA_STATUS_FAILED Operation failed.
131  */
132 CAResult_t CALEGattStartDeviceScanning();
133
134 /**
135  * Used to stop LE discovery for BLE  devices.
136  */
137 void CALEGattStopDeviceScanning();
138
139 /**
140  * This is the thread  which will be used for making gatt connection with
141  * remote devices.
142  * @param[in] remoteAddress MAC address of remote device to connect.
143  */
144 void CAGattConnectThread (void *remoteAddress);
145
146 /**
147  * Used to do connection with remote device.
148  *
149  * @param[in] remoteAddress Remote address inwhich we wants to connect with.
150  *
151  * @return ::CA_STATUS_OK or Appropriate error code.
152  * @retval ::CA_STATUS_OK  Successful.
153  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
154  * @retval ::CA_STATUS_FAILED Operation failed.
155  */
156 CAResult_t CALEGattConnect(const char *remoteAddress);
157
158 /**
159  * Used to do disconnection with remote device.
160  * @param[in] remoteAddress Remote address inwhich we wants to disconnect with.
161  *
162  * @return ::CA_STATUS_OK or Appropriate error code.
163  * @retval ::CA_STATUS_OK  Successful.
164  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
165  * @retval ::CA_STATUS_FAILED Operation failed.
166  */
167 CAResult_t CALEGattDisConnect(const char *remoteAddress);
168
169 /**
170  * This is thread which will be spawned for discovering ble services. Once
171  * called discover api, then it will be terminated.
172  * @param[in] remoteAddress Mac address of the remote device in which we
173  *                           want to search services.
174  */
175 void CADiscoverLEServicesThread (void *remoteAddress);
176
177 /**
178  * Used to discover the services and characteristics that is advertised by Gatt
179  * Server.
180  *
181  * @param[in] remoteAddress MAC address of remote device in which we want to discover
182  *                      the services and characteristics.
183  *
184  * @return ::CA_STATUS_OK or Appropriate error code.
185  * @retval ::CA_STATUS_OK  Successful.
186  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
187  * @retval ::CA_STATUS_FAILED Operation failed.
188  */
189 CAResult_t CALEGattDiscoverServices(const char *remoteAddress);
190 #endif /* TZ_BLE_CLIENT_H_ */