From c37703dcfcd6c9762be046779f136bc8f1c4acd9 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 9 Jun 2016 15:58:23 +0200 Subject: 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 Reviewed-by: Christian Kandeler Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothdevicediscoveryagent.cpp | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/bluetooth/qbluetoothdevicediscoveryagent.cpp') 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 @@ -231,6 +231,49 @@ QList QBluetoothDeviceDiscoveryAgent::discoveredDevices() return d->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. -- cgit v1.2.3