summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
diff options
context:
space:
mode:
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;