From ed4f9f3c4354d4f65318832eadaf0cfc5c288404 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Fri, 15 Mar 2019 10:15:57 +0100 Subject: winrt: Stop LE device watcher when discovery is finished In order to protect ourselves from late callbacks we have to unregister the LE watcher's callback as soon as we signal, that we are done with device discovery. We do not expect any additional devices afterwards and might run into a late callback otherwise, so we should stop the watcher immediately and not wait until worker destruction. Change-Id: I85520a4724397aeb5a693d2c8b940a72d68d9663 Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 5dad5ee7..e0209693 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -136,7 +136,7 @@ public: explicit QWinRTBluetoothDeviceDiscoveryWorker(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods); ~QWinRTBluetoothDeviceDiscoveryWorker(); void start(); - void stop(); + void stopLEWatcher(); private: void startDeviceDiscovery(QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode); @@ -213,7 +213,7 @@ QWinRTBluetoothDeviceDiscoveryWorker::QWinRTBluetoothDeviceDiscoveryWorker(QBlue QWinRTBluetoothDeviceDiscoveryWorker::~QWinRTBluetoothDeviceDiscoveryWorker() { - stop(); + stopLEWatcher(); #ifdef CLASSIC_APP_BUILD CoUninitialize(); #endif @@ -235,7 +235,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::start() qCDebug(QT_BT_WINRT) << "Worker started"; } -void QWinRTBluetoothDeviceDiscoveryWorker::stop() +void QWinRTBluetoothDeviceDiscoveryWorker::stopLEWatcher() { if (m_leWatcher) { HRESULT hr = m_leWatcher->Stop(); @@ -430,6 +430,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::setupLEDeviceWatcher() void QWinRTBluetoothDeviceDiscoveryWorker::finishDiscovery() { emit scanFinished(); + stopLEWatcher(); deleteLater(); } @@ -875,7 +876,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop() { Q_Q(QBluetoothDeviceDiscoveryAgent); if (worker) { - worker->stop(); + worker->stopLEWatcher(); disconnectAndClearWorker(); emit q->canceled(); } -- cgit v1.2.3