update the header for Doxygen
[platform/framework/native/bluetooth.git] / src / FNetBt_BluetoothGapSystemAdapter.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file    FNetBt_BluetoothGapSystemAdapter.h
19  * @brief   This is the header file for the _BluetoothGapSystemAdapter class.
20  *
21  * This header file contains the declaration of the _BluetoothGapSystemAdapter class.
22  */
23 #ifndef _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_
24 #define _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_
25
26 #include <bluetooth.h>
27 #include <FBaseObject.h>
28 #include <FBaseResult.h>
29 #include <FBaseColLinkedListT.h>
30 #include <FNetBtBluetoothTypes.h>
31
32 static const int _BT_ADDRESS_LENGTH = 6;
33
34 // forward declarations
35 namespace Tizen { namespace Base { namespace Collection
36 {
37 class IList;
38 } } }
39
40 namespace Tizen { namespace Net { namespace Bluetooth
41 {
42
43 // forward declarations
44 class BluetoothDevice;
45 class _IBluetoothDeviceEventListener;
46 class _IBluetoothManagerEventListener;
47 class _BluetoothIpcProxy;
48
49 /**
50  * @class   _BluetoothGapSystemAdapter
51  * @brief   This class provides functions related to deliver the system events to the listeners such as
52  *          _BluetoothManagerImpl. This class is a type of singleton, therefore only one instance should be allowed.
53  */
54 class _BluetoothGapSystemAdapter
55         : public Tizen::Base::Object
56 {
57 public:
58         /**
59          * Creates an instance of this class if there is no instance in this application context.
60          * Gets the exist instance because this class is a singleton, otherwise.
61          *
62          * @return      the instance of this class
63          */
64         static _BluetoothGapSystemAdapter* GetInstance(void);
65
66
67         /**
68          * Register an instance of _IBluetoothManagerEventListener interface into the internal list.
69          *
70          * @return      An error code
71          * @param[in]   listener                The instance of _IBluetoothManagerEventListener to be registered
72          * @param[in]   isHighPriority          Set to @c true to register with the high priority, @n
73          *                                      else @c false
74          * @exception   E_SUCCESS               The method is successful.
75          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
76          */
77         result RegisterManagerEventListener(const _IBluetoothManagerEventListener& listener, bool isHighPriority);
78
79         /**
80          * Unregister an instance of _IBluetoothManagerEventListener interface from the internal list.
81          *
82          * @return      An error code
83          * @param[in]   listener                The instance of _IBluetoothManagerEventListener to be unregistered
84          * @exception   E_SUCCESS               The method is successful.
85          * @exception   E_OBJ_NOT_FOUND         The input instance is not registered.
86          */
87         result UnregisterManagerEventListener(const _IBluetoothManagerEventListener& listener);
88
89         /**
90          * Register an instance of _IBluetoothDeviceEventListener interface into the internal list.
91          *
92          * @return      An error code
93          * @param[in]   listener                The instance of _IBluetoothDeviceEventListener to be registered
94          * @exception   E_SUCCESS               The method is successful.
95          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
96          */
97         result RegisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener);
98
99         /**
100          * Unregister an instance of _IBluetoothDeviceEventListener interface from the internal list.
101          *
102          * @return      An error code
103          * @param[in]   listener                The instance of _IBluetoothDeviceEventListener to be unregistered
104          * @exception   E_SUCCESS               The method is successful.
105          * @exception   E_OBJ_NOT_FOUND         The input instance is not registered.
106          */
107         result UnregisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener);
108
109         /**
110          * Activates %Bluetooth module.
111          *
112          * @return      An error code
113          * @exception   E_SUCCESS               The method is successful.
114          * @exception   E_FAILURE               The method failed.
115          */
116         result Activate(void);
117
118         /**
119          * Deactivates %Bluetooth module.
120          *
121          * @return      An error code
122          * @exception   E_SUCCESS               The method is successful.
123          * @exception   E_FAILURE               The method failed.
124          */
125         result Deactivate(void);
126
127         /**
128          * Checks whether the %Bluetooth is activated or not.
129          *
130          * @return       @c true, if activated @n
131          *               @c false, otherwise
132          */
133         bool IsActivated(void) const;
134
135         /**
136          * Checks if the Bluetooth-specific profile is available.
137          *
138          * @return      @c true if connection is available @n
139          *              @c false, otherwise
140          * @param[in]   type                    The connection type to check availability
141          */
142         bool IsAvailable(BluetoothConnectionType type) const;
143
144         /**
145          * Gets the local %Bluetooth device address.
146          *
147          * @return      The local %Bluetooth device address
148          */
149         Tizen::Base::String GetLocalDeviceAddress(void) const;
150
151         /**
152          * Gets the discoverable mode of the local device.
153          *
154          * @return       The discoverable mode of the local device
155          */
156         BluetoothDiscoverableMode GetDiscoverableMode(void) const;
157
158         /**
159          * Gets the remaining time, in seconds, until the local device is not discoverable.
160          *
161          * @return      The remaining time, in seconds, until the local device to be not discoverable.
162          */
163         int GetRemainingTimeAsDiscoverable(void) const;
164
165         /**
166          * Gets all Paired Device list.
167          *
168          * @return       Pointer to the paired device list on success @n
169          *               @c null, otherwise.
170          * @remarks      It is caller's responsibility that deletes the result list.
171          */
172         Tizen::Base::Collection::IList* GetAllPairedDeviceListN(void) const;
173
174         /**
175          * Pairs(Bonds) with the specified remote device.
176          *
177          * @return      An error code
178          * @param[in]   deviceAddress           The address of a remote device to pair with
179          * @exception   E_SUCCESS               The method is successful.
180          * @exception   E_SYSTEM                A system error occurred.
181          */
182         result Pair(const Tizen::Base::ByteBuffer& deviceAddress);
183
184         /**
185          * Cancels the pairing in progress.
186          *
187          * @return      An error code
188          * @exception   E_SUCCESS               The method is successful.
189          * @exception   E_SYSTEM                A system error occurred.
190          */
191         result CancelPair(void);
192
193         /**
194          * Unpairs(Unbonds) with the specified paired device.
195          *
196          * @return      An error code
197          * @param[in]   deviceAddress           The address of the paired device to unpair with
198          * @exception   E_SUCCESS               The method is successful.
199          * @exception   E_SYSTEM                A system error occurred.
200          */
201         result Unpair(const Tizen::Base::ByteBuffer& deviceAddress);
202
203         /**
204          * Checks if this device is paired with the specified remote device.
205          *
206          * @return      @c true if the device is paired @n
207          *              @c false, otherwise
208          * @param[in]   deviceAddress           The address of a remote device to check
209          * @exception   E_SUCCESS               The method is successful.
210          * @exception   E_SYSTEM                A system error occurred.
211          */
212         bool IsPaired(const Tizen::Base::ByteBuffer& deviceAddress) const;
213
214         /**
215          * Starts a device discovery process.
216          *
217          * @return       An error code
218          * @exception    E_SUCCESS              The method is successful.
219          * @exception    E_SYSTEM               A system error occurred.
220          */
221         result StartDiscovery(void);
222
223         /**
224          * Stops the discovery in progress.
225          *
226          * @return       An error code
227          * @exception    E_SUCCESS              The method is successful.
228          * @exception    E_SYSTEM               A system error occurred.
229          */
230         result CancelDiscovery(void);
231
232         /**
233          * Checks whether the device discovery is in progress or not.
234          *
235          * @return       @c true, if in progress @n
236          *               @c false, otherwise
237          */
238         bool IsDiscoveryInProgress(void) const;
239
240         /**
241          * Retrieves the service list from a remote device.
242          *
243          * @return       An error code
244          * @param[in]    deviceAddress          The address of a remote device which the service list is retrieved from
245          * @exception    E_SUCCESS              The method is successful.
246          * @exception    E_SYSTEM               A system error occurred.
247          */
248         result RetrieveServiceList(const Tizen::Base::ByteBuffer& deviceAddress);
249
250
251         /**
252          * Gets the information of the specified paired device.
253          *
254          * @return       An error code
255          * @param[in]    address                The address of a paired device
256          * @param[out]   pairedDevice           The remote device instance whose information to be filled in
257          * @exception    E_SUCCESS              The method is successful.
258          * @exception    E_SYSTEM               A system error occurred.
259          */
260         static result GetPairedDevice(const Tizen::Base::ByteBuffer& address, BluetoothDevice& pairedDevice);
261
262         /**
263          * Callback to notify the change in the state of Bluetooth adapter.
264          */
265         static void OnAdapterStateChanged(int status, bt_adapter_state_e adapterState, void* pUserdata);
266
267         /**
268          * Callback to notify the change in the visibility mode of Bluetooth adapter.
269          */
270         static void OnVisibilityModeChanged(int result, bt_adapter_visibility_mode_e mode, void* pUserdata);
271
272         /**
273          * Callback to notify when you get bonded devices repeatedly.
274          */
275         static bool OnPairedDeviceFound(bt_device_info_s* pDeviceInfo, void* pUserdata);
276
277         /**
278          * Callback to notify when the state of the device discovery changes.
279          */
280         static void OnDeviceDiscoveryStateChanged(int status, bt_adapter_device_discovery_state_e discoveryState,
281                                                                 bt_adapter_device_discovery_info_s* pDiscoveryInfo, void* pUserdata);
282
283         /**
284          * Callback to notify when the process of service discovery is completed.
285          */
286         static void OnServiceDiscoveryCompleted(int status, bt_device_sdp_info_s* pSdpInfo, void* pUserdata);
287
288         /**
289          * Callback to notify that a new remote device is paired with this local device.
290          */
291         static void OnPairingCompleted(int status, bt_device_info_s* pDeviceInfo, void* pUserdata);
292
293         /**
294          * Callback to notify that the already paired device is unpaired with this local device.
295          */
296         static void OnPairedDeviceRemoved(int status, char* pRemoteAddress, void* pUserdata);
297
298         /**
299          * Callback to notify when the state of the device connection changes.
300          */
301         static void OnConnectionStateChanged(bool isConnected, const char* pRemoteAddress, void* pUserdata);
302
303
304 private:
305         _BluetoothGapSystemAdapter(void);
306         ~_BluetoothGapSystemAdapter(void);
307
308         _BluetoothGapSystemAdapter(const _BluetoothGapSystemAdapter& value);
309         _BluetoothGapSystemAdapter& operator =(const _BluetoothGapSystemAdapter& value);
310
311         bool Construct(void);
312
313         static void InitSingleton(void);
314
315 private:
316         Tizen::Base::Collection::LinkedListT<_IBluetoothManagerEventListener*> __mgrEvtListenerList;
317         Tizen::Base::Collection::LinkedListT<_IBluetoothDeviceEventListener*> __devEvtListenerList;
318         static _BluetoothGapSystemAdapter* __pInstance;
319
320 }; // _BluetoothGapSystemAdapter
321
322 } } }
323 #endif // _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_