summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-09-14 13:35:25 +0300
committerJuha Vuolle <juha.vuolle@insta.fi>2021-09-22 13:15:34 +0300
commit8df5f6ad7056a6cbba272a1a8c8861fa9b0f4ac6 (patch)
tree52521e48d74b7c0fdf6c3d720d858f97c26d4792
parent359721c3b4c099b3bd00ae72b51935d38a0ec640 (diff)
downloadqtconnectivity-8df5f6ad7056a6cbba272a1a8c8861fa9b0f4ac6.tar.gz
Move connecting to a LE device to background on Windows
The BT LE connectToDevice() method on Windows was a synchronous operation for the caller by blocking while spinning the event loop to keep rest of the application responsive. Other platforms behave differently. This commit makes the connect call to return immediately while scheduling the connection in the background. The QTBUG-83633 was originally about slightly different crash which seems not be reproducible anymore, but this crash was found while investigating that and is investigated in that item. Task-number: QTBUG-83633 Change-Id: I092a94f2437351d27da758db6746f5b24d5fa9c7 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit 3fc3716e0cd209cd9475d632925a9148b40b2f1d) Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt.cpp12
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt_new.cpp13
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt_new_p.h1
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt_p.h1
4 files changed, 23 insertions, 4 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp
index a9f9fd64..6a039337 100644
--- a/src/bluetooth/qlowenergycontroller_winrt.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt.cpp
@@ -260,14 +260,22 @@ void QLowEnergyControllerPrivateWinRT::init()
void QLowEnergyControllerPrivateWinRT::connectToDevice()
{
qCDebug(QT_BT_WINRT) << __FUNCTION__;
- Q_Q(QLowEnergyController);
if (remoteDevice.isNull()) {
qWarning() << "Invalid/null remote device address";
setError(QLowEnergyController::UnknownRemoteDeviceError);
return;
}
-
setState(QLowEnergyController::ConnectingState);
+ // Queue the device connecting to happen in the background
+ QMetaObject::invokeMethod(this,
+ &QLowEnergyControllerPrivateWinRT::doConnectToDevice,
+ Qt::QueuedConnection);
+}
+
+void QLowEnergyControllerPrivateWinRT::doConnectToDevice()
+{
+ qCDebug(QT_BT_WINRT) << __FUNCTION__;
+ Q_Q(QLowEnergyController);
ComPtr<IBluetoothLEDeviceStatics> deviceStatics;
HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_BluetoothLEDevice).Get(), &deviceStatics);
diff --git a/src/bluetooth/qlowenergycontroller_winrt_new.cpp b/src/bluetooth/qlowenergycontroller_winrt_new.cpp
index 9fa86e05..f448fe33 100644
--- a/src/bluetooth/qlowenergycontroller_winrt_new.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt_new.cpp
@@ -459,14 +459,23 @@ void QLowEnergyControllerPrivateWinRTNew::connectToDevice()
{
qCDebug(QT_BT_WINRT) << __FUNCTION__;
mAbortPending = false;
- Q_Q(QLowEnergyController);
if (remoteDevice.isNull()) {
qWarning() << "Invalid/null remote device address";
setError(QLowEnergyController::UnknownRemoteDeviceError);
return;
}
-
setState(QLowEnergyController::ConnectingState);
+ // Queue the device connecting to happen in the background
+ QMetaObject::invokeMethod(this,
+ &QLowEnergyControllerPrivateWinRTNew::doConnectToDevice,
+ Qt::QueuedConnection);
+}
+
+
+void QLowEnergyControllerPrivateWinRTNew::doConnectToDevice()
+{
+ qCDebug(QT_BT_WINRT) << __FUNCTION__;
+ Q_Q(QLowEnergyController);
ComPtr<IBluetoothLEDeviceStatics> deviceStatics;
HRESULT hr = GetActivationFactory(
diff --git a/src/bluetooth/qlowenergycontroller_winrt_new_p.h b/src/bluetooth/qlowenergycontroller_winrt_new_p.h
index d7d90dbd..b238f48e 100644
--- a/src/bluetooth/qlowenergycontroller_winrt_new_p.h
+++ b/src/bluetooth/qlowenergycontroller_winrt_new_p.h
@@ -136,6 +136,7 @@ signals:
private slots:
void handleCharacteristicChanged(quint16 charHandle, const QByteArray &data);
void handleServiceHandlerError(const QString &error);
+ void doConnectToDevice();
private:
void connectToPairedDevice();
diff --git a/src/bluetooth/qlowenergycontroller_winrt_p.h b/src/bluetooth/qlowenergycontroller_winrt_p.h
index d87477c6..629f62fc 100644
--- a/src/bluetooth/qlowenergycontroller_winrt_p.h
+++ b/src/bluetooth/qlowenergycontroller_winrt_p.h
@@ -119,6 +119,7 @@ signals:
private slots:
void handleCharacteristicChanged(quint16 charHandle, const QByteArray &data);
+ void doConnectToDevice();
private:
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice> mDevice;