diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/bluetooth.pro | 3 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristic.h | 1 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller.cpp | 10 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android.cpp | 86 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android_p.h | 175 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_p.h | 44 | ||||
-rw-r--r-- | src/bluetooth/qlowenergydescriptor.h | 1 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyservice.h | 1 |
8 files changed, 236 insertions, 85 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 6b07d890..378a7d00 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -146,6 +146,9 @@ qtConfig(bluez) { qbluetoothserver_android.cpp \ qlowenergycontroller_android.cpp + PRIVATE_HEADERS -= qlowenergycontroller_p.h + PRIVATE_HEADERS += qlowenergycontroller_android_p.h + } else:osx { QT_PRIVATE = concurrent DEFINES += QT_OSX_BLUETOOTH diff --git a/src/bluetooth/qlowenergycharacteristic.h b/src/bluetooth/qlowenergycharacteristic.h index d02e6560..c6d54f8e 100644 --- a/src/bluetooth/qlowenergycharacteristic.h +++ b/src/bluetooth/qlowenergycharacteristic.h @@ -97,6 +97,7 @@ protected: friend class QLowEnergyService; friend class QLowEnergyControllerPrivate; + friend class QLowEnergyControllerPrivateAndroid; friend class QLowEnergyControllerPrivateBluez; friend class QLowEnergyControllerPrivateCommon; friend class QLowEnergyControllerPrivateOSX; diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index e5c726b0..b79c22e5 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -52,6 +52,8 @@ #include "bluez/bluez5_helper_p.h" #include "qlowenergycontroller_bluezdbus_p.h" #include "qlowenergycontroller_bluez_p.h" +#elif defined(QT_ANDROID_BLUETOOTH) +#include "qlowenergycontroller_android_p.h" #else #include "qlowenergycontroller_p.h" #endif @@ -308,6 +310,8 @@ QLowEnergyController::QLowEnergyController( d_ptr = new QLowEnergyControllerPrivateBluezDBus(); else d_ptr = new QLowEnergyControllerPrivateBluez(); +#elif defined(QT_ANDROID_BLUETOOTH) + d_ptr = new QLowEnergyControllerPrivateAndroid(); #else d_ptr = new QLowEnergyControllerPrivateCommon(); #endif @@ -345,6 +349,8 @@ QLowEnergyController::QLowEnergyController( d_ptr = new QLowEnergyControllerPrivateBluezDBus(); else d_ptr = new QLowEnergyControllerPrivateBluez(); +#elif defined(QT_ANDROID_BLUETOOTH) + d_ptr = new QLowEnergyControllerPrivateAndroid(); #else d_ptr = new QLowEnergyControllerPrivateCommon(); #endif @@ -385,6 +391,8 @@ QLowEnergyController::QLowEnergyController( d_ptr = new QLowEnergyControllerPrivateBluezDBus(); else d_ptr = new QLowEnergyControllerPrivateBluez(); +#elif defined(QT_ANDROID_BLUETOOTH) + d_ptr = new QLowEnergyControllerPrivateAndroid(); #else d_ptr = new QLowEnergyControllerPrivateCommon(); #endif @@ -437,6 +445,8 @@ QLowEnergyController::QLowEnergyController(QObject *parent) d_ptr = new QLowEnergyControllerPrivateBluezDBus(); else d_ptr = new QLowEnergyControllerPrivateBluez(); +#elif defined(QT_ANDROID_BLUETOOTH) + d_ptr = new QLowEnergyControllerPrivateAndroid(); #else d_ptr = new QLowEnergyControllerPrivateCommon(); #endif diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 5c1a7060..592f6c70 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -37,7 +37,7 @@ ** ****************************************************************************/ -#include "qlowenergycontroller_p.h" +#include "qlowenergycontroller_android_p.h" #include <QtCore/QLoggingCategory> #include <QtAndroidExtras/QAndroidJniEnvironment> #include <QtBluetooth/QLowEnergyServiceData> @@ -69,14 +69,14 @@ static QAndroidJniObject javaUuidfromQtUuid(const QBluetoothUuid& uuid) return javaUuid; } -QLowEnergyControllerPrivateCommon::QLowEnergyControllerPrivateCommon() +QLowEnergyControllerPrivateAndroid::QLowEnergyControllerPrivateAndroid() : QLowEnergyControllerPrivate(), hub(0) { registerQLowEnergyControllerMetaType(); } -QLowEnergyControllerPrivateCommon::~QLowEnergyControllerPrivateCommon() +QLowEnergyControllerPrivateAndroid::~QLowEnergyControllerPrivateAndroid() { if (role == QLowEnergyController::PeripheralRole) { if (hub) @@ -84,7 +84,7 @@ QLowEnergyControllerPrivateCommon::~QLowEnergyControllerPrivateCommon() } } -void QLowEnergyControllerPrivateCommon::init() +void QLowEnergyControllerPrivateAndroid::init() { // Android Central/Client support starts with v18 // Peripheral/Server support requires Android API v21 @@ -104,13 +104,13 @@ void QLowEnergyControllerPrivateCommon::init() // we only connect to the peripheral role specific signals // TODO add connections as they get added later on connect(hub, &LowEnergyNotificationHub::connectionUpdated, - this, &QLowEnergyControllerPrivateCommon::connectionUpdated); + this, &QLowEnergyControllerPrivateAndroid::connectionUpdated); connect(hub, &LowEnergyNotificationHub::advertisementError, - this, &QLowEnergyControllerPrivateCommon::advertisementError); + this, &QLowEnergyControllerPrivateAndroid::advertisementError); connect(hub, &LowEnergyNotificationHub::serverCharacteristicChanged, - this, &QLowEnergyControllerPrivateCommon::serverCharacteristicChanged); + this, &QLowEnergyControllerPrivateAndroid::serverCharacteristicChanged); connect(hub, &LowEnergyNotificationHub::serverDescriptorWritten, - this, &QLowEnergyControllerPrivateCommon::serverDescriptorWritten); + this, &QLowEnergyControllerPrivateAndroid::serverDescriptorWritten); } else { if (version < 18) { qWarning() << "Qt Bluetooth LE Central/Client support not available" @@ -121,25 +121,25 @@ void QLowEnergyControllerPrivateCommon::init() hub = new LowEnergyNotificationHub(remoteDevice, isPeripheral, this); // we only connect to the central role specific signals connect(hub, &LowEnergyNotificationHub::connectionUpdated, - this, &QLowEnergyControllerPrivateCommon::connectionUpdated); + this, &QLowEnergyControllerPrivateAndroid::connectionUpdated); connect(hub, &LowEnergyNotificationHub::servicesDiscovered, - this, &QLowEnergyControllerPrivateCommon::servicesDiscovered); + this, &QLowEnergyControllerPrivateAndroid::servicesDiscovered); connect(hub, &LowEnergyNotificationHub::serviceDetailsDiscoveryFinished, - this, &QLowEnergyControllerPrivateCommon::serviceDetailsDiscoveryFinished); + this, &QLowEnergyControllerPrivateAndroid::serviceDetailsDiscoveryFinished); connect(hub, &LowEnergyNotificationHub::characteristicRead, - this, &QLowEnergyControllerPrivateCommon::characteristicRead); + this, &QLowEnergyControllerPrivateAndroid::characteristicRead); connect(hub, &LowEnergyNotificationHub::descriptorRead, - this, &QLowEnergyControllerPrivateCommon::descriptorRead); + this, &QLowEnergyControllerPrivateAndroid::descriptorRead); connect(hub, &LowEnergyNotificationHub::characteristicWritten, - this, &QLowEnergyControllerPrivateCommon::characteristicWritten); + this, &QLowEnergyControllerPrivateAndroid::characteristicWritten); connect(hub, &LowEnergyNotificationHub::descriptorWritten, - this, &QLowEnergyControllerPrivateCommon::descriptorWritten); + this, &QLowEnergyControllerPrivateAndroid::descriptorWritten); connect(hub, &LowEnergyNotificationHub::characteristicChanged, - this, &QLowEnergyControllerPrivateCommon::characteristicChanged); + this, &QLowEnergyControllerPrivateAndroid::characteristicChanged); } } -void QLowEnergyControllerPrivateCommon::connectToDevice() +void QLowEnergyControllerPrivateAndroid::connectToDevice() { if (!hub) return; // Android version below v18 @@ -168,7 +168,7 @@ void QLowEnergyControllerPrivateCommon::connectToDevice() } } -void QLowEnergyControllerPrivateCommon::disconnectFromDevice() +void QLowEnergyControllerPrivateAndroid::disconnectFromDevice() { /* Catch an Android timeout bug. If the device is connecting but cannot * physically connect it seems to ignore the disconnect call below. @@ -186,7 +186,7 @@ void QLowEnergyControllerPrivateCommon::disconnectFromDevice() setState(QLowEnergyController::UnconnectedState); } -void QLowEnergyControllerPrivateCommon::discoverServices() +void QLowEnergyControllerPrivateAndroid::discoverServices() { if (hub && hub->javaObject().callMethod<jboolean>("discoverServices")) { qCDebug(QT_BT_ANDROID) << "Service discovery initiated"; @@ -197,7 +197,7 @@ void QLowEnergyControllerPrivateCommon::discoverServices() } } -void QLowEnergyControllerPrivateCommon::discoverServiceDetails(const QBluetoothUuid &service) +void QLowEnergyControllerPrivateAndroid::discoverServiceDetails(const QBluetoothUuid &service) { if (!serviceList.contains(service)) { qCWarning(QT_BT_ANDROID) << "Discovery of unknown service" << service.toString() @@ -232,7 +232,7 @@ void QLowEnergyControllerPrivateCommon::discoverServiceDetails(const QBluetoothU qCDebug(QT_BT_ANDROID) << "Discovery of" << service << "started"; } -void QLowEnergyControllerPrivateCommon::writeCharacteristic( +void QLowEnergyControllerPrivateAndroid::writeCharacteristic( const QSharedPointer<QLowEnergyServicePrivate> service, const QLowEnergyHandle charHandle, const QByteArray &newValue, @@ -286,7 +286,7 @@ void QLowEnergyControllerPrivateCommon::writeCharacteristic( service->setError(QLowEnergyService::CharacteristicWriteError); } -void QLowEnergyControllerPrivateCommon::writeDescriptor( +void QLowEnergyControllerPrivateAndroid::writeDescriptor( const QSharedPointer<QLowEnergyServicePrivate> service, const QLowEnergyHandle charHandle, const QLowEnergyHandle descHandle, @@ -337,7 +337,7 @@ void QLowEnergyControllerPrivateCommon::writeDescriptor( service->setError(QLowEnergyService::DescriptorWriteError); } -void QLowEnergyControllerPrivateCommon::readCharacteristic( +void QLowEnergyControllerPrivateAndroid::readCharacteristic( const QSharedPointer<QLowEnergyServicePrivate> service, const QLowEnergyHandle charHandle) { @@ -365,7 +365,7 @@ void QLowEnergyControllerPrivateCommon::readCharacteristic( service->setError(QLowEnergyService::CharacteristicReadError); } -void QLowEnergyControllerPrivateCommon::readDescriptor( +void QLowEnergyControllerPrivateAndroid::readDescriptor( const QSharedPointer<QLowEnergyServicePrivate> service, const QLowEnergyHandle /*charHandle*/, const QLowEnergyHandle descriptorHandle) @@ -391,7 +391,7 @@ void QLowEnergyControllerPrivateCommon::readDescriptor( service->setError(QLowEnergyService::DescriptorReadError); } -void QLowEnergyControllerPrivateCommon::connectionUpdated( +void QLowEnergyControllerPrivateAndroid::connectionUpdated( QLowEnergyController::ControllerState newState, QLowEnergyController::Error errorCode) { @@ -407,7 +407,7 @@ void QLowEnergyControllerPrivateCommon::connectionUpdated( } // called if server/peripheral -void QLowEnergyControllerPrivateCommon::peripheralConnectionUpdated( +void QLowEnergyControllerPrivateAndroid::peripheralConnectionUpdated( QLowEnergyController::ControllerState newState, QLowEnergyController::Error errorCode) { @@ -437,7 +437,7 @@ void QLowEnergyControllerPrivateCommon::peripheralConnectionUpdated( } // called if client/central -void QLowEnergyControllerPrivateCommon::centralConnectionUpdated( +void QLowEnergyControllerPrivateAndroid::centralConnectionUpdated( QLowEnergyController::ControllerState newState, QLowEnergyController::Error errorCode) { @@ -482,7 +482,7 @@ void QLowEnergyControllerPrivateCommon::centralConnectionUpdated( } } -void QLowEnergyControllerPrivateCommon::servicesDiscovered( +void QLowEnergyControllerPrivateAndroid::servicesDiscovered( QLowEnergyController::Error errorCode, const QString &foundServices) { Q_Q(QLowEnergyController); @@ -513,7 +513,7 @@ void QLowEnergyControllerPrivateCommon::servicesDiscovered( } } -void QLowEnergyControllerPrivateCommon::serviceDetailsDiscoveryFinished( +void QLowEnergyControllerPrivateAndroid::serviceDetailsDiscoveryFinished( const QString &serviceUuid, int startHandle, int endHandle) { const QBluetoothUuid service(serviceUuid); @@ -561,7 +561,7 @@ void QLowEnergyControllerPrivateCommon::serviceDetailsDiscoveryFinished( pointer->setState(QLowEnergyService::ServiceDiscovered); } -void QLowEnergyControllerPrivateCommon::characteristicRead( +void QLowEnergyControllerPrivateAndroid::characteristicRead( const QBluetoothUuid &serviceUuid, int handle, const QBluetoothUuid &charUuid, int properties, const QByteArray &data) { @@ -592,7 +592,7 @@ void QLowEnergyControllerPrivateCommon::characteristicRead( } } -void QLowEnergyControllerPrivateCommon::descriptorRead( +void QLowEnergyControllerPrivateAndroid::descriptorRead( const QBluetoothUuid &serviceUuid, const QBluetoothUuid &charUuid, int descHandle, const QBluetoothUuid &descUuid, const QByteArray &data) { @@ -633,7 +633,7 @@ void QLowEnergyControllerPrivateCommon::descriptorRead( } } -void QLowEnergyControllerPrivateCommon::characteristicWritten( +void QLowEnergyControllerPrivateAndroid::characteristicWritten( int charHandle, const QByteArray &data, QLowEnergyService::ServiceError errorCode) { QSharedPointer<QLowEnergyServicePrivate> service = @@ -662,7 +662,7 @@ void QLowEnergyControllerPrivateCommon::characteristicWritten( emit service->characteristicWritten(characteristic, data); } -void QLowEnergyControllerPrivateCommon::descriptorWritten( +void QLowEnergyControllerPrivateAndroid::descriptorWritten( int descHandle, const QByteArray &data, QLowEnergyService::ServiceError errorCode) { QSharedPointer<QLowEnergyServicePrivate> service = @@ -689,7 +689,7 @@ void QLowEnergyControllerPrivateCommon::descriptorWritten( emit service->descriptorWritten(descriptor, data); } -void QLowEnergyControllerPrivateCommon::serverDescriptorWritten( +void QLowEnergyControllerPrivateAndroid::serverDescriptorWritten( const QAndroidJniObject &jniDesc, const QByteArray &newValue) { qCDebug(QT_BT_ANDROID) << "Server descriptor change notification" << newValue.toHex(); @@ -754,7 +754,7 @@ void QLowEnergyControllerPrivateCommon::serverDescriptorWritten( } } -void QLowEnergyControllerPrivateCommon::characteristicChanged( +void QLowEnergyControllerPrivateAndroid::characteristicChanged( int charHandle, const QByteArray &data) { QSharedPointer<QLowEnergyServicePrivate> service = @@ -779,7 +779,7 @@ void QLowEnergyControllerPrivateCommon::characteristicChanged( emit service->characteristicChanged(characteristic, data); } -void QLowEnergyControllerPrivateCommon::serverCharacteristicChanged( +void QLowEnergyControllerPrivateAndroid::serverCharacteristicChanged( const QAndroidJniObject &characteristic, const QByteArray &newValue) { qCDebug(QT_BT_ANDROID) << "Server characteristic change notification" << newValue.toHex(); @@ -828,7 +828,7 @@ void QLowEnergyControllerPrivateCommon::serverCharacteristicChanged( QLowEnergyCharacteristic(servicePrivate, foundHandle), newValue); } -void QLowEnergyControllerPrivateCommon::serviceError( +void QLowEnergyControllerPrivateAndroid::serviceError( int attributeHandle, QLowEnergyService::ServiceError errorCode) { // ignore call if it isn't really an error @@ -844,7 +844,7 @@ void QLowEnergyControllerPrivateCommon::serviceError( service->setError(errorCode); } -void QLowEnergyControllerPrivateCommon::advertisementError(int errorCode) +void QLowEnergyControllerPrivateAndroid::advertisementError(int errorCode) { Q_Q(QLowEnergyController); @@ -995,7 +995,7 @@ static QAndroidJniObject createJavaAdvertiseSettings(const QLowEnergyAdvertising } -void QLowEnergyControllerPrivateCommon::startAdvertising(const QLowEnergyAdvertisingParameters ¶ms, +void QLowEnergyControllerPrivateAndroid::startAdvertising(const QLowEnergyAdvertisingParameters ¶ms, const QLowEnergyAdvertisingData &advertisingData, const QLowEnergyAdvertisingData &scanResponseData) { @@ -1022,13 +1022,13 @@ void QLowEnergyControllerPrivateCommon::startAdvertising(const QLowEnergyAdverti } } -void QLowEnergyControllerPrivateCommon::stopAdvertising() +void QLowEnergyControllerPrivateAndroid::stopAdvertising() { setState(QLowEnergyController::UnconnectedState); hub->javaObject().callMethod<void>("stopAdvertising"); } -void QLowEnergyControllerPrivateCommon::requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms) +void QLowEnergyControllerPrivateAndroid::requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms) { // Possible since Android v21 // Android does not permit specification of specific latency or min/max @@ -1167,7 +1167,7 @@ static int setupDescPermissions(const QLowEnergyDescriptorData &descData) return permissions; } -void QLowEnergyControllerPrivateCommon::addToGenericAttributeList(const QLowEnergyServiceData &serviceData, +void QLowEnergyControllerPrivateAndroid::addToGenericAttributeList(const QLowEnergyServiceData &serviceData, QLowEnergyHandle startHandle) { QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(startHandle); @@ -1258,7 +1258,7 @@ void QLowEnergyControllerPrivateCommon::addToGenericAttributeList(const QLowEner service->androidService.object()); } -QLowEnergyService *QLowEnergyControllerPrivateCommon::addServiceHelper( +QLowEnergyService *QLowEnergyControllerPrivateAndroid::addServiceHelper( const QLowEnergyServiceData &service) { // Spec says services "should" be grouped by uuid length (16-bit first, then 128-bit). diff --git a/src/bluetooth/qlowenergycontroller_android_p.h b/src/bluetooth/qlowenergycontroller_android_p.h new file mode 100644 index 00000000..ba56ad4c --- /dev/null +++ b/src/bluetooth/qlowenergycontroller_android_p.h @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** 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 QLOWENERGYCONTROLLERPRIVATEANDROID_P_H +#define QLOWENERGYCONTROLLERPRIVATEANDROID_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 <qglobal.h> +#include <QtCore/QQueue> +#include <QtCore/QVector> +#include <QtBluetooth/qbluetooth.h> +#include <QtBluetooth/qlowenergycharacteristic.h> +#include "qlowenergycontroller.h" +#include "qlowenergycontrollerbase_p.h" + +#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE) +#include <QtBluetooth/QBluetoothSocket> +#elif defined(QT_ANDROID_BLUETOOTH) +#include <QtAndroidExtras/QAndroidJniObject> +#include "android/lowenergynotificationhub_p.h" +#elif defined(QT_WINRT_BLUETOOTH) +#include <wrl.h> +#include <windows.devices.bluetooth.h> +#endif + +#include <functional> + +QT_BEGIN_NAMESPACE + +class QLowEnergyServiceData; +class QTimer; + +#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE) +class HciManager; +class LeCmacCalculator; +class QSocketNotifier; +class RemoteDeviceManager; +#elif defined(QT_ANDROID_BLUETOOTH) +class LowEnergyNotificationHub; +#elif defined(QT_WINRT_BLUETOOTH) +class QWinRTLowEnergyServiceHandler; +#endif + +extern void registerQLowEnergyControllerMetaType(); + +class QLeAdvertiser; + +class QLowEnergyControllerPrivateAndroid : public QLowEnergyControllerPrivate +{ + Q_OBJECT +public: + QLowEnergyControllerPrivateAndroid(); + ~QLowEnergyControllerPrivateAndroid(); + + void init() override; + + void connectToDevice() override; + void disconnectFromDevice() override; + + void discoverServices() override; + void discoverServiceDetails(const QBluetoothUuid &service) override; + + void startAdvertising(const QLowEnergyAdvertisingParameters ¶ms, + const QLowEnergyAdvertisingData &advertisingData, + const QLowEnergyAdvertisingData &scanResponseData) override; + void stopAdvertising() override; + + void requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms) override; + + // misc helpers + QLowEnergyService *addServiceHelper(const QLowEnergyServiceData &service) override; + + // read data + void readCharacteristic(const QSharedPointer<QLowEnergyServicePrivate> service, + const QLowEnergyHandle charHandle) override; + void readDescriptor(const QSharedPointer<QLowEnergyServicePrivate> service, + const QLowEnergyHandle charHandle, + const QLowEnergyHandle descriptorHandle) override; + + // write data + void writeCharacteristic(const QSharedPointer<QLowEnergyServicePrivate> service, + const QLowEnergyHandle charHandle, + const QByteArray &newValue, QLowEnergyService::WriteMode mode) override; + void writeDescriptor(const QSharedPointer<QLowEnergyServicePrivate> service, + const QLowEnergyHandle charHandle, + const QLowEnergyHandle descriptorHandle, + const QByteArray &newValue) override; + + void addToGenericAttributeList(const QLowEnergyServiceData &service, + QLowEnergyHandle startHandle) override; + + QLowEnergyHandle lastLocalHandle; +private: + + LowEnergyNotificationHub *hub; + +private slots: + void connectionUpdated(QLowEnergyController::ControllerState newState, + QLowEnergyController::Error errorCode); + void servicesDiscovered(QLowEnergyController::Error errorCode, + const QString &foundServices); + void serviceDetailsDiscoveryFinished(const QString& serviceUuid, + int startHandle, int endHandle); + void characteristicRead(const QBluetoothUuid &serviceUuid, int handle, + const QBluetoothUuid &charUuid, int properties, + const QByteArray& data); + void descriptorRead(const QBluetoothUuid &serviceUuid, const QBluetoothUuid &charUuid, + int handle, const QBluetoothUuid &descUuid, const QByteArray &data); + void characteristicWritten(int charHandle, const QByteArray &data, + QLowEnergyService::ServiceError errorCode); + void descriptorWritten(int descHandle, const QByteArray &data, + QLowEnergyService::ServiceError errorCode); + void serverDescriptorWritten(const QAndroidJniObject &jniDesc, const QByteArray &newValue); + void characteristicChanged(int charHandle, const QByteArray &data); + void serverCharacteristicChanged(const QAndroidJniObject &jniChar, const QByteArray &newValue); + void serviceError(int attributeHandle, QLowEnergyService::ServiceError errorCode); + void advertisementError(int errorCode); + +private: + void peripheralConnectionUpdated(QLowEnergyController::ControllerState newState, + QLowEnergyController::Error errorCode); + void centralConnectionUpdated(QLowEnergyController::ControllerState newState, + QLowEnergyController::Error errorCode); +}; + +QT_END_NAMESPACE + +#endif // QLOWENERGYCONTROLLERPRIVATEANDROID_P_H diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h index 4b3d43c8..db34c344 100644 --- a/src/bluetooth/qlowenergycontroller_p.h +++ b/src/bluetooth/qlowenergycontroller_p.h @@ -77,10 +77,7 @@ QT_END_NAMESPACE #include "qlowenergycontroller.h" #include "qlowenergycontrollerbase_p.h" -#if defined(QT_ANDROID_BLUETOOTH) -#include <QtAndroidExtras/QAndroidJniObject> -#include "android/lowenergynotificationhub_p.h" -#elif defined(QT_WINRT_BLUETOOTH) +#if defined(QT_WINRT_BLUETOOTH) #include <wrl.h> #include <windows.devices.bluetooth.h> #endif @@ -92,12 +89,6 @@ QT_BEGIN_NAMESPACE class QLowEnergyServiceData; class QTimer; -#if defined(QT_ANDROID_BLUETOOTH) -class LowEnergyNotificationHub; -#elif defined(QT_WINRT_BLUETOOTH) -class QWinRTLowEnergyServiceHandler; -#endif - extern void registerQLowEnergyControllerMetaType(); class QLowEnergyControllerPrivateCommon : public QLowEnergyControllerPrivate @@ -164,38 +155,7 @@ public: private: -#if defined(QT_ANDROID_BLUETOOTH) - LowEnergyNotificationHub *hub; - -private slots: - void connectionUpdated(QLowEnergyController::ControllerState newState, - QLowEnergyController::Error errorCode); - void servicesDiscovered(QLowEnergyController::Error errorCode, - const QString &foundServices); - void serviceDetailsDiscoveryFinished(const QString& serviceUuid, - int startHandle, int endHandle); - void characteristicRead(const QBluetoothUuid &serviceUuid, int handle, - const QBluetoothUuid &charUuid, int properties, - const QByteArray& data); - void descriptorRead(const QBluetoothUuid &serviceUuid, const QBluetoothUuid &charUuid, - int handle, const QBluetoothUuid &descUuid, const QByteArray &data); - void characteristicWritten(int charHandle, const QByteArray &data, - QLowEnergyService::ServiceError errorCode); - void descriptorWritten(int descHandle, const QByteArray &data, - QLowEnergyService::ServiceError errorCode); - void serverDescriptorWritten(const QAndroidJniObject &jniDesc, const QByteArray &newValue); - void characteristicChanged(int charHandle, const QByteArray &data); - void serverCharacteristicChanged(const QAndroidJniObject &jniChar, const QByteArray &newValue); - void serviceError(int attributeHandle, QLowEnergyService::ServiceError errorCode); - void advertisementError(int errorCode); - -private: - void peripheralConnectionUpdated(QLowEnergyController::ControllerState newState, - QLowEnergyController::Error errorCode); - void centralConnectionUpdated(QLowEnergyController::ControllerState newState, - QLowEnergyController::Error errorCode); - -#elif defined(QT_WINRT_BLUETOOTH) +#if defined(QT_WINRT_BLUETOOTH) private slots: void characteristicChanged(int charHandle, const QByteArray &data); diff --git a/src/bluetooth/qlowenergydescriptor.h b/src/bluetooth/qlowenergydescriptor.h index 8060b2f3..fd37498d 100644 --- a/src/bluetooth/qlowenergydescriptor.h +++ b/src/bluetooth/qlowenergydescriptor.h @@ -79,6 +79,7 @@ protected: friend class QLowEnergyCharacteristic; friend class QLowEnergyService; friend class QLowEnergyControllerPrivate; + friend class QLowEnergyControllerPrivateAndroid; friend class QLowEnergyControllerPrivateBluez; friend class QLowEnergyControllerPrivateCommon; friend class QLowEnergyControllerPrivateOSX; diff --git a/src/bluetooth/qlowenergyservice.h b/src/bluetooth/qlowenergyservice.h index aa686413..233e08b0 100644 --- a/src/bluetooth/qlowenergyservice.h +++ b/src/bluetooth/qlowenergyservice.h @@ -134,6 +134,7 @@ private: // QLowEnergyController is the factory for this class friend class QLowEnergyController; + friend class QLowEnergyControllerPrivateAndroid; friend class QLowEnergyControllerPrivateBluez; friend class QLowEnergyControllerPrivateCommon; QLowEnergyService(QSharedPointer<QLowEnergyServicePrivate> p, |