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.
19 * @file FNetBtBluetoothManager.h
20 * @brief This is the header file for the %BluetoothManager class.
22 * This header file contains the declarations of the %BluetoothManager class.
24 #ifndef _FNET_BT_BLUETOOTH_MANAGER_H_
25 #define _FNET_BT_BLUETOOTH_MANAGER_H_
27 #include <FBaseObject.h>
28 #include <FBaseResult.h>
29 #include <FNetBtBluetoothTypes.h>
31 namespace Tizen { namespace Base
41 namespace Tizen { namespace Net { namespace Bluetooth
44 // forward declarations
45 class BluetoothDevice;
46 class IBluetoothManagerEventListener;
47 class IBluetoothDeviceEventListener;
48 class _BluetoothManagerImpl;
51 * @class BluetoothManager
52 * @brief This class is used to obtain information about a local device or a paired device and also helps configure
53 * the %Bluetooth stack.
56 * The %BluetoothManager class is used to obtain information about a local device or a paired device and also helps configure the
59 * For more information on the class features, see
60 * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
62 * The following diagram illustrates the interactions between this class and the application.
63 * @image html net_bluetooth_manager_sequence_diagram.png
65 class _OSP_EXPORT_ BluetoothManager
66 : public Tizen::Base::Object
70 * The object is not fully constructed after this constructor is called. @n
71 * For full construction, the Construct() method must be called right after calling this constructor.
75 BluetoothManager(void);
78 * This destructor overrides Tizen::Base::Object::~Object().
82 virtual ~BluetoothManager(void);
85 * Constructs and initializes an instance of the %BluetoothManager class with the specified listener.
88 * @feature %http://tizen.org/feature/network.bluetooth
90 * @return An error code
91 * @param[in] listener The listener to handle the %BluetoothManager event
92 * @exception E_SUCCESS The method is successful.
93 * @exception E_OUT_OF_MEMORY The memory is insufficient.
94 * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature.
95 * For more information, see
96 * <a href="../org.tizen.gettingstarted/html/tizen_overview/application_filtering.htm">
97 * Application Filtering</a>.
98 * @exception E_SYSTEM A system error has occurred.
99 * @remarks Before calling this method, check whether the feature is supported by
100 * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&).
102 result Construct(IBluetoothManagerEventListener& listener);
105 * Activates %Bluetooth on a device.
109 * @privilege %http://tizen.org/privilege/bluetooth.admin
111 * @return An error code
112 * @exception E_SUCCESS The method is successful.
113 * @exception E_IN_PROGRESS The %Bluetooth activation process is in progress.
114 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
116 * For example, %Bluetooth is already activated.
117 * @exception E_OUT_OF_MEMORY The memory is insufficient.
118 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
119 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
120 * @exception E_SYSTEM A system error has occurred.
121 * @see IBluetoothManagerEventListener::OnBluetoothActivated()
123 result Activate(void);
126 * Deactivates %Bluetooth on a device.
130 * @privilege %http://tizen.org/privilege/bluetooth.admin
132 * @return An error code
133 * @exception E_SUCCESS The method is successful.
134 * @exception E_IN_PROGRESS The %Bluetooth deactivation process is in progress.
135 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
137 * For example, %Bluetooth is already deactivated.
138 * @exception E_OUT_OF_MEMORY The memory is insufficient.
139 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
140 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
141 * @exception E_SYSTEM A system error has occurred.
142 * @see IBluetoothManagerEventListener::OnBluetoothDeactivated()
144 result Deactivate(void);
148 * Checks whether a %Bluetooth-specific profile is available.
150 * @brief <i> [Deprecated] </i>
151 * @deprecated This method is deprecated because multiple clients as well as multiple SPP servers with unique
152 * service UUIDs are supported. In case of the OPP server, invoke
153 * BluetoothOppServer::StartService() directly without checking the OPP server's availability.
154 * If a new OPP server is not available, the method returns the @c E_SERVICE_UNAVAILABLE exception.
157 * @return @c true if the specified type of connection is available, @n
159 * @param[in] type The connection type
163 bool IsAvailable(BluetoothConnectionType type) const;
167 * Gets the local device information.
169 * @brief <i> [Deprecated] </i>
170 * @deprecated This method is deprecated because the return value of this method is a dangling pointer if this
171 * instance of %BluetoothManager is deleted. In addition to this, the BluetoothDevice class
172 * represents only remote devices since Tizen. Instead of using this method, the GetLocalDeviceAddress()
173 * and GetLocalDeviceName() methods are recommended.
176 * @return The local device information
177 * @exception E_SUCCESS The method is successful.
178 * @exception E_OUT_OF_MEMORY The memory is insufficient.
179 * @exception E_SYSTEM A system error has occurred.
180 * @remarks The specific error code can be accessed using the GetLastResult() method.
183 const BluetoothDevice* GetLocalDevice(void) const;
186 * Gets the local %Bluetooth device address.
190 * @return The local %Bluetooth device address @n
191 * The address is expressed as a @c 6 byte hexadecimal value delimited by colons, @n
192 * for example, "00:3D:47:EF:8A:03".
194 Tizen::Base::String GetLocalDeviceAddress(void) const;
197 * Gets the local %Bluetooth device name.
201 * @return The local %Bluetooth device name
203 Tizen::Base::String GetLocalDeviceName(void) const;
207 * Gets the operational mode of the %Bluetooth unit.
209 * @brief <i> [Deprecated] </i>
210 * @deprecated BluetoothDeviceStateType is deprecated. Therefore, this method is also deprecated, because the
211 * return value of this method is of type %BluetoothDeviceStateType. Instead of using this method, the
212 * IsActivated() and GetDiscoverableMode() methods are recommended.
216 * @return The operational mode
219 BluetoothDeviceStateType GetLocalDeviceState(void) const;
222 * Checks whether the local %Bluetooth is activated.
226 * @return @c true if the local %Bluetooth is activated, @n
229 bool IsActivated(void) const;
232 * Gets the discoverable mode of the local device.
235 * @brief <i> [Compatibility] </i>
239 * @compatibility This method has compatibility issues. @n
240 * For more information, see @ref BluetoothManagerGetDiscoverableModePage "here".
243 * @return The discoverable mode of the local device
245 BluetoothDiscoverableMode GetDiscoverableMode(void) const;
249 * @page BluetoothManagerGetDiscoverableModePage Compatibility for GetDiscoverableMode()
251 * @section BluetoothManagerGetDiscoverableModePageIssueSection Issues
252 * Implementation of this method in %Tizen API versions prior to 2.0 has the following issue: @n
254 * -# The always discoverable mode and the discoverable mode with a certain amount of time cannot be
255 * differentiated. ::BT_DISC_MODE_DISCOVERABLE of BluetoothDiscoverableMode means both.
257 * @section BluetoothManagerGetDiscoverableModePageSolutionSection Resolutions
258 * The issue mentioned above is resolved in %Tizen API version 2.0, and it is recommended to use %Tizen
259 * API version 3.0 or above. @n
261 * -# The new element, ::BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE, is added into BluetoothDiscoverableMode
262 * in %Tizen API version 2.0, therefore, ::BT_DISC_MODE_DISCOVERABLE means the always discoverable mode and
263 * @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE means the discoverable mode with a certain amount of time.
268 * Gets the remaining time, in seconds, until the discoverable mode is changed from
269 * ::BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE to ::BT_DISC_MODE_NOT_DISCOVERABLE. @n
270 * The %GetRemainingTimeAsDiscoverable() method is valid only if the current discoverable mode is
271 * @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
275 * @return The remaining time, in seconds, until the local device is not discoverable @n
276 * @c 0 is returned if the current discoverable mode is not ::BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
278 int GetRemainingTimeAsDiscoverable(void) const;
281 * Checks whether the device discovery is in progress.
285 * @return @c true if the device discovery is in progress, @n
288 bool IsDiscoveryInProgress(void) const;
291 * Sets the name of the local device. @n
292 * The searching device detects the local devices in close proximity based on the specified device name, and the
293 * name is only valid while an application is active.
297 * @privilege %http://tizen.org/privilege/bluetooth.admin
299 * @return An error code
300 * @param[in] deviceName The new device name @n
301 * The specified device name is automatically truncated if its size is greater
303 * @exception E_SUCCESS The method is successful.
304 * @exception E_INVALID_ARG The specified device name is an empty string.
305 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
306 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
307 * @exception E_SYSTEM A system error has occurred.
308 * @remarks This method does not affect the system settings.
310 result SetLocalDeviceName(const Tizen::Base::String& deviceName);
313 * Sets the discoverable mode of the local device.
316 * @privlevel platform
317 * @privilege %http://tizen.org/privilege/bluetoothmanager
319 * @return An error code
320 * @param[in] mode The new discoverable mode
321 * @param[in] seconds The duration in seconds for which the local device is discoverable @n
322 * The specified duration is adopted only if the specified @c mode is
323 * @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
324 * @exception E_SUCCESS The method is successful.
325 * @exception E_INVALID_ARG The specified @c seconds should be greater than @c 0 if the specified @c mode
326 * is @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
327 * @exception E_INVALID_OPERATION %Bluetooth is not activated.
328 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
329 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
330 * @exception E_SYSTEM A system error has occurred.
331 * @see IBluetoothManagerEventListener::OnBluetoothDiscoverableModeChanged()
333 result SetDiscoverableMode(BluetoothDiscoverableMode mode, int seconds = 0);
337 * Refreshes the paired device list.
339 * @brief <i> [Deprecated] </i>
340 * @deprecated This method is deprecated because the paired device list of this instance of %BluetoothManager is
341 * refreshed automatically. An application should not call this method to refresh the list.
344 * @return An error code
345 * @exception E_SUCCESS The method is successful.
346 * @exception E_OUT_OF_MEMORY The memory is insufficient.
347 * @exception E_SYSTEM A system error has occurred.
350 result RefreshPairedDeviceList(void);
354 * Searches for an element that matches a %Bluetooth address.
356 * @brief <i> [Deprecated] </i>
357 * @deprecated This method is deprecated because the return value of this method is a dangling pointer, if this
358 * instance of %BluetoothManager is deleted. In addition to this, it is also an invalid pointer if the
359 * paired device list is updated internally. Instead of using this method, GetPairedDeviceByAddressN()
363 * @return An instance of BluetoothDevice that contains the specified address, @n
364 * else @c null if the search is not successful
365 * @param[in] deviceAddress The address to locate
366 * @exception E_SUCCESS The method is successful.
367 * @exception E_OBJ_NOT_FOUND The specified device is not found in the paired device list.
368 * @remarks The specific error code can be accessed using the GetLastResult() method.
371 const BluetoothDevice* GetPairedDeviceByAddress(const Tizen::Base::ByteBuffer& deviceAddress) const;
374 * Gets the element that matches a %Bluetooth address.
378 * @return An instance of BluetoothDevice that contains the specified address, @n
379 * else @c null if the search is not successful
380 * @param[in] deviceAddress The address to locate
381 * @exception E_SUCCESS The method is successful.
382 * @exception E_OBJ_NOT_FOUND The specified device is not found in the paired device list.
383 * @exception E_OUT_OF_MEMORY The memory is insufficient.
384 * @remarks The specific error code can be accessed using the GetLastResult() method.
386 BluetoothDevice* GetPairedDeviceByAddressN(const Tizen::Base::ByteBuffer& deviceAddress) const;
389 * Gets the elements matching a device name in the paired device list.
393 * @return The list that contains the matching devices, @n
394 * else @c null if the search is not successful
395 * @param[in] deviceName The name of the device to locate
396 * @exception E_SUCCESS The method is successful.
397 * @exception E_OBJ_NOT_FOUND The specified device is not found in the paired device list.
398 * @exception E_OUT_OF_MEMORY The memory is insufficient.
399 * @remarks The specific error code can be accessed using the GetLastResult() method.
401 Tizen::Base::Collection::IList* GetPairedDeviceByNameN(const Tizen::Base::String& deviceName) const;
405 * Gets the element at the specified index.
407 * @brief <i> [Deprecated] </i>
408 * @deprecated This method is deprecated because the return value of this method is a dangling pointer, if this
409 * instance of %BluetoothManager is deleted. In addition to this, it is also an invalid pointer if the
410 * paired device list is updated internally. Instead of using this method, the GetPairedDeviceListN() and
411 * Tizen::Base::Collection::IList::GetAt() methods are recommended.
414 * @return An instance of BluetoothDevice at the specified index, @n
415 * else @c null if there is no element
416 * @param[in] index The index in the list
417 * @exception E_SUCCESS The method is successful.
418 * @exception E_OBJ_NOT_FOUND The specified input parameter is not found in the paired device list.
419 * @remarks The specific error code can be accessed using the GetLastResult() method.
422 const BluetoothDevice* GetPairedDeviceAt(int index) const;
426 * Gets the paired device list.
428 * @brief <i> [Deprecated] </i>
429 * @deprecated This method is deprecated because the return value of this method is a dangling pointer, if this
430 * instance of %BluetoothManager is deleted. In addition to this, some elements of the list may also
431 * be invalid pointers if the paired device list is updated internally. Instead of using this method,
432 * GetPairedDeviceListN() is recommended.
435 * @return A pointer to the paired device list, @n
436 * else @c null if it fails
437 * @exception E_SUCCESS The method is successful.
438 * @remarks The specific error code can be accessed using the GetLastResult() method.
441 const Tizen::Base::Collection::IList* GetPairedDeviceList(void) const;
444 * Gets the paired device list.
448 * @return A pointer to the paired device list, @n
449 * else @c null if it fails
450 * @exception E_SUCCESS The method is successful.
451 * @exception E_OUT_OF_MEMORY The memory is insufficient.
452 * @remarks The specific error code can be accessed using the GetLastResult() method.
454 Tizen::Base::Collection::IList* GetPairedDeviceListN(void) const;
457 * Sets a remote device event listener for searching devices and services.
461 * @return An error code
462 * @param[in] pListener The device event listener to set @n
463 * If the specified listener is @c null, the listener currently set is
465 * @exception E_SUCCESS The method is successful.
466 * @exception E_SYSTEM A system error has occurred.
467 * @remarks Only one event listener can be set.
469 result SetBluetoothDeviceListener(IBluetoothDeviceEventListener* pListener);
472 * Starts the device discovery process.
476 * @privilege %http://tizen.org/privilege/bluetooth.gap
478 * @return An error code
479 * @exception E_SUCCESS The method is successful.
480 * @exception E_IN_PROGRESS The device discovery process is in progress.
481 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
483 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
484 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
485 * @exception E_SYSTEM A system error has occurred.
486 * @see IBluetoothDeviceEventListener::OnBluetoothDiscoveryStarted()
487 * @see IBluetoothDeviceEventListener::OnBluetoothRemoteDeviceFoundN()
488 * @see IBluetoothDeviceEventListener::OnBluetoothDiscoveryDone()
490 result StartDiscovery(void);
493 * Cancels the device discovery process.
497 * @privilege %http://tizen.org/privilege/bluetooth.gap
499 * @return An error code
500 * @exception E_SUCCESS The method is successful.
501 * @exception E_IN_PROGRESS The termination of the device discovery process is in progress.
502 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
504 * For example, the discovery has not started as yet.
505 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
506 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
507 * @exception E_SYSTEM A system error has occurred.
508 * @see IBluetoothDeviceEventListener::OnBluetoothDiscoveryDone()
510 result CancelDiscovery(void);
513 * Retrieves the service list from a remote device.
517 * @privilege %http://tizen.org/privilege/bluetooth.gap
519 * @return An error code
520 * @param[in] pairedDevice The remote device that is already paired with the local device
521 * @exception E_SUCCESS The method is successful.
522 * @exception E_IN_PROGRESS The retrieving is in progress.
523 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
525 * For example, the discovery is in progress.
526 * @exception E_NOT_PAIRED The input device is not found in the paired device list.
527 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
528 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
529 * @exception E_SYSTEM A system error has occurred.
530 * @remarks The target remote device should be a paired device.
531 * @see IBluetoothDeviceEventListener::OnBluetoothServiceListReceived()
533 result RetrieveServiceList(const BluetoothDevice& pairedDevice);
536 * Pairs with the specified remote device.
540 * @privilege %http://tizen.org/privilege/bluetooth.gap
542 * @return An error code
543 * @param[in] remoteDevice The remote %Bluetooth device to pair with
544 * @exception E_SUCCESS The method is successful.
545 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
547 * For example, %Bluetooth is not activated.
548 * @exception E_DEVICE_BUSY The device cannot be approached because another operation is in progress.
549 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
550 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
551 * @exception E_SYSTEM A system error has occurred.
552 * @remarks IBluetoothDeviceEventListener::OnBluetoothPaired() is called if the pairing is successful, @n
553 * otherwise IBluetoothDeviceEventListener::OnBluetoothPairingFailed() is called if the pairing has failed.
555 result Pair(const BluetoothDevice& remoteDevice);
558 * Stops the pairing process.
562 * @privilege %http://tizen.org/privilege/bluetooth.gap
564 * @return An error code
565 * @exception E_SUCCESS The method is successful.
566 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
568 * For example, the pairing process is not in progress.
569 * @exception E_IN_PROGRESS The termination of the pairing process is in progress.
570 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
571 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
572 * @exception E_SYSTEM A system error has occurred.
573 * @remarks If the cancelling of the pairing process is successful, @n
574 * IBluetoothDeviceEventListener::OnBluetoothPairingFailed() is called with @c E_OPERATION_CANCELED.
576 result CancelPair(void);
579 * Unpairs a paired device. @n
580 * The process of unpairing is to remove a specified device from the paired device list. No notification is
581 * transmitted to the remote device. @n
582 * The %Unpair() method is synchronous. Only when the result of this method is @c E_SUCCESS, the unpaired event is fired.
586 * @privilege %http://tizen.org/privilege/bluetooth.gap
588 * @return An error code
589 * @param[in] pairedDevice The paired device to unpair
590 * @exception E_SUCCESS The method is successful.
591 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
593 * For example, %Bluetooth is not activated, or retrieving the service
594 * list is in progress.
595 * @exception E_NOT_PAIRED The input device is not found in the paired device list.
596 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
597 * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1
598 * @exception E_SYSTEM A system error has occurred.
599 * @see IBluetoothDeviceEventListener::OnBluetoothUnpaired()
601 result Unpair(const BluetoothDevice& pairedDevice);
605 // The implementation of this copy constructor is intentionally blank to prohibit copying of objects.
607 BluetoothManager(const BluetoothManager& value);
610 // The implementation of this copy assignment operator is intentionally blank to prohibit copying of objects.
612 BluetoothManager& operator =(const BluetoothManager& value);
615 _BluetoothManagerImpl* __pImpl;
617 friend class _BluetoothManagerImpl;
619 }; // BluetoothManager
622 #endif // _FNET_BT_BLUETOOTH_MANAGER_H_