summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2023-03-23 21:57:01 +0200
committerTarja Sundqvist <tarja.sundqvist@qt.io>2023-03-23 21:57:01 +0200
commit3dcb548bd6fe4aa488ca0bac95e65a7a366c3eca (patch)
treed8e263e0341880d970832326c7c7cecfd05e67cd /src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
parente957d4810b05d8453e163d7bcdcab42d3c60a7bb (diff)
parent2b3b5c899ebdb0fc11273af7370804f5f03ad9e8 (diff)
Merge remote-tracking branch 'origin/tqtc/lts-5.15.9' into tqtc/lts-5.15-opensourcev5.15.9-lts-lgpl
Diffstat (limited to 'src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp')
-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 66834827..82a2ebbc 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;