summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-21 14:56:14 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-23 12:46:36 +0100
commit77c756fdb33e66dcdccc513af9cc865a658f7e73 (patch)
treee865a45517f35ef722b4a8a163a8f6894c02a56a
parent9cfe355b4e0b7761360728ddf1b12832f4809e26 (diff)
downloadqtconnectivity-77c756fdb33e66dcdccc513af9cc865a658f7e73.tar.gz
Reset the controller's internal state when disconnecting
This caused problems when disconnecting from the remote device while an openrequest was pending and if the controller tried to reconnect immediately afterwards. The pending request queue was blocked forever. Change-Id: I444d5ac6763b65ec8baf687e0dccec4b28016a6c Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--src/bluetooth/bluez/hcimanager.cpp1
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp11
-rw-r--r--src/bluetooth/qlowenergycontroller_p.h2
3 files changed, 14 insertions, 0 deletions
diff --git a/src/bluetooth/bluez/hcimanager.cpp b/src/bluetooth/bluez/hcimanager.cpp
index 449f0825..17d54a4b 100644
--- a/src/bluetooth/bluez/hcimanager.cpp
+++ b/src/bluetooth/bluez/hcimanager.cpp
@@ -150,6 +150,7 @@ bool HciManager::monitorEvent(HciManager::HciEvent event)
return false;
// this event is already enabled
+ // TODO runningEvents does not seem to be used
if (runningEvents.contains(event))
return true;
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index 4f8021e2..5629966d 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -271,6 +271,7 @@ void QLowEnergyControllerPrivate::disconnectFromDevice()
{
setState(QLowEnergyController::ClosingState);
l2cpSocket->close();
+ resetController();
}
void QLowEnergyControllerPrivate::l2cpDisconnected()
@@ -306,9 +307,19 @@ void QLowEnergyControllerPrivate::l2cpErrorChanged(QBluetoothSocket::SocketError
}
invalidateServices();
+ resetController();
setState(QLowEnergyController::UnconnectedState);
}
+
+void QLowEnergyControllerPrivate::resetController()
+{
+ openRequests.clear();
+ requestPending = false;
+ encryptionChangePending = false;
+ securityLevelValue = -1;
+}
+
void QLowEnergyControllerPrivate::l2cpReadyRead()
{
const QByteArray reply = l2cpSocket->readAll();
diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h
index ee206035..db1b346a 100644
--- a/src/bluetooth/qlowenergycontroller_p.h
+++ b/src/bluetooth/qlowenergycontroller_p.h
@@ -160,6 +160,8 @@ private:
const QByteArray &newValue, quint16 offset);
bool increaseEncryptLevelfRequired(quint8 errorCode);
+ void resetController();
+
private slots:
void l2cpConnected();
void l2cpDisconnected();