diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2018-05-17 16:15:04 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2018-05-29 13:51:20 +0000 |
commit | aad6e26574ff069e080bf6461c0fb7d0fee9e403 (patch) | |
tree | d064d779bd66d9711a091f378527ba4d849c486e /src/bluetooth/qlowenergycontrollerbase.cpp | |
parent | 88207ae868002f0b53151d2c5c2ac416284ce9c1 (diff) |
Properly invalidate services when calling disconnectService() on BlueZ
While the central role implementation properly invalidates all the
LowEnergyServicePrivate instances, peripheral mode was leaking service
instances. This is triggered when the peripheral disconnects from a client
or when the user calls disconnectService(). On the other hand
stopAdvertising() does not do that.
This patch fixes the service instance leak and ensures that the class
docs specifically state the behavior difference between stopAdvertising()
and disconnectService().
Change-Id: Ia52b141096dc1db3d0cefe3ed18c230eecccd9c0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontrollerbase.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycontrollerbase.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/bluetooth/qlowenergycontrollerbase.cpp b/src/bluetooth/qlowenergycontrollerbase.cpp index 687f5b9e..c7b9ec0b 100644 --- a/src/bluetooth/qlowenergycontrollerbase.cpp +++ b/src/bluetooth/qlowenergycontrollerbase.cpp @@ -261,6 +261,8 @@ void QLowEnergyControllerPrivate::invalidateServices() } serviceList.clear(); + localServices.clear(); + lastLocalHandle = {}; } QLowEnergyService *QLowEnergyControllerPrivate::addServiceHelper( @@ -308,7 +310,12 @@ QLowEnergyService *QLowEnergyControllerPrivate::addServiceHelper( return nullptr; } + if (localServices.contains(servicePrivate->uuid)) { + qWarning() << "Overriding existing local service with uuid" + << servicePrivate->uuid; + } this->localServices.insert(servicePrivate->uuid, servicePrivate); + this->addToGenericAttributeList(service, servicePrivate->startHandle); return new QLowEnergyService(servicePrivate); } |