summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2022-01-20 13:01:13 +0200
committerIvan Solovev <ivan.solovev@qt.io>2022-01-28 10:13:06 +0100
commit6a96181d9ac673a7aa66a9077e2f4f8aba90c30f (patch)
tree90de238ce3905ed92f8fabc0993cbedd115def58 /src
parent228d5bad4b2aabf93c30393de706cad4d1424f68 (diff)
Decrement the pending paired device counter only once per device
The m_pendingPairedDevices variable keeps track of if there are more devices which should be discovered. The counter was decrement twice instead of once leading to possibly non-ending discovery or missing a discovered device. This patch also introduces a helper method to decrement-and-check the amount of pending paired devices. Using this method in classicBluetoothInfoFromDeviceIdAsync allows to properly finish device discovery in case of an async operation error for the last device in the list. Task-number: QTBUG-99685 Done-with: Ivan Solovev <ivan.solovev@qt.io> Change-Id: Iaa36b212e8754940d9d574a60379fa0c32fdad2c Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit 0c76617b0cbb7ad4903c2573c206e00bfb6add59) Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
index e515d4e1..8967e424 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
@@ -157,6 +157,8 @@ private:
#endif
HRESULT onBluetoothLEAdvertisementReceived(IBluetoothLEAdvertisementReceivedEventArgs *args);
+ void decrementPairedDevicesAndCheckFinished();
+
public slots:
void finishDiscovery();
@@ -492,10 +494,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync
// on Windows 10 FromIdAsync might ask for device permission. We cannot wait here but have to handle that asynchronously
HRESULT hr = m_deviceStatics->FromIdAsync(deviceId, &deviceFromIdOperation);
if (FAILED(hr)) {
- --m_pendingPairedDevices;
- if (!m_pendingPairedDevices
- && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod))
- finishDiscovery();
+ decrementPairedDevicesAndCheckFinished();
qCWarning(QT_BT_WINRT) << "Could not obtain bluetooth device from id";
return S_OK;
}
@@ -506,15 +505,13 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync
if (thisPointer) {
if (status == Completed)
thisPointer->onPairedClassicBluetoothDeviceFoundAsync(op, status);
- --thisPointer->m_pendingPairedDevices;
+ else
+ thisPointer->decrementPairedDevicesAndCheckFinished();
}
return S_OK;
}).Get());
if (FAILED(hr)) {
- --m_pendingPairedDevices;
- if (!m_pendingPairedDevices
- && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod))
- finishDiscovery();
+ decrementPairedDevicesAndCheckFinished();
qCWarning(QT_BT_WINRT) << "Could not register device found callback";
return S_OK;
}
@@ -522,7 +519,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync
});
if (FAILED(hr)) {
emit errorOccured(QBluetoothDeviceDiscoveryAgent::UnknownError);
- --m_pendingPairedDevices;
+ decrementPairedDevicesAndCheckFinished();
qCWarning(QT_BT_WINRT) << "Could not obtain bluetooth device from id";
return;
}
@@ -531,6 +528,10 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync
// "deviceFound" will be emitted at the end of the deviceFromIdOperation callback
void QWinRTBluetoothDeviceDiscoveryWorker::leBluetoothInfoFromDeviceIdAsync(HSTRING deviceId)
{
+ // Note: in this method we do not need to call
+ // decrementPairedDevicesAndCheckFinished() because we *do* run LE
+ // scanning, so the condition in the check will always be false.
+ // It's enough to just decrement m_pendingPairedDevices.
HRESULT hr;
hr = QEventDispatcherWinRT::runOnXamlThread([deviceId, this]() {
ComPtr<IAsyncOperation<BluetoothLEDevice *>> deviceFromIdOperation;
@@ -548,7 +549,8 @@ void QWinRTBluetoothDeviceDiscoveryWorker::leBluetoothInfoFromDeviceIdAsync(HSTR
if (thisPointer) {
if (status == Completed)
thisPointer->onPairedBluetoothLEDeviceFoundAsync(op, status);
- --thisPointer->m_pendingPairedDevices;
+ else
+ --thisPointer->m_pendingPairedDevices;
}
return S_OK;
}).Get());
@@ -687,6 +689,14 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoun
return S_OK;
}
+void QWinRTBluetoothDeviceDiscoveryWorker::decrementPairedDevicesAndCheckFinished()
+{
+ if ((--m_pendingPairedDevices == 0)
+ && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)) {
+ finishDiscovery();
+ }
+}
+
HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedBluetoothLEDeviceFoundAsync(IAsyncOperation<BluetoothLEDevice *> *op, AsyncStatus status)
{
--m_pendingPairedDevices;