2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FNetBt_BluetoothGapSystemAdapter.h
19 * @brief This is the header file for the _BluetoothGapSystemAdapter class.
21 * This header file contains the declaration of the _BluetoothGapSystemAdapter class.
23 #ifndef _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_
24 #define _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_
26 #include <bluetooth.h>
27 #include <FBaseObject.h>
28 #include <FBaseResult.h>
29 #include <FBaseColLinkedListT.h>
30 #include <FNetBtBluetoothTypes.h>
32 static const int _BT_ADDRESS_LENGTH = 6;
34 // forward declarations
35 namespace Tizen { namespace Base { namespace Collection
40 namespace Tizen { namespace Net { namespace Bluetooth
43 // forward declarations
44 class BluetoothDevice;
45 class _IBluetoothDeviceEventListener;
46 class _IBluetoothManagerEventListener;
47 class _BluetoothIpcProxy;
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.
54 class _BluetoothGapSystemAdapter
55 : public Tizen::Base::Object
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.
62 * @return the instance of this class
64 static _BluetoothGapSystemAdapter* GetInstance(void);
68 * Register an instance of _IBluetoothManagerEventListener interface into the internal list.
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
74 * @exception E_SUCCESS The method is successful.
75 * @exception E_OUT_OF_MEMORY The memory is insufficient.
77 result RegisterManagerEventListener(const _IBluetoothManagerEventListener& listener, bool isHighPriority);
80 * Unregister an instance of _IBluetoothManagerEventListener interface from the internal list.
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.
87 result UnregisterManagerEventListener(const _IBluetoothManagerEventListener& listener);
90 * Register an instance of _IBluetoothDeviceEventListener interface into the internal list.
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.
97 result RegisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener);
100 * Unregister an instance of _IBluetoothDeviceEventListener interface from the internal list.
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.
107 result UnregisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener);
110 * Activates %Bluetooth module.
112 * @return An error code
113 * @exception E_SUCCESS The method is successful.
114 * @exception E_FAILURE The method failed.
116 result Activate(void);
119 * Deactivates %Bluetooth module.
121 * @return An error code
122 * @exception E_SUCCESS The method is successful.
123 * @exception E_FAILURE The method failed.
125 result Deactivate(void);
128 * Checks whether the %Bluetooth is activated or not.
130 * @return @c true, if activated @n
131 * @c false, otherwise
133 bool IsActivated(void) const;
136 * Checks if the Bluetooth-specific profile is available.
138 * @return @c true if connection is available @n
139 * @c false, otherwise
140 * @param[in] type The connection type to check availability
142 bool IsAvailable(BluetoothConnectionType type) const;
145 * Gets the local %Bluetooth device address.
147 * @return The local %Bluetooth device address
149 Tizen::Base::String GetLocalDeviceAddress(void) const;
152 * Gets the discoverable mode of the local device.
154 * @return The discoverable mode of the local device
156 BluetoothDiscoverableMode GetDiscoverableMode(void) const;
159 * Gets the remaining time, in seconds, until the local device is not discoverable.
161 * @return The remaining time, in seconds, until the local device to be not discoverable.
163 int GetRemainingTimeAsDiscoverable(void) const;
166 * Gets all Paired Device list.
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.
172 Tizen::Base::Collection::IList* GetAllPairedDeviceListN(void) const;
175 * Pairs(Bonds) with the specified remote device.
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.
182 result Pair(const Tizen::Base::ByteBuffer& deviceAddress);
185 * Cancels the pairing in progress.
187 * @return An error code
188 * @exception E_SUCCESS The method is successful.
189 * @exception E_SYSTEM A system error occurred.
191 result CancelPair(void);
194 * Unpairs(Unbonds) with the specified paired device.
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.
201 result Unpair(const Tizen::Base::ByteBuffer& deviceAddress);
204 * Checks if this device is paired with the specified remote device.
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.
212 bool IsPaired(const Tizen::Base::ByteBuffer& deviceAddress) const;
215 * Starts a device discovery process.
217 * @return An error code
218 * @exception E_SUCCESS The method is successful.
219 * @exception E_SYSTEM A system error occurred.
221 result StartDiscovery(void);
224 * Stops the discovery in progress.
226 * @return An error code
227 * @exception E_SUCCESS The method is successful.
228 * @exception E_SYSTEM A system error occurred.
230 result CancelDiscovery(void);
233 * Checks whether the device discovery is in progress or not.
235 * @return @c true, if in progress @n
236 * @c false, otherwise
238 bool IsDiscoveryInProgress(void) const;
241 * Retrieves the service list from a remote device.
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.
248 result RetrieveServiceList(const Tizen::Base::ByteBuffer& deviceAddress);
252 * Gets the information of the specified paired device.
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.
260 static result GetPairedDevice(const Tizen::Base::ByteBuffer& address, BluetoothDevice& pairedDevice);
263 * Callback to notify the change in the state of Bluetooth adapter.
265 static void OnAdapterStateChanged(int status, bt_adapter_state_e adapterState, void* pUserdata);
268 * Callback to notify the change in the visibility mode of Bluetooth adapter.
270 static void OnVisibilityModeChanged(int result, bt_adapter_visibility_mode_e mode, void* pUserdata);
273 * Callback to notify when you get bonded devices repeatedly.
275 static bool OnPairedDeviceFound(bt_device_info_s* pDeviceInfo, void* pUserdata);
278 * Callback to notify when the state of the device discovery changes.
280 static void OnDeviceDiscoveryStateChanged(int status, bt_adapter_device_discovery_state_e discoveryState,
281 bt_adapter_device_discovery_info_s* pDiscoveryInfo, void* pUserdata);
284 * Callback to notify when the process of service discovery is completed.
286 static void OnServiceDiscoveryCompleted(int status, bt_device_sdp_info_s* pSdpInfo, void* pUserdata);
289 * Callback to notify that a new remote device is paired with this local device.
291 static void OnPairingCompleted(int status, bt_device_info_s* pDeviceInfo, void* pUserdata);
294 * Callback to notify that the already paired device is unpaired with this local device.
296 static void OnPairedDeviceRemoved(int status, char* pRemoteAddress, void* pUserdata);
299 * Callback to notify when the state of the device connection changes.
301 static void OnConnectionStateChanged(bool isConnected, const char* pRemoteAddress, void* pUserdata);
305 _BluetoothGapSystemAdapter(void);
306 ~_BluetoothGapSystemAdapter(void);
308 _BluetoothGapSystemAdapter(const _BluetoothGapSystemAdapter& value);
309 _BluetoothGapSystemAdapter& operator =(const _BluetoothGapSystemAdapter& value);
311 bool Construct(void);
313 static void InitSingleton(void);
316 Tizen::Base::Collection::LinkedListT<_IBluetoothManagerEventListener*> __mgrEvtListenerList;
317 Tizen::Base::Collection::LinkedListT<_IBluetoothDeviceEventListener*> __devEvtListenerList;
318 static _BluetoothGapSystemAdapter* __pInstance;
320 }; // _BluetoothGapSystemAdapter
323 #endif // _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_