From 24a07f0a94a0ac036866c18ef415f06dd1fb8bbe Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 7 Mar 2018 15:05:03 +0100 Subject: Enable new DBus LE backed for central role use cases The manual override env variable was renamed. The new name is more fitting for the use case. Task-number: QTBUG-46819 Task-number: QTBUG-66908 Change-Id: I9202ebf3f847d5c7dcc9e3c84b060b35343dd2fd Reviewed-by: Timur Pocheptsov --- src/bluetooth/qlowenergycontroller.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/bluetooth/qlowenergycontroller.cpp') diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index 3be1aed3..caa6c3fa 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -292,11 +292,13 @@ void registerQLowEnergyControllerMetaType() } } -static QLowEnergyControllerPrivate *privateController() +static QLowEnergyControllerPrivate *privateController(QLowEnergyController::Role role) { #if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE) - // for now Bluez DBus disabled - if (false && bluetoothdVersion() >= QVersionNumber(5, 42)) { + // The new DBUS implementation only supports Central role for now + // For Peripheral role support see QTBUG-66909 + if (role == QLowEnergyController::CentralRole + && bluetoothdVersion() >= QVersionNumber(5, 42)) { qCWarning(QT_BT) << "Using BlueZ LE DBus API"; return new QLowEnergyControllerPrivateBluezDBus(); } else { @@ -329,7 +331,7 @@ QLowEnergyController::QLowEnergyController( QObject *parent) : QObject(parent) { - d_ptr = privateController(); + d_ptr = privateController(CentralRole); Q_D(QLowEnergyController); d->q_ptr = this; @@ -358,7 +360,7 @@ QLowEnergyController::QLowEnergyController( QObject *parent) : QObject(parent) { - d_ptr = privateController(); + d_ptr = privateController(CentralRole); Q_D(QLowEnergyController); d->q_ptr = this; @@ -391,7 +393,7 @@ QLowEnergyController::QLowEnergyController( QObject *parent) : QObject(parent) { - d_ptr = privateController(); + d_ptr = privateController(CentralRole); Q_D(QLowEnergyController); d->q_ptr = this; @@ -436,7 +438,7 @@ QLowEnergyController *QLowEnergyController::createPeripheral(QObject *parent) QLowEnergyController::QLowEnergyController(QObject *parent) : QObject(parent) { - d_ptr = privateController(); + d_ptr = privateController(PeripheralRole); Q_D(QLowEnergyController); d->q_ptr = this; -- cgit v1.2.3 From 08ee3470fe71089503c57530396a4534f39afe9e Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 21 Mar 2018 07:48:29 +0100 Subject: Fix compiler warning qlowenergycontroller.cpp:295:82: warning: unused parameter 'role' [-Wunused-parameter] static QLowEnergyControllerPrivate *privateController(QLowEnergyController::Role role) Change-Id: I4d3d2ad1e2dbabd0101efd6294a2481491587926 Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/bluetooth/qlowenergycontroller.cpp') diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index caa6c3fa..a23955ff 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -306,10 +306,13 @@ static QLowEnergyControllerPrivate *privateController(QLowEnergyController::Role return new QLowEnergyControllerPrivateBluez(); } #elif defined(QT_ANDROID_BLUETOOTH) + Q_UNUSED(role); return new QLowEnergyControllerPrivateAndroid(); #elif defined(QT_WINRT_BLUETOOTH) + Q_UNUSED(role); return new QLowEnergyControllerPrivateWinRT(); #else + Q_UNUSED(role); return new QLowEnergyControllerPrivateCommon(); #endif } -- cgit v1.2.3 From aad6e26574ff069e080bf6461c0fb7d0fee9e403 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 17 May 2018 16:15:04 +0200 Subject: 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 Reviewed-by: Timur Pocheptsov Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/bluetooth/qlowenergycontroller.cpp') diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index a23955ff..6b4c17d6 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -603,9 +603,10 @@ void QLowEnergyController::connectToDevice() This function does nothing if the controller is in the \l UnconnectedState. - If the controller is in the peripheral role, it stops advertising too. - The application must restart the advertising mode by calling - \l startAdvertising(). + If the controller is in the peripheral role, it stops advertising and removes + all services which have previously been added via \l addService(). + To reuse the QLowEnergyController instance the application must re-add services + and restart the advertising mode by calling \l startAdvertising(). \sa connectToDevice() */ @@ -742,6 +743,9 @@ void QLowEnergyController::startAdvertising(const QLowEnergyAdvertisingParameter /*! Stops advertising, if this object is currently in the advertising state. + The controller has to be in the \l PeripheralRole for this function to work. + It does not invalidate services which have previously been added via \l addService(). + \since 5.7 \sa startAdvertising() */ @@ -760,8 +764,15 @@ void QLowEnergyController::stopAdvertising() The controller must be in the \l PeripheralRole and in the \l UnconnectedState. The \a service object must be valid. + \note Once the peripheral instance is disconnected from the remote central device or + if \l disconnectFromDevice() is manually called, every service definition that was + previously added via this function is removed from the peripheral. Therefore this function + must be called again before re-advertising this peripheral controller instance. The described + behavior is connection specific and therefore not dependent on whether \l stopAdvertising() + was called. + \since 5.7 - \sa QLowEnergyServiceData::addIncludedService + \sa stopAdvertising(), disconnectFromDevice(), QLowEnergyServiceData::addIncludedService */ QLowEnergyService *QLowEnergyController::addService(const QLowEnergyServiceData &service, QObject *parent) -- cgit v1.2.3