From 59ae3cc2ac7baee7e9df1e6ceffcfc882fbe6121 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 24 Oct 2017 16:46:03 +0200 Subject: Introduce Base class for QLowEnergyControllerPrivate This permits alternative implementations selectable at runtime. Currently this is only used by Bluez. Change-Id: I3ddeb7f888f3b09bdc62f10d5b9a36320500f329 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qlowenergycontroller_bluezdbus_p.h | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/bluetooth/qlowenergycontroller_bluezdbus_p.h (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus_p.h') diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h new file mode 100644 index 00000000..fb7f3e7a --- /dev/null +++ b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QLOWENERGYCONTROLLERPRIVATEDBUS_P_H +#define QLOWENERGYCONTROLLERPRIVATEDBUS_P_H + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qlowenergycontroller.h" +#include "qlowenergycontrollerbase_p.h" + +QT_BEGIN_NAMESPACE + +class QLowEnergyControllerPrivateBluezDBus : public QLowEnergyControllerPrivateBase +{ + Q_OBJECT +public: + QLowEnergyControllerPrivateBluezDBus(); + ~QLowEnergyControllerPrivateBluezDBus(); + + void init() override; + void connectToDevice() override; + void disconnectFromDevice() override; + + void discoverServices() override; + void discoverServiceDetails(const QBluetoothUuid &/*service*/) override; + + void readCharacteristic( + const QSharedPointer /*service*/, + const QLowEnergyHandle /*charHandle*/) override; + void readDescriptor( + const QSharedPointer /*service*/, + const QLowEnergyHandle /*charHandle*/, + const QLowEnergyHandle /*descriptorHandle*/) override; + + void writeCharacteristic( + const QSharedPointer /*service*/, + const QLowEnergyHandle /*charHandle*/, + const QByteArray &/*newValue*/, + QLowEnergyService::WriteMode /*writeMode*/) override; + void writeDescriptor( + const QSharedPointer /*service*/, + const QLowEnergyHandle /*charHandle*/, + const QLowEnergyHandle /*descriptorHandle*/, + const QByteArray &/*newValue*/) override; + + void startAdvertising( + const QLowEnergyAdvertisingParameters &/* params */, + const QLowEnergyAdvertisingData &/* advertisingData */, + const QLowEnergyAdvertisingData &/* scanResponseData */) override; + void stopAdvertising() override; + + void requestConnectionUpdate( + const QLowEnergyConnectionParameters & /* params */) override; + void addToGenericAttributeList( + const QLowEnergyServiceData &/* service */, + QLowEnergyHandle /* startHandle */) override; + + QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service) override; + + QLowEnergyController::ControllerState state; + QLowEnergyController::Error error; +}; + +QT_END_NAMESPACE + +#endif // QLOWENERGYCONTROLLERPRIVATEDBUS_P_H -- cgit v1.2.3 From fbf36811672de79f2a648af97ca73d6c0e3b1608 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 25 Oct 2017 14:49:47 +0200 Subject: Rename various QLEControllerPrivate classes The base class is renamed to QLEControllerPrivate and the existing QLEControllerPrivate becomes QLEControllerPrivateCommon. This is necessary to re-enable Q_DECLARE_PRIVATE. The macro uses by convention the "Private" class prefix which is currently broken because not every implementation uses QLEControllerPrivate as d-pointer type. This also avoids a SC/BC break in qlowenergycontroller.h as the d-pointer remains the same and the functions declared via Q_DECLARE_PRIVATE still return the same type. Change-Id: I84890b06280b2c473a4d370606d3bbc58a258eea Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller_bluezdbus_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus_p.h') diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h index fb7f3e7a..b10199f5 100644 --- a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h +++ b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE -class QLowEnergyControllerPrivateBluezDBus : public QLowEnergyControllerPrivateBase +class QLowEnergyControllerPrivateBluezDBus : public QLowEnergyControllerPrivate { Q_OBJECT public: -- cgit v1.2.3 From da7a013dd2aa7bed9f4a6b5122b8f9dadcb252ab Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 29 Nov 2017 15:15:51 +0100 Subject: BTLE DBus: Add ability to connect/disconnect to remote device The patch uses the Device1 DBus API to connect and disconnect to a remote BTLE device. In addition, status and error condition tracking is added to adapt to various error cases. Task-number: QTBUG-46819 Change-Id: I0671df5596882c89aeead89c05ddcc855f8ba375 Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller_bluezdbus_p.h | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus_p.h') diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h index b10199f5..c4589381 100644 --- a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h +++ b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h @@ -55,6 +55,13 @@ #include "qlowenergycontroller.h" #include "qlowenergycontrollerbase_p.h" +#include + +class OrgBluezAdapter1Interface; +class OrgBluezDevice1Interface; +class OrgFreedesktopDBusObjectManagerInterface; +class OrgFreedesktopDBusPropertiesInterface; + QT_BEGIN_NAMESPACE class QLowEnergyControllerPrivateBluezDBus : public QLowEnergyControllerPrivate @@ -104,8 +111,25 @@ public: QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service) override; - QLowEnergyController::ControllerState state; - QLowEnergyController::Error error; + +private: + void connectToDeviceHelper(); + void resetController(); + +private slots: + void devicePropertiesChanged(const QString &interface, const QVariantMap &changedProperties, + const QStringList &/*invalidatedProperties*/); + void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces); + +private: + OrgBluezAdapter1Interface* adapter{}; + OrgBluezDevice1Interface* device{}; + OrgFreedesktopDBusObjectManagerInterface* managerBluez{}; + OrgFreedesktopDBusPropertiesInterface* deviceMonitor{}; + + bool pendingConnect = false; + bool pendingDisconnect = false; + bool disconnectSignalRequired = false; }; QT_END_NAMESPACE -- cgit v1.2.3 From 4462750a68cb93b5d363b6efdbe1d6a6f0e5811f Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 14 Dec 2017 14:29:53 +0100 Subject: Implement QLEService::discoverDetails for DBus Bluez This includes support for reading of characteristics and descriptors. Task-number: QTBUG-46819 Change-Id: I8ac1ef3bcd5bc475941f1a9f889d0742eb8def35 Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller_bluezdbus_p.h | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus_p.h') diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h index c4589381..84326e48 100644 --- a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h +++ b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h @@ -59,11 +59,16 @@ class OrgBluezAdapter1Interface; class OrgBluezDevice1Interface; +class OrgBluezGattCharacteristic1Interface; +class OrgBluezGattDescriptor1Interface; +class OrgBluezGattService1Interface; class OrgFreedesktopDBusObjectManagerInterface; class OrgFreedesktopDBusPropertiesInterface; QT_BEGIN_NAMESPACE +class QDBusPendingCallWatcher; + class QLowEnergyControllerPrivateBluezDBus : public QLowEnergyControllerPrivate { Q_OBJECT @@ -116,11 +121,15 @@ private: void connectToDeviceHelper(); void resetController(); + void scheduleNextJob(); + private slots: void devicePropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &/*invalidatedProperties*/); void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces); + void onCharReadFinished(QDBusPendingCallWatcher *call); + void onDescReadFinished(QDBusPendingCallWatcher *call); private: OrgBluezAdapter1Interface* adapter{}; OrgBluezDevice1Interface* device{}; @@ -130,6 +139,43 @@ private: bool pendingConnect = false; bool pendingDisconnect = false; bool disconnectSignalRequired = false; + + struct GattCharacteristic + { + QSharedPointer characteristic; + QVector> descriptors; + }; + + struct GattService + { + QString servicePath; + QVector characteristics; + }; + + QHash dbusServices; + QLowEnergyHandle runningHandle = 1; + + struct GattJob { + enum JobFlag { + Unset = 0x00, + CharRead = 0x01, + CharWrite = 0x02, + DescRead = 0x04, + DescWrite = 0x08, + ServiceDiscovery = 0x10, + LastServiceDiscovery = 0x20 + }; + Q_DECLARE_FLAGS(JobFlags, JobFlag) + + JobFlags flags = GattJob::Unset; + QLowEnergyHandle handle; + QSharedPointer service; + }; + + QVector jobs; + bool jobPending = false; + + void prepareNextJob(); }; QT_END_NAMESPACE -- cgit v1.2.3 From 1e03015803549e2865b2772fe5be43d7bec8ccc1 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 4 Jan 2018 13:08:29 +0100 Subject: Implement Char read & write for dbus Gatt Read/write is limited to central role support. Peripheral role support will follow at a later stage. Task-number: QTBUG-46819 Change-Id: Idc27ea31cf0629470dc46490235c57f64b51498d Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller_bluezdbus_p.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus_p.h') diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h index 84326e48..c4845fc1 100644 --- a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h +++ b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h @@ -130,6 +130,7 @@ private slots: void onCharReadFinished(QDBusPendingCallWatcher *call); void onDescReadFinished(QDBusPendingCallWatcher *call); + void onCharWriteFinished(QDBusPendingCallWatcher *call); private: OrgBluezAdapter1Interface* adapter{}; OrgBluezDevice1Interface* device{}; @@ -169,6 +170,8 @@ private: JobFlags flags = GattJob::Unset; QLowEnergyHandle handle; + QByteArray value; + QLowEnergyService::WriteMode writeMode = QLowEnergyService::WriteWithResponse; QSharedPointer service; }; -- cgit v1.2.3 From 45ea69635f08f967b31660e2bcd33d3bb8187497 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 10 Jan 2018 10:31:41 +0100 Subject: Implement read-/writeDescriptor() for DBus GATT In addition there is a minor debug cleanup in the reading of descriptor code. Task-number: QTBUG-46819 Change-Id: I3f65c7d113b306b5b4892fa5df189476c06df0e9 Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller_bluezdbus_p.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus_p.h') diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h index c4845fc1..7195bfbf 100644 --- a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h +++ b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h @@ -131,6 +131,7 @@ private slots: void onCharReadFinished(QDBusPendingCallWatcher *call); void onDescReadFinished(QDBusPendingCallWatcher *call); void onCharWriteFinished(QDBusPendingCallWatcher *call); + void onDescWriteFinished(QDBusPendingCallWatcher *call); private: OrgBluezAdapter1Interface* adapter{}; OrgBluezDevice1Interface* device{}; -- cgit v1.2.3 From e55981842b702dced8ed0301ff9550e7d98e8a14 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 22 Jan 2018 12:24:01 +0100 Subject: BlueZ: Implements characteristicChanged() notifications This feature depends on ClientCharacteristicConfiguration descriptor types which determine whether changed signals are sent or not. The patch also ensures that cached char values are not updated/cached when the char is not readable. Task-number: QTBUG-46819 Change-Id: I841bcaaca60c588eae7d4067b6ead6af28f957e3 Reviewed-by: Oliver Wolff --- src/bluetooth/qlowenergycontroller_bluezdbus_p.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus_p.h') diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h index 7195bfbf..7ac1808f 100644 --- a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h +++ b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h @@ -126,6 +126,9 @@ private: private slots: void devicePropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &/*invalidatedProperties*/); + void characteristicPropertiesChanged(QLowEnergyHandle charHandle, const QString &interface, + const QVariantMap &changedProperties, + const QStringList &invalidatedProperties); void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces); void onCharReadFinished(QDBusPendingCallWatcher *call); @@ -145,6 +148,7 @@ private: struct GattCharacteristic { QSharedPointer characteristic; + QSharedPointer charMonitor; QVector> descriptors; }; -- cgit v1.2.3 From 98aa6ba02628eb29cc82361fad6d2d8b18ae0488 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 24 Jul 2018 13:28:55 +0200 Subject: Mark classes derived from QLowEnergyControllerPrivate as final Fixes missing overrides for the dtor in the process. Change-Id: Iea3d010c1cebddaf8ea6ea392a7f13e4d87f67da Reviewed-by: Timur Pocheptsov --- src/bluetooth/qlowenergycontroller_bluezdbus_p.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/qlowenergycontroller_bluezdbus_p.h') diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h index 7ac1808f..0e0bfcb5 100644 --- a/src/bluetooth/qlowenergycontroller_bluezdbus_p.h +++ b/src/bluetooth/qlowenergycontroller_bluezdbus_p.h @@ -69,12 +69,12 @@ QT_BEGIN_NAMESPACE class QDBusPendingCallWatcher; -class QLowEnergyControllerPrivateBluezDBus : public QLowEnergyControllerPrivate +class QLowEnergyControllerPrivateBluezDBus final : public QLowEnergyControllerPrivate { Q_OBJECT public: QLowEnergyControllerPrivateBluezDBus(); - ~QLowEnergyControllerPrivateBluezDBus(); + ~QLowEnergyControllerPrivateBluezDBus() override; void init() override; void connectToDevice() override; -- cgit v1.2.3