From 94cc2b914a027fbcb7a1eb6cb34af45d0c07d2a4 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 17 Aug 2017 15:26:24 +0200 Subject: winrt: Make sure that "finished" is emitted for device discovery If we do not scan for low energy devices, the timeout will never be triggered. In this case the discovery is finished as soon as every paired device has been handled by the worker. Change-Id: I59772e706ac0fbf62c560a54d650bef9815118b6 Reviewed-by: Maurice Kalinowski --- src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 1aaaf0a4..17726660 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -104,7 +104,7 @@ private: HRESULT onBluetoothLEDeviceFound(ComPtr device, PairingCheck pairingCheck = CheckForPairing); public slots: - void handleLeTimeout(); + void finishDiscovery(); Q_SIGNALS: void deviceFound(const QBluetoothDeviceInfo &info); @@ -247,7 +247,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::setupLEDeviceWatcher() Q_ASSERT_SUCCEEDED(hr); } -void QWinRTBluetoothDeviceDiscoveryWorker::handleLeTimeout() +void QWinRTBluetoothDeviceDiscoveryWorker::finishDiscovery() { emit scanFinished(); deleteLater(); @@ -263,6 +263,9 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync HRESULT hr = m_deviceStatics->FromIdAsync(deviceId, &deviceFromIdOperation); if (FAILED(hr)) { --m_pendingPairedDevices; + if (!m_pendingPairedDevices + && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)) + finishDiscovery(); qCWarning(QT_BT_WINRT) << "Could not obtain bluetooth device from id"; return S_OK; } @@ -271,6 +274,9 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync (this, &QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoundAsync).Get()); if (FAILED(hr)) { --m_pendingPairedDevices; + if (!m_pendingPairedDevices + && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)) + finishDiscovery(); qCWarning(QT_BT_WINRT) << "Could not register device found callback"; return S_OK; } @@ -386,6 +392,8 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoun QMetaObject::invokeMethod(this, "deviceFound", Qt::AutoConnection, Q_ARG(QBluetoothDeviceInfo, info)); + if (!m_pendingPairedDevices && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)) + finishDiscovery(); return S_OK; } @@ -556,7 +564,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent leScanTimer->setSingleShot(true); } connect(leScanTimer, &QTimer::timeout, - worker, &QWinRTBluetoothDeviceDiscoveryWorker::handleLeTimeout); + worker, &QWinRTBluetoothDeviceDiscoveryWorker::finishDiscovery); leScanTimer->setInterval(lowEnergySearchTimeout); leScanTimer->start(); } @@ -619,7 +627,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::disconnectAndClearWorker() q, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered); if (leScanTimer) { disconnect(leScanTimer, &QTimer::timeout, - worker, &QWinRTBluetoothDeviceDiscoveryWorker::handleLeTimeout); + worker, &QWinRTBluetoothDeviceDiscoveryWorker::finishDiscovery); } worker.clear(); } -- cgit v1.2.3