diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2016-06-09 15:58:23 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2016-06-15 11:57:26 +0000 |
commit | c37703dcfcd6c9762be046779f136bc8f1c4acd9 (patch) | |
tree | 01f487d407171b61e422d17968ddbec8837408a6 /src | |
parent | db55878a269450d7a8f559e5d3862403eba7fbc8 (diff) |
Add BTLE device discovery timeout API
This timeout adjusts the BTLE device discovery. Some BTLE devices
require some time to show up in such a search. In general the platforms
use open ended search methodologies as their own usage pattern for
BTLE device discovery too. So far Qt Bluetooth limited the time
through a hardcoded value which the API user could not adjust.
Task-number: QTBUG-53012
Change-Id: Ia37cebd4015b438db998c6b4a265f563c1a2f89f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
8 files changed, 86 insertions, 2 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp index b6faee75..b90f6b01 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp @@ -232,6 +232,49 @@ QList<QBluetoothDeviceInfo> QBluetoothDeviceDiscoveryAgent::discoveredDevices() } /*! + Sets the maximum search time for Bluetooth Low Energy device search to + \a timeout in milliseconds. If \a timeout is \c 0 the discovery runs + until \l stop() is called. + + This reflects the fact that the discovery process for Bluetooth Low Energy devices + is mostly open ended. The platform continues to look for more devices until the search is + manually stopped. The timeout ensures that the search is aborted after \a timeout milliseconds. + Of course, it is still possible to manually abort the discovery by calling \l stop(). + + The new timeout value does not take effect until the device search is restarted. + In addition the timeout does not affect the classic Bluetooth device search. Depending on + the platform it may add more time to the total discovery process beyond \a timeout. + + \a lowEnergyDiscoveryTimeout() + \since 5.8 + */ +void QBluetoothDeviceDiscoveryAgent::setLowEnergyDiscoveryTimeout(int timeout) +{ + Q_D(QBluetoothDeviceDiscoveryAgent); + + // cannot deliberately turn it off + if (d->lowEnergySearchTimeout < 0 || timeout < 0) + return; + + d->lowEnergySearchTimeout = timeout; +} + +/*! + Returns a timeout in milliseconds that is applied to the Bluetooth Low Energy device search. + A value of \c -1 implies that the platform does not support this property and the timeout for + the device search cannot be adjusted. A return value of \c 0 + implies a never-ending search which must be manually stopped via \l stop(). + + \sa setLowEnergyDiscoveryTimeout() + \since 5.8 + */ +int QBluetoothDeviceDiscoveryAgent::lowEnergyDiscoveryTimeout() const +{ + Q_D(const QBluetoothDeviceDiscoveryAgent); + return d->lowEnergySearchTimeout; +} + +/*! Starts Bluetooth device discovery, if it is not already started. The deviceDiscovered() signal is emitted as each device is discovered. The finished() signal diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h index 954ae704..39b558af 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h @@ -91,6 +91,9 @@ public: QList<QBluetoothDeviceInfo> discoveredDevices() const; + void setLowEnergyDiscoveryTimeout(int msTimeout); + int lowEnergyDiscoveryTimeout() const; + public Q_SLOTS: void start(); void stop(); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index 5f163dfd..1d5e2c99 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -66,6 +66,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( leScanTimeout(0), pendingCancel(false), pendingStart(false), + lowEnergySearchTimeout(-1), //TODO change when implemented q_ptr(parent) { adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter", diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index 0243d31f..add6624d 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -68,6 +68,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( adapterBluez5(0), discoveryTimer(0), useExtendedDiscovery(false), + lowEnergySearchTimeout(-1), //TODO change when implemented q_ptr(parent) { Q_Q(QBluetoothDeviceDiscoveryAgent); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm index 0e4b460f..571eb793 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm @@ -101,6 +101,7 @@ private: bool stopPending; QScopedPointer<OSXBluetooth::DDATimerHandler> timer; + int lowEnergySearchTimeout; }; namespace OSXBluetooth { @@ -144,7 +145,8 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con lastError(QBluetoothDeviceDiscoveryAgent::NoError), inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry), startPending(false), - stopPending(false) + stopPending(false), + lowEnergySearchTimeout(-1) // change when implemented { Q_UNUSED(adapter); @@ -430,4 +432,19 @@ QString QBluetoothDeviceDiscoveryAgent::errorString() const return d_ptr->errorString; } +int QBluetoothDeviceDiscoveryAgent::lowEnergyDiscoveryTimeout() const +{ + return d_ptr->lowEnergySearchTimeout; +} + +void QBluetoothDeviceDiscoveryAgent::setLowEnergyDiscoveryTimeout(int timeout) +{ + // cannot deliberately turn it off + if (d_ptr->lowEnergySearchTimeout < 0 || timeout < 0) + return; + + d_ptr->lowEnergySearchTimeout = timeout; + return; +} + QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm index 0ead4e36..5422d235 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm @@ -135,6 +135,7 @@ private: DevicesList discoveredDevices; QScopedPointer<OSXBluetooth::DDATimerHandler> timer; + int lowEnergySearchTimeout; }; namespace OSXBluetooth { @@ -180,7 +181,8 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con startPending(false), stopPending(false), lastError(QBluetoothDeviceDiscoveryAgent::NoError), - inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry) + inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry), + lowEnergySearchTimeout(-1) // change when implemented { Q_ASSERT_X(q != Q_NULLPTR, Q_FUNC_INFO, "invalid q_ptr (null)"); @@ -624,4 +626,19 @@ QString QBluetoothDeviceDiscoveryAgent::errorString() const return d_ptr->errorString; } +void QBluetoothDeviceDiscoveryAgent::setLowEnergyDiscoveryTimeout(int timeout) +{ + // cannot deliberately turn it off + if (d_ptr->lowEnergySearchTimeout < 0 || timeout < 0) + return; + + d_ptr->lowEnergySearchTimeout = timeout; + return; +} + +int QBluetoothDeviceDiscoveryAgent::lowEnergyDiscoveryTimeout() const +{ + return d_ptr->lowEnergySearchTimeout; +} + QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp index f7780722..85be8233 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp @@ -55,6 +55,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( QBluetoothDeviceDiscoveryAgent *parent) : inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry), lastError(QBluetoothDeviceDiscoveryAgent::NoError), + lowEnergySearchTimeout(-1), q_ptr(parent) { Q_UNUSED(deviceAdapter); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h index f49ff8b7..f97c2f42 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h @@ -155,6 +155,7 @@ private: QTimer extendedDiscoveryTimer; #endif + int lowEnergySearchTimeout; QBluetoothDeviceDiscoveryAgent *q_ptr; }; |