From b5e90f9e554997254fb54255339578e92234d5bb Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Fri, 19 Jan 2018 09:19:44 +0100 Subject: winrt: Finish classic BT device discovery if no device is found Task-number: QTBUG-65801 Change-Id: I32be0262165d963ba5fb933c73414451431b2242 Reviewed-by: Maurice Kalinowski --- .../qbluetoothdevicediscoveryagent_winrt.cpp | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 17726660..ab01f14f 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -88,7 +88,7 @@ private: QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode); void gatherDeviceInformation(IDeviceInformation *deviceInfo, QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode); - void gatherMultipleDeviceInformation(IVectorView *devices, + void gatherMultipleDeviceInformation(quint32 deviceCount, IVectorView *devices, QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode); void setupLEDeviceWatcher(); void classicBluetoothInfoFromDeviceIdAsync(HSTRING deviceId); @@ -197,7 +197,20 @@ void QWinRTBluetoothDeviceDiscoveryWorker::onDeviceDiscoveryFinished(IAsyncOpera HRESULT hr; hr = op->GetResults(&devices); Q_ASSERT_SUCCEEDED(hr); - gatherMultipleDeviceInformation(devices.Get(), mode); + quint32 deviceCount; + hr = devices->get_Size(&deviceCount); + Q_ASSERT_SUCCEEDED(hr); + + // For classic discovery only paired devices will be found. If we only do classic disovery and + // no device is found, the scan is finished. + if (requestedModes == QBluetoothDeviceDiscoveryAgent::ClassicMethod && + deviceCount == 0) { + finishDiscovery(); + return; + } + + m_pendingPairedDevices += deviceCount; + gatherMultipleDeviceInformation(deviceCount, devices.Get(), mode); } void QWinRTBluetoothDeviceDiscoveryWorker::gatherDeviceInformation(IDeviceInformation *deviceInfo, QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode) @@ -212,15 +225,11 @@ void QWinRTBluetoothDeviceDiscoveryWorker::gatherDeviceInformation(IDeviceInform classicBluetoothInfoFromDeviceIdAsync(deviceId.Get()); } -void QWinRTBluetoothDeviceDiscoveryWorker::gatherMultipleDeviceInformation(IVectorView *devices, QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode) +void QWinRTBluetoothDeviceDiscoveryWorker::gatherMultipleDeviceInformation(quint32 deviceCount, IVectorView *devices, QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode) { - quint32 deviceCount; - HRESULT hr = devices->get_Size(&deviceCount); - Q_ASSERT_SUCCEEDED(hr); - m_pendingPairedDevices += deviceCount; for (quint32 i = 0; i < deviceCount; ++i) { ComPtr device; - hr = devices->GetAt(i, &device); + HRESULT hr = devices->GetAt(i, &device); Q_ASSERT_SUCCEEDED(hr); gatherDeviceInformation(device.Get(), mode); } -- cgit v1.2.3