diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/bluetooth.pro | 7 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontrollernew.cpp | 14 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontrollernew_bluez.cpp | 15 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontrollernew_p.h | 10 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyservice.cpp | 61 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyservice.h | 14 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyserviceprivate.cpp | 75 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyserviceprivate_p.h | 81 |
8 files changed, 193 insertions, 84 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index e2663df0..cceceea2 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -49,7 +49,8 @@ PRIVATE_HEADERS += \ qlowenergyprocess_p.h \ qlowenergydescriptorinfo_p.h \ qlowenergycontroller_p.h \ - qlowenergycontrollernew_p.h + qlowenergycontrollernew_p.h \ + qlowenergyserviceprivate_p.h SOURCES += \ qbluetoothaddress.cpp\ @@ -71,7 +72,8 @@ SOURCES += \ qlowenergycharacteristicinfo.cpp \ qlowenergydescriptorinfo.cpp \ qlowenergycontroller.cpp \ - qlowenergycontrollernew.cpp + qlowenergycontrollernew.cpp \ + qlowenergyserviceprivate.cpp config_bluez:qtHaveModule(dbus) { QT *= dbus @@ -187,3 +189,4 @@ config_bluez:qtHaveModule(dbus) { OTHER_FILES += HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS + diff --git a/src/bluetooth/qlowenergycontrollernew.cpp b/src/bluetooth/qlowenergycontrollernew.cpp index 0a9800ae..bc65b3cf 100644 --- a/src/bluetooth/qlowenergycontrollernew.cpp +++ b/src/bluetooth/qlowenergycontrollernew.cpp @@ -102,10 +102,10 @@ void QLowEnergyControllerNewPrivate::setState( void QLowEnergyControllerNewPrivate::invalidateServices() { - foreach (const QBluetoothUuid &service, serviceList.keys()) { - ServiceDetails detail = serviceList.take(service); - detail.service.data()->setState(QLowEnergyService::InvalidService); - } + foreach (const QSharedPointer<QLowEnergyServicePrivate> service, serviceList.values()) + service->setState(QLowEnergyService::InvalidService); + + serviceList.clear(); } QLowEnergyControllerNew::QLowEnergyControllerNew( @@ -200,8 +200,10 @@ void QLowEnergyControllerNew::discoverServices() QList<QSharedPointer<QLowEnergyService> > QLowEnergyControllerNew::services() const { QList<QSharedPointer<QLowEnergyService> > results; - foreach (const ServiceDetails &entry, d_ptr->serviceList) - results.append(entry.service); + foreach (const QSharedPointer<QLowEnergyServicePrivate> p, d_ptr->serviceList.values()) { + QLowEnergyService *service = new QLowEnergyService(p); + results.append(QSharedPointer<QLowEnergyService>(service)); + } return results; } diff --git a/src/bluetooth/qlowenergycontrollernew_bluez.cpp b/src/bluetooth/qlowenergycontrollernew_bluez.cpp index a2a0bac2..fd04b7ca 100644 --- a/src/bluetooth/qlowenergycontrollernew_bluez.cpp +++ b/src/bluetooth/qlowenergycontrollernew_bluez.cpp @@ -180,16 +180,15 @@ void QLowEnergyControllerNewPrivate::l2cpReadyRead() //qDebug() << "Found uuid:" << uuid << "start handle:" << hex // << start << "end handle:" << end; - ServiceDetails details; - details.startHandle = start; - details.endHandle = end; + QLowEnergyServicePrivate *priv = new QLowEnergyServicePrivate(); + priv->uuid = uuid; + priv->startHandle = start; + priv->endHandle = end; + priv->setController(this); - QLowEnergyService *service = new QLowEnergyService(uuid); - service->setController(this); - QSharedPointer<QLowEnergyService> pointer(service); - details.service = pointer; + QSharedPointer<QLowEnergyServicePrivate> pointer(priv); - serviceList.insert(uuid, details); + serviceList.insert(uuid, pointer); emit q->serviceDiscovered(uuid); } diff --git a/src/bluetooth/qlowenergycontrollernew_p.h b/src/bluetooth/qlowenergycontrollernew_p.h index b5a66aeb..0efb0817 100644 --- a/src/bluetooth/qlowenergycontrollernew_p.h +++ b/src/bluetooth/qlowenergycontrollernew_p.h @@ -45,6 +45,7 @@ #include <qglobal.h> #include <QtBluetooth/qbluetooth.h> #include "qlowenergycontrollernew.h" +#include "qlowenergyserviceprivate_p.h" #if defined(QT_BLUEZ_BLUETOOTH) && !defined(QT_BLUEZ_NO_BTLE) #include <QtBluetooth/QBluetoothSocket> @@ -52,12 +53,7 @@ QT_BEGIN_NAMESPACE -typedef QPair<QLowEnergyHandle,QLowEnergyHandle> HandlePair; - -struct ServiceDetails { - QLowEnergyHandle startHandle, endHandle; - QSharedPointer<QLowEnergyService> service; -}; +typedef QMap<QBluetoothUuid, QSharedPointer<QLowEnergyServicePrivate> > ServiceDataMap; class QLowEnergyControllerNewPrivate : public QObject { @@ -96,7 +92,7 @@ public: private: // list of all found service uuids - QMap<QBluetoothUuid, ServiceDetails> serviceList; + ServiceDataMap serviceList; #if defined(QT_BLUEZ_BLUETOOTH) && !defined(QT_BLUEZ_NO_BTLE) QBluetoothSocket *l2cpSocket; diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 0e25c9b3..2a7f4b4c 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -45,19 +45,10 @@ #include <QtBluetooth/QLowEnergyCharacteristicInfo> #include "qlowenergycontrollernew_p.h" +#include "qlowenergyserviceprivate_p.h" QT_BEGIN_NAMESPACE -class QLowEnergyServicePrivate { -public: - QBluetoothUuid uuid; - QLowEnergyService::ServiceType type; - QLowEnergyService::ServiceState state; - QLowEnergyService::ServiceError lastError; - - QPointer<QLowEnergyControllerNewPrivate> controller; -}; - /*! \internal @@ -65,54 +56,20 @@ public: The user gets access to class instances via \l QLowEnergyControllerNew::services(). */ -QLowEnergyService::QLowEnergyService(const QBluetoothUuid &uuid, +QLowEnergyService::QLowEnergyService(QSharedPointer<QLowEnergyServicePrivate> p, QObject *parent) - : QObject(parent) -{ - d_ptr = new QLowEnergyServicePrivate(); - d_ptr->uuid = uuid; - d_ptr->state = QLowEnergyService::InvalidService; - d_ptr->type = QLowEnergyService::PrimaryService; - d_ptr->lastError = QLowEnergyService::NoError; -} - -/*! - \internal - - Called by Controller right after construction. - */ -void QLowEnergyService::setController(QLowEnergyControllerNewPrivate *control) -{ - Q_D(QLowEnergyService); - if (!control) - return; - - d->state = QLowEnergyService::DiscoveryRequired; - d->controller = control; -} - -/*! - \internal - - Called by Controller. - */ -void QLowEnergyService::setError(QLowEnergyService::ServiceError newError) + : QObject(parent), + d_ptr(p) { - Q_D(QLowEnergyService); - d->lastError = newError; - emit error(newError); + connect(p.data(), SIGNAL(error(QLowEnergyService::ServiceError)), + this, SIGNAL(error(QLowEnergyService::ServiceError))); + connect(p.data(), SIGNAL(stateChanged(QLowEnergyService::ServiceState)), + this, SIGNAL(stateChanged(QLowEnergyService::ServiceState))); } -void QLowEnergyService::setState(QLowEnergyService::ServiceState newState) -{ - Q_D(QLowEnergyService); - d->state = newState; - emit stateChanged(newState); -} QLowEnergyService::~QLowEnergyService() { - delete d_ptr; } QList<QSharedPointer<QLowEnergyService> > QLowEnergyService::includedServices() const @@ -170,7 +127,7 @@ void QLowEnergyService::discoverDetails() return; if (!d->controller) { - setError(QLowEnergyService::ServiceNotValidError); + d->setError(QLowEnergyService::ServiceNotValidError); return; } diff --git a/src/bluetooth/qlowenergyservice.h b/src/bluetooth/qlowenergyservice.h index 03505e30..4ea1dabb 100644 --- a/src/bluetooth/qlowenergyservice.h +++ b/src/bluetooth/qlowenergyservice.h @@ -95,17 +95,13 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QLowEnergyService) - QLowEnergyServicePrivate *d_ptr; + QSharedPointer<QLowEnergyServicePrivate> d_ptr; - // the symbols below are used by QLowEnergyControllerNewPrivate - // TODO check whether there are other ways of accessing the internals - friend class QLowEnergyControllerNewPrivate; - - QLowEnergyService(const QBluetoothUuid &uuid, + // QLowEnergyControllerNewPrivate is the factory for this class + friend class QLowEnergyControllerNew; + QLowEnergyService(QSharedPointer<QLowEnergyServicePrivate> p, QObject *parent = 0); - void setController(QLowEnergyControllerNewPrivate* control); - void setError(QLowEnergyService::ServiceError newError); - void setState(QLowEnergyService::ServiceState newState); + }; QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergyserviceprivate.cpp b/src/bluetooth/qlowenergyserviceprivate.cpp new file mode 100644 index 00000000..138caa2b --- /dev/null +++ b/src/bluetooth/qlowenergyserviceprivate.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qlowenergyserviceprivate_p.h" + +QLowEnergyServicePrivate::QLowEnergyServicePrivate(QObject *parent) : + QObject(parent), + type(QLowEnergyService::PrimaryService), + state(QLowEnergyService::InvalidService), + lastError(QLowEnergyService::NoError) +{ +} + +QLowEnergyServicePrivate::~QLowEnergyServicePrivate() +{ +} + +void QLowEnergyServicePrivate::setController(QLowEnergyControllerNewPrivate *control) +{ + if (!control) + return; + + state = QLowEnergyService::DiscoveryRequired; + controller = control; +} + +void QLowEnergyServicePrivate::setError(QLowEnergyService::ServiceError newError) +{ + lastError = newError; + emit error(newError); +} + +void QLowEnergyServicePrivate::setState(QLowEnergyService::ServiceState newState) +{ + state = newState; + emit stateChanged(newState); +} diff --git a/src/bluetooth/qlowenergyserviceprivate_p.h b/src/bluetooth/qlowenergyserviceprivate_p.h new file mode 100644 index 00000000..538cd49d --- /dev/null +++ b/src/bluetooth/qlowenergyserviceprivate_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QLOWENERGYSERVICEPRIVATE_P_H +#define QLOWENERGYSERVICEPRIVATE_P_H + +#include <QtCore/QObject> +#include <QtCore/QPointer> +#include <QtBluetooth/qbluetooth.h> +#include <QtBluetooth/QLowEnergyService> + +#include "qlowenergycontrollernew_p.h" + +class QLowEnergyServicePrivate : public QObject +{ + Q_OBJECT +public: + explicit QLowEnergyServicePrivate(QObject *parent = 0); + ~QLowEnergyServicePrivate(); + + void setController(QLowEnergyControllerNewPrivate* control); + void setError(QLowEnergyService::ServiceError newError); + void setState(QLowEnergyService::ServiceState newState); + +signals: + void stateChanged(QLowEnergyService::ServiceState newState); + void error(QLowEnergyService::ServiceError error); + +public slots: + +public: + QLowEnergyHandle startHandle; + QLowEnergyHandle endHandle; + + QBluetoothUuid uuid; + QLowEnergyService::ServiceType type; + QLowEnergyService::ServiceState state; + QLowEnergyService::ServiceError lastError; + + QPointer<QLowEnergyControllerNewPrivate> controller; +}; + +#endif // QLOWENERGYSERVICEPRIVATE_P_H |