diff options
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 3839b2d6..d34685b1 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -406,6 +406,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::onAdvertisementDataReceived( const ServiceData &serviceData, const QList<QBluetoothUuid> &uuids) { // Merge newly found services with list of currently found ones + bool needDiscoverServices = false; { QMutexLocker locker(&m_leDevicesMutex); if (m_foundLEDevicesMap.contains(address)) { @@ -426,14 +427,13 @@ void QWinRTBluetoothDeviceDiscoveryWorker::onAdvertisementDataReceived( if (adInfo.serviceData != m_foundLEDevicesMap[address].serviceData) changedFields.setFlag((QBluetoothDeviceInfo::Field::ServiceData)); } - bool newServiceAdded = false; for (const QBluetoothUuid &uuid : std::as_const(uuids)) { if (!foundServices.contains(uuid)) { foundServices.append(uuid); - newServiceAdded = true; + needDiscoverServices = true; } } - if (!newServiceAdded) { + if (!needDiscoverServices) { if (!changedFields.testFlag(QBluetoothDeviceInfo::Field::None)) { QMetaObject::invokeMethod(this, "deviceDataChanged", Qt::AutoConnection, Q_ARG(QBluetoothAddress, QBluetoothAddress(address)), @@ -445,6 +445,7 @@ void QWinRTBluetoothDeviceDiscoveryWorker::onAdvertisementDataReceived( } m_foundLEDevicesMap[address].services = foundServices; } else { + needDiscoverServices = true; LEAdvertisingInfo info; info.services = std::move(uuids); info.manufacturerData = std::move(manufacturerData); @@ -453,24 +454,26 @@ void QWinRTBluetoothDeviceDiscoveryWorker::onAdvertisementDataReceived( m_foundLEDevicesMap.insert(address, info); } } - ++m_pendingDevices; // as if we discovered a new LE device - auto thisPtr = shared_from_this(); - auto asyncOp = BluetoothLEDevice::FromBluetoothAddressAsync(address); - asyncOp.Completed([thisPtr, address](auto &&op, AsyncStatus status) { - if (thisPtr) { - if (status == AsyncStatus::Completed) { - BluetoothLEDevice device = op.GetResults(); - if (device) { - thisPtr->handleLowEnergyDevice(device); - return; + if (needDiscoverServices) { + ++m_pendingDevices; // as if we discovered a new LE device + auto thisPtr = shared_from_this(); + auto asyncOp = BluetoothLEDevice::FromBluetoothAddressAsync(address); + asyncOp.Completed([thisPtr, address](auto &&op, AsyncStatus status) { + if (thisPtr) { + if (status == AsyncStatus::Completed) { + BluetoothLEDevice device = op.GetResults(); + if (device) { + thisPtr->handleLowEnergyDevice(device); + return; + } } + // status != Completed or failed to extract result + qCDebug(QT_BT_WINDOWS) << "Failed to get LE device from address" + << QBluetoothAddress(address); + invokeDecrementPendingDevicesCountAndCheckFinished(thisPtr); } - // status != Completed or failed to extract result - qCDebug(QT_BT_WINDOWS) << "Failed to get LE device from address" - << QBluetoothAddress(address); - invokeDecrementPendingDevicesCountAndCheckFinished(thisPtr); - } - }); + }); + } } void QWinRTBluetoothDeviceDiscoveryWorker::stopAdvertisementWatcher() |