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(-) (limited to 'src') 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 From dd2e19ca327a3f7a49c40b61c483ec60dcaafa90 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 24 Jan 2018 10:41:46 +0100 Subject: Initialize the discoveryAgent variable to 0 Change-Id: Ief783e899cde02ae033be8cd3af61ab5572d81a5 Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket_p.cpp | 1 + src/bluetooth/qbluetoothsocket_winrt.cpp | 1 + 2 files changed, 2 insertions(+) (limited to 'src') diff --git a/src/bluetooth/qbluetoothsocket_p.cpp b/src/bluetooth/qbluetoothsocket_p.cpp index 39d483d6..4c716005 100644 --- a/src/bluetooth/qbluetoothsocket_p.cpp +++ b/src/bluetooth/qbluetoothsocket_p.cpp @@ -50,6 +50,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate() socketType(QBluetoothServiceInfo::UnknownProtocol), state(QBluetoothSocket::UnconnectedState), socketError(QBluetoothSocket::NoSocketError), + discoveryAgent(0), secFlags(QBluetooth::NoSecurity) { #ifndef QT_IOS_BLUETOOTH diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index 501ffd74..17eeb195 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -309,6 +309,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate() socketType(QBluetoothServiceInfo::UnknownProtocol), state(QBluetoothSocket::UnconnectedState), socketError(QBluetoothSocket::NoSocketError), + discoveryAgent(0), secFlags(QBluetooth::NoSecurity), m_worker(new SocketWorker()) { -- cgit v1.2.3 From df376c4c27d16f70ba69925553acfc69287b269a Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 26 Jan 2018 11:54:55 +0100 Subject: Windows: Cancel and close the operation before deleting the SocketWorker Since it is possible that after calling Cancel() on the IAsyncInfo that it will still call the Completed() callback, we need to ensure that it has a chance to process the pending events before it is deleted. Change-Id: I7d6fbb5bf6344098048b147c9d361c1fe7923b55 Reviewed-by: Alex Blasche Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket_winrt.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index 17eeb195..1faebf69 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -125,6 +125,9 @@ public: } ~SocketWorker() + { + } + void close() { if (Q_UNLIKELY(m_initialReadOp)) { ComPtr info; @@ -402,6 +405,7 @@ void QBluetoothSocketPrivate::abort() this, &QBluetoothSocketPrivate::handleNewData); disconnect(m_worker, &SocketWorker::socketErrorOccured, this, &QBluetoothSocketPrivate::handleError); + m_worker->close(); m_worker->deleteLater(); if (socket != -1) { -- cgit v1.2.3