summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2019-03-25 15:46:11 +0100
committerOliver Wolff <oliver.wolff@qt.io>2019-03-28 08:07:15 +0000
commit845e185b2881210b8f3a0dc25926c3d74b0008bf (patch)
treee8bd8b15b50a0be802ac8cebd6e3c9e9d37c400d
parent7bfd9ae91ff801ae6b36d3fe7563bcb2781c5e01 (diff)
winrt: More corrections for handling device disconnections
The signal about device disconnections has to be done at the very end of disconnectFromDevice as a user's application might access an invalid mDevice otherwise if it tries to reconnect automatically. The list of device services has to be invalidated when a remote device disconnects. The same is done in other backends. Additionally the "valueChanged" callbacks should be unregistered on device disconnection. Thus we avoid late callbacks which might cause asserts. Task-number: QTBUG-74394 Change-Id: I156be8ebefc9d9e5533bc60e7018088641680ba3 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt.cpp7
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt_new.cpp7
2 files changed, 10 insertions, 4 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp
index 5347902f..989c5443 100644
--- a/src/bluetooth/qlowenergycontroller_winrt.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt.cpp
@@ -340,6 +340,8 @@ void QLowEnergyControllerPrivateWinRT::connectToDevice()
emit q->connected();
} else if (state != QLowEnergyController::UnconnectedState
&& status == BluetoothConnectionStatus::BluetoothConnectionStatus_Disconnected) {
+ invalidateServices();
+ unregisterFromValueChanges();
setError(QLowEnergyController::RemoteHostClosedError);
setState(QLowEnergyController::UnconnectedState);
emit q->disconnected();
@@ -434,8 +436,7 @@ void QLowEnergyControllerPrivateWinRT::disconnectFromDevice()
{
qCDebug(QT_BT_WINRT) << __FUNCTION__;
Q_Q(QLowEnergyController);
- setState(QLowEnergyController::UnconnectedState);
- emit q->disconnected();
+ setState(QLowEnergyController::ClosingState);
unregisterFromValueChanges();
if (mDevice) {
if (mStatusChangedToken.value) {
@@ -444,6 +445,8 @@ void QLowEnergyControllerPrivateWinRT::disconnectFromDevice()
}
mDevice = nullptr;
}
+ setState(QLowEnergyController::UnconnectedState);
+ emit q->disconnected();
}
ComPtr<IGattDeviceService> QLowEnergyControllerPrivateWinRT::getNativeService(const QBluetoothUuid &serviceUuid)
diff --git a/src/bluetooth/qlowenergycontroller_winrt_new.cpp b/src/bluetooth/qlowenergycontroller_winrt_new.cpp
index 42451e35..42d0a320 100644
--- a/src/bluetooth/qlowenergycontroller_winrt_new.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt_new.cpp
@@ -396,6 +396,8 @@ void QLowEnergyControllerPrivateWinRTNew::connectToDevice()
emit q->connected();
} else if (state != QLowEnergyController::UnconnectedState
&& status == BluetoothConnectionStatus::BluetoothConnectionStatus_Disconnected) {
+ invalidateServices();
+ unregisterFromValueChanges();
setError(QLowEnergyController::RemoteHostClosedError);
setState(QLowEnergyController::UnconnectedState);
emit q->disconnected();
@@ -517,8 +519,7 @@ void QLowEnergyControllerPrivateWinRTNew::disconnectFromDevice()
{
qCDebug(QT_BT_WINRT) << __FUNCTION__;
Q_Q(QLowEnergyController);
- setState(QLowEnergyController::UnconnectedState);
- emit q->disconnected();
+ setState(QLowEnergyController::ClosingState);
unregisterFromValueChanges();
if (mDevice) {
if (mStatusChangedToken.value) {
@@ -527,6 +528,8 @@ void QLowEnergyControllerPrivateWinRTNew::disconnectFromDevice()
}
mDevice = nullptr;
}
+ setState(QLowEnergyController::UnconnectedState);
+ emit q->disconnected();
}
ComPtr<IGattDeviceService> QLowEnergyControllerPrivateWinRTNew::getNativeService(