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 the local device or the paired devices, and to configure
53 * the %Bluetooth stack.
56 * The %BluetoothManager class is used to obtain information about the local device or the paired devices and to 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 class _OSP_EXPORT_ BluetoothManager
63 : public Tizen::Base::Object
67 * The object is not fully constructed after this constructor is called. For full construction, the Construct()
68 * method must be called right after calling this constructor.
72 BluetoothManager(void);
75 * This destructor overrides Tizen::Base::Object::~Object().
79 virtual ~BluetoothManager(void);
82 * Constructs and initializes an instance of the %BluetoothManager class with the specified listener.
85 * @feature %http://tizen.org/feature/network.bluetooth
87 * @return An error code
88 * @param[in] listener The listener to handle the %BluetoothManager event
89 * @exception E_SUCCESS The method is successful.
90 * @exception E_OUT_OF_MEMORY The memory is insufficient.
91 * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature.
92 * For more information, see
93 * <a href="../org.tizen.gettingstarted/html/tizen_overview/application_filtering.htm">
94 * Application Filtering</a>.
95 * @exception E_SYSTEM A system error has occurred.
96 * @remarks Before calling this method, check whether the feature is supported by %Tizen::System::SystemInfo::GetValue()
99 result Construct(IBluetoothManagerEventListener& listener);
102 * Activates %Bluetooth on a device.
106 * @privilege %http://tizen.org/privilege/bluetooth.admin
108 * @return An error code
109 * @exception E_SUCCESS The method is successful.
110 * @exception E_IN_PROGRESS The %Bluetooth activation process is in progress.
111 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
113 * For example, %Bluetooth is already activated.
114 * @exception E_OUT_OF_MEMORY The memory is insufficient.
115 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
116 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
117 * @exception E_SYSTEM A system error has occurred.
118 * @see IBluetoothManagerEventListener::OnBluetoothActivated()
120 result Activate(void);
123 * Deactivates %Bluetooth on a device.
127 * @privilege %http://tizen.org/privilege/bluetooth.admin
129 * @return An error code
130 * @exception E_SUCCESS The method is successful.
131 * @exception E_IN_PROGRESS The %Bluetooth deactivation process is in progress.
132 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
134 * For example, the %Bluetooth is already deactivated.
135 * @exception E_OUT_OF_MEMORY The memory is insufficient.
136 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
137 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
138 * @exception E_SYSTEM A system error has occurred.
139 * @see IBluetoothManagerEventListener::OnBluetoothDeactivated()
141 result Deactivate(void);
145 * Checks whether a %Bluetooth-specific profile is available.
147 * @brief <i> [Deprecated] </i>
148 * @deprecated This method is deprecated because multiple clients as well as multiple SPP servers with unique
149 * service UUIDs are supported. In case of OPP server, invoke
150 * BluetoothOppServer::StartService() directly without checking OPP server's availability.
151 * If a new OPP server is not available, the method returns the E_SERVICE_UNAVAILABLE exception.
154 * @return @c true if the specified type of connection is available, @n
156 * @param[in] type The connection type
160 bool IsAvailable(BluetoothConnectionType type) const;
164 * Gets the local device information.
166 * @brief <i> [Deprecated] </i>
167 * @deprecated This method is deprecated because the return value of this method is a dangling pointer if this
168 * instance of %BluetoothManager is deleted. In addition to this, the %BluetoothDevice class
169 * represents only remote devices since Tizen. Instead of using this method, the GetLocalDeviceAddress()
170 * and GetLocalDeviceName() methods are recommended.
173 * @return The local device information
174 * @exception E_SUCCESS The method is successful.
175 * @exception E_OUT_OF_MEMORY The memory is insufficient.
176 * @exception E_SYSTEM A system error has occurred.
177 * @remarks The specific error code can be accessed using the GetLastResult() method.
180 const BluetoothDevice* GetLocalDevice(void) const;
183 * Gets the local %Bluetooth device address.
187 * @return The local %Bluetooth device address @n
188 * The address is expressed as a @c 6 byte hexadecimal value delimited by colons. @n
189 * For example, "00:3D:47:EF:8A:03".
191 Tizen::Base::String GetLocalDeviceAddress(void) const;
194 * Gets the local %Bluetooth device name.
198 * @return The local %Bluetooth device name
200 Tizen::Base::String GetLocalDeviceName(void) const;
204 * Gets the operational mode of the %Bluetooth unit.
206 * @brief <i> [Deprecated] </i>
207 * @deprecated %BluetoothDeviceStateType is deprecated. Therefore, this method is also deprecated, because the
208 * return value of this method is of type %BluetoothDeviceStateType. Instead of using this method, the
209 * IsActivated() and GetDiscoverableMode() methods are recommended.
213 * @return The operational mode
216 BluetoothDeviceStateType GetLocalDeviceState(void) const;
219 * Checks whether the local %Bluetooth is activated.
223 * @return @c true if the local %Bluetooth is activated, @n
226 bool IsActivated(void) const;
229 * Gets the discoverable mode of the local device.
232 * @brief <i> [Compatibility] </i>
236 * @compatibility This method has compatibility issues. @n
237 * For more information, see @ref BluetoothManagerGetDiscoverableModePage "here".
240 * @return The discoverable mode of the local device
242 BluetoothDiscoverableMode GetDiscoverableMode(void) const;
246 * @page BluetoothManagerGetDiscoverableModePage Compatibility for GetDiscoverableMode()
248 * @section BluetoothManagerGetDiscoverableModePageIssueSection Issues
249 * Implementation of this method in API versions prior to 2.0 has the following issue: @n
251 * -# The always discoverable mode and the discoverable mode with a certain amount of time cannot be
252 * differentiated. BT_DISC_MODE_DISCOVERABLE of BluetoothDiscoverableMode means both.
254 * @section BluetoothManagerGetDiscoverableModePageSolutionSection Resolutions
255 * The issue mentioned above is resolved in API version 2.0, and it is recommended to use API version
258 * -# The new element, BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE, is added into BluetoothDiscoverableMode
259 * in API version 2.0, Therefore, BT_DISC_MODE_DISCOVERABLE means the always discoverable mode and
260 * BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE means the discoverable mode with a certain amount of time.
265 * Gets the remaining time, in seconds, until the discoverable mode is changed from
266 * ::BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE to be ::BT_DISC_MODE_NOT_DISCOVERABLE. @n
267 * The %GetRemainingTimeAsDiscoverable() method is valid only if the current discoverable mode is @c
268 * BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
272 * @return The remaining time, in seconds, until the local device is not discoverable @n
273 * @c 0 is returned if the current discoverable mode is not ::BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
275 int GetRemainingTimeAsDiscoverable(void) const;
278 * Checks whether the device discovery is in progress.
282 * @return @c true if the device discovery is in progress, @n
285 bool IsDiscoveryInProgress(void) const;
288 * Sets a name of the local device. @n
289 * The searching device detects the local devices in close proximity based on the specified device name, and the
290 * name is only valid while an application is active.
294 * @privilege %http://tizen.org/privilege/bluetooth.admin
296 * @return An error code
297 * @param[in] deviceName The new device name @n
298 * The specified device name is automatically truncated if its size is greater
300 * @exception E_SUCCESS The method is successful.
301 * @exception E_INVALID_ARG The specified device name is an empty string.
302 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
303 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
304 * @exception E_SYSTEM A system error has occurred.
305 * @remarks This method does not affect the system settings.
307 result SetLocalDeviceName(const Tizen::Base::String& deviceName);
310 * Sets the discoverable mode of the local device.
313 * @privlevel platform
314 * @privilege %http://tizen.org/privilege/bluetoothmanager
316 * @return An error code
317 * @param[in] mode The new discoverable mode
318 * @param[in] seconds The duration in seconds for which the local device is discoverable @n
319 * The specified duration is adopted only if the specified @c mode is
320 * @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
321 * @exception E_SUCCESS The method is successful.
322 * @exception E_INVALID_ARG The specified @c seconds should be greater than 0 if the specified @c mode
323 * is @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
324 * @exception E_INVALID_OPERATION %Bluetooth is not activated.
325 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
326 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
327 * @exception E_SYSTEM A system error has occurred.
328 * @see IBluetoothManagerEventListener::OnBluetoothDiscoverableModeChanged()
330 result SetDiscoverableMode(BluetoothDiscoverableMode mode, int seconds = 0);
334 * Refreshes the paired device list.
336 * @brief <i> [Deprecated] </i>
337 * @deprecated This method is deprecated because the paired device list of this instance of %BluetoothManager is
338 * refreshed automatically. An application should not call this method to refresh the list.
341 * @return An error code
342 * @exception E_SUCCESS The method is successful.
343 * @exception E_OUT_OF_MEMORY The memory is insufficient.
344 * @exception E_SYSTEM A system error has occurred.
347 result RefreshPairedDeviceList(void);
351 * Searches for an element that matches a %Bluetooth address.
353 * @brief <i> [Deprecated] </i>
354 * @deprecated This method is deprecated because the return value of this method is a dangling pointer, if this
355 * instance of %BluetoothManager is deleted. In addition to this, it is also an invalid pointer if the
356 * paired device list is updated internally. Instead of using this method, GetPairedDeviceByAddressN()
360 * @return The instance of %BluetoothDevice containing the specified address, @n
361 * else @c null if the search is not successful
362 * @param[in] deviceAddress The address to locate
363 * @exception E_SUCCESS The method is successful.
364 * @exception E_OBJ_NOT_FOUND The specified device is not found in the paired device list.
365 * @remarks The specific error code can be accessed using the GetLastResult() method.
368 const BluetoothDevice* GetPairedDeviceByAddress(const Tizen::Base::ByteBuffer& deviceAddress) const;
371 * Gets an element that matches a %Bluetooth address.
375 * @return The instance of %BluetoothDevice containing the specified address, @n
376 * else @c null if the search is not successful
377 * @param[in] deviceAddress The address to locate
378 * @exception E_SUCCESS The method is successful.
379 * @exception E_OBJ_NOT_FOUND The specified device is not found in the paired device list.
380 * @exception E_OUT_OF_MEMORY The memory is insufficient.
381 * @remarks The specific error code can be accessed using the GetLastResult() method.
383 BluetoothDevice* GetPairedDeviceByAddressN(const Tizen::Base::ByteBuffer& deviceAddress) const;
386 * Gets the elements matching a device name in the paired device list.
390 * @return A list containing the matching devices, @n
391 * else @c null if the search is not successful
392 * @param[in] deviceName The name of the device to locate
393 * @exception E_SUCCESS The method is successful.
394 * @exception E_OBJ_NOT_FOUND The specified device is not found in the paired device list.
395 * @exception E_OUT_OF_MEMORY The memory is insufficient.
396 * @remarks The specific error code can be accessed using the GetLastResult() method.
398 Tizen::Base::Collection::IList* GetPairedDeviceByNameN(const Tizen::Base::String& deviceName) const;
402 * Gets the element at the specified index.
404 * @brief <i> [Deprecated] </i>
405 * @deprecated This method is deprecated because the return value of this method is a dangling pointer, if this
406 * instance of %BluetoothManager is deleted. In addition to this, it is also an invalid pointer if the
407 * paired device list is updated internally. Instead of using this method, GetPairedDeviceListN() and
408 * Tizen::Base::Collection::IList::GetAt() are recommended.
411 * @return The instance of %BluetoothDevice at the specified index, @n
412 * else @c null if there is no element
413 * @param[in] index The index in the list
414 * @exception E_SUCCESS The method is successful.
415 * @exception E_OBJ_NOT_FOUND The specified index is not found in the paired device list.
416 * @remarks The specific error code can be accessed using the GetLastResult() method.
419 const BluetoothDevice* GetPairedDeviceAt(int index) const;
423 * Gets the paired device list.
425 * @brief <i> [Deprecated] </i>
426 * @deprecated This method is deprecated because the return value of this method is a dangling pointer, if this
427 * instance of %BluetoothManager is deleted. In addition to this, some elements of the list may also
428 * be invalid pointers if the paired device list is updated internally. Instead of using this method,
429 * GetPairedDeviceListN() is recommended.
432 * @return A pointer to the paired device list on success, @n
434 * @exception E_SUCCESS The method is successful.
435 * @remarks The specific error code can be accessed using the GetLastResult() method.
438 const Tizen::Base::Collection::IList* GetPairedDeviceList(void) const;
441 * Gets the paired device list.
445 * @return A pointer to the paired device list on success, @n
447 * @exception E_SUCCESS The method is successful.
448 * @exception E_OUT_OF_MEMORY The memory is insufficient.
449 * @remarks The specific error code can be accessed using the GetLastResult() method.
451 Tizen::Base::Collection::IList* GetPairedDeviceListN(void) const;
454 * Sets a remote device event listener for searching devices and services.
458 * @return An error code
459 * @param[in] pListener The device event listener to set @n
460 * If the specified listener is @c null, the listener currently set is
462 * @exception E_SUCCESS The method is successful.
463 * @exception E_SYSTEM A system error has occurred.
464 * @remarks Only one event listener can be set.
466 result SetBluetoothDeviceListener(IBluetoothDeviceEventListener* pListener);
469 * Starts the device discovery process.
473 * @privilege %http://tizen.org/privilege/bluetooth.gap
475 * @return An error code
476 * @exception E_SUCCESS The method is successful.
477 * @exception E_IN_PROGRESS The device discovery process is in progress.
478 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of this
480 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
481 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
482 * @exception E_SYSTEM A system error has occurred.
483 * @see IBluetoothDeviceEventListener::OnBluetoothDiscoveryStarted()
484 * @see IBluetoothDeviceEventListener::OnBluetoothRemoteDeviceFoundN()
485 * @see IBluetoothDeviceEventListener::OnBluetoothDiscoveryDone()
487 result StartDiscovery(void);
490 * Cancels the device discovery process.
494 * @privilege %http://tizen.org/privilege/bluetooth.gap
496 * @return An error code
497 * @exception E_SUCCESS The method is successful.
498 * @exception E_IN_PROGRESS The termination of the device discovery process is in progress.
499 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of this
501 * For example, the discovery has not started as yet.
502 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
503 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
504 * @exception E_SYSTEM A system error has occurred.
505 * @see IBluetoothDeviceEventListener::OnBluetoothDiscoveryDone()
507 result CancelDiscovery(void);
510 * Retrieves the service list from a remote device.
514 * @privilege %http://tizen.org/privilege/bluetooth.gap
516 * @return An error code
517 * @param[in] pairedDevice A remote device that is already paired with the local device
518 * @exception E_SUCCESS The method is successful.
519 * @exception E_IN_PROGRESS The retrieving is in progress.
520 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of this
522 * For example, the discovery is in progress.
523 * @exception E_NOT_PAIRED The input device is not found in the paired device list.
524 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
525 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
526 * @exception E_SYSTEM A system error has occurred.
527 * @remarks The target remote device should be a paired device.
528 * @see IBluetoothDeviceEventListener::OnBluetoothServiceListReceived()
530 result RetrieveServiceList(const BluetoothDevice& pairedDevice);
533 * Pairs with the specified remote device.
537 * @privilege %http://tizen.org/privilege/bluetooth.gap
539 * @return An error code
540 * @param[in] remoteDevice The remote %Bluetooth device to pair with
541 * @exception E_SUCCESS The method is successful.
542 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of this
544 * For example, the %Bluetooth is not activated.
545 * @exception E_DEVICE_BUSY The device cannot be approached because other operation is in progress.
546 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
547 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
548 * @exception E_SYSTEM A system error has occurred.
549 * @remarks IBluetoothDeviceEventListener::OnBluetoothPaired() is called if the pairing is successful, @n
550 * IBluetoothDeviceEventListener::OnBluetoothPairingFailed() if the pairing has failed.
552 result Pair(const BluetoothDevice& remoteDevice);
555 * Stops the pairing process.
559 * @privilege %http://tizen.org/privilege/bluetooth.gap
561 * @return An error code
562 * @exception E_SUCCESS The method is successful.
563 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of this
565 * For example, the pairing process is not in progress.
566 * @exception E_IN_PROGRESS The termination of the pairing process is in progress.
567 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
568 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
569 * @exception E_SYSTEM A system error has occurred.
570 * @remarks If the canceling of the pairing process is successful, @n
571 * IBluetoothDeviceEventListener::OnBluetoothPairingFailed() is called with @c E_OPERATION_CANCELED.
573 result CancelPair(void);
576 * Unpairs with a paired device. @n
577 * The process of unpairing is to remove a specified device from the paired device list. No notification is
578 * transmitted to the remote device. @n
579 * The %Unpair() method is synchronous. Only when the result of this method is @c E_SUCCESS, the unpaired event is fired.
583 * @privilege %http://tizen.org/privilege/bluetooth.gap
585 * @return An error code
586 * @param[in] pairedDevice The paired device to unpair
587 * @exception E_SUCCESS The method is successful.
588 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of this
590 * For example, the %Bluetooth is not activated, or retrieving the service
591 * list is in progress.
592 * @exception E_NOT_PAIRED The input device is not found in the paired device list.
593 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
594 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
595 * @exception E_SYSTEM A system error has occurred.
596 * @see IBluetoothDeviceEventListener::OnBluetoothUnpaired()
598 result Unpair(const BluetoothDevice& pairedDevice);
602 // The implementation of this copy constructor is intentionally blank to prohibit copying of objects.
604 BluetoothManager(const BluetoothManager& value);
607 // The implementation of this copy assignment operator is intentionally blank to prohibit copying of objects.
609 BluetoothManager& operator =(const BluetoothManager& value);
612 _BluetoothManagerImpl* __pImpl;
614 friend class _BluetoothManagerImpl;
616 }; // BluetoothManager
619 #endif // _FNET_BT_BLUETOOTH_MANAGER_H_