summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-06-24 15:08:44 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-06-26 16:36:32 +0200
commit004491a61de53d128aade26d497dcf7a557e09c4 (patch)
tree6ec3a63f748c4e75bd856f458fc508dcab4e8c0b /src
parentb9909f15e8760e1587f67d9ff028bf730a92d044 (diff)
Introduce QLowEnergyDescriptor
The class is based in QLowEnergyDescriptorInfo and exposes the found descriptor information. The only missing piece of information is the descriptor value. Extends the QLowEnergyController unit test in such a way that descriptor information is tested too (except for values). Change-Id: I6ba6a862fff48fbdd27cd8219d2eb8f6d0058aea Reviewed-by: Fabian Bumberger <fbumberger@rim.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/bluetooth.pro2
-rw-r--r--src/bluetooth/qbluetoothuuid.h1
-rw-r--r--src/bluetooth/qlowenergycharacteristic.cpp34
-rw-r--r--src/bluetooth/qlowenergycharacteristic.h4
-rw-r--r--src/bluetooth/qlowenergycontrollernew_bluez.cpp15
-rw-r--r--src/bluetooth/qlowenergydescriptor.cpp254
-rw-r--r--src/bluetooth/qlowenergydescriptor.h91
-rw-r--r--src/bluetooth/qlowenergyservice.h2
-rw-r--r--src/bluetooth/qlowenergyserviceprivate_p.h7
9 files changed, 392 insertions, 18 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 6405ad02..6b015229 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -28,6 +28,7 @@ PUBLIC_HEADERS += \
qlowenergycharacteristicinfo.h \
qlowenergycharacteristic.h \
qlowenergydescriptorinfo.h \
+ qlowenergydescriptor.h \
qbluetoothtransferreply.h \
qlowenergycontroller.h \
qlowenergycontrollernew.h
@@ -73,6 +74,7 @@ SOURCES += \
qlowenergycharacteristicinfo.cpp \
qlowenergycharacteristic.cpp \
qlowenergydescriptorinfo.cpp \
+ qlowenergydescriptor.cpp \
qlowenergycontroller.cpp \
qlowenergycontrollernew.cpp \
qlowenergyserviceprivate.cpp
diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h
index 66be1b18..274e98ab 100644
--- a/src/bluetooth/qbluetoothuuid.h
+++ b/src/bluetooth/qbluetoothuuid.h
@@ -261,6 +261,7 @@ public:
};
enum DescriptorType {
+ UnknownDescriptorType = 0x0,
CharacteristicExtendedProperties = 0x2900,
CharacteristicUserDescription = 0x2901,
ClientCharacteristicConfiguration = 0x2902,
diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp
index 10136c10..f74aa808 100644
--- a/src/bluetooth/qlowenergycharacteristic.cpp
+++ b/src/bluetooth/qlowenergycharacteristic.cpp
@@ -219,9 +219,16 @@ QLowEnergyCharacteristic &QLowEnergyCharacteristic::operator=(const QLowEnergyCh
}
/*!
- Returns true if the QLowEnergyCharacteristic object is valid, otherwise returns false.
- If it returns \c false, it means that this instance is not associated to any service
- or the associated service is no longer valid.
+ Returns \c true if the QLowEnergyCharacteristic object is valid, otherwise returns \c false.
+
+ An invalid characteristic object is not associated to any service
+ or the associated service is no longer valid due to for example a disconnect from
+ the underlying Bluetooth Low Energy device. Once the object is invalid
+ it cannot become valid anymore.
+
+ \note If a QLowEnergyCharacteristic instance turns invalid due to a disconnect
+ from the underlying device, the information encapsulated by the current
+ instance remains as it was at the time of the disconnect.
*/
bool QLowEnergyCharacteristic::isValid() const
{
@@ -239,12 +246,25 @@ bool QLowEnergyCharacteristic::isValid() const
/*!
Returns the list of characteristic descriptors.
*/
-QList<QLowEnergyDescriptorInfo> QLowEnergyCharacteristic::descriptors() const
+QList<QLowEnergyDescriptor> QLowEnergyCharacteristic::descriptors() const
{
- // TODO QLowEnergyCharacteristic::descriptors()
- QList<QLowEnergyDescriptorInfo> result;
- return result;
+ QList<QLowEnergyDescriptor> result;
+
+ if (d_ptr.isNull() || !data
+ || !d_ptr->characteristicList.contains(data->handle))
+ return result;
+ QList<QLowEnergyHandle> descriptorKeys = d_ptr->characteristicList[data->handle].
+ descriptorList.keys();
+
+ std::sort(descriptorKeys.begin(), descriptorKeys.end());
+
+ foreach (QLowEnergyHandle descHandle, descriptorKeys) {
+ QLowEnergyDescriptor descriptor(d_ptr, data->handle, descHandle);
+ result.append(descriptor);
+ }
+
+ return result;
}
QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycharacteristic.h b/src/bluetooth/qlowenergycharacteristic.h
index 6454ef67..4478b910 100644
--- a/src/bluetooth/qlowenergycharacteristic.h
+++ b/src/bluetooth/qlowenergycharacteristic.h
@@ -46,7 +46,7 @@
#include <QtCore/QObject>
#include <QtBluetooth/qbluetooth.h>
#include <QtBluetooth/QBluetoothUuid>
-#include <QtBluetooth/QLowEnergyDescriptorInfo>
+#include <QtBluetooth/QLowEnergyDescriptor>
QT_BEGIN_NAMESPACE
@@ -86,7 +86,7 @@ public:
QLowEnergyCharacteristic::PropertyTypes properties() const;
QLowEnergyHandle handle() const;
- QList<QLowEnergyDescriptorInfo> descriptors() const;
+ QList<QLowEnergyDescriptor> descriptors() const;
bool isValid() const;
diff --git a/src/bluetooth/qlowenergycontrollernew_bluez.cpp b/src/bluetooth/qlowenergycontrollernew_bluez.cpp
index 4e5f5270..3ddbfd5c 100644
--- a/src/bluetooth/qlowenergycontrollernew_bluez.cpp
+++ b/src/bluetooth/qlowenergycontrollernew_bluez.cpp
@@ -420,11 +420,6 @@ void QLowEnergyControllerNewPrivate::processReply(
* The uuid can be 16 or 128 bit which is indicated by format.
*/
- if (isErrorResponse) {
- //TODO handle error
- break;
- }
-
QList<QLowEnergyHandle> keys = request.reference.value<QList<QLowEnergyHandle> >();
if (keys.isEmpty()) {
qCWarning(QT_BT_BLUEZ) << "Descriptor discovery for unknown characteristic received";
@@ -436,6 +431,10 @@ void QLowEnergyControllerNewPrivate::processReply(
serviceForHandle(charHandle);
Q_ASSERT(!p.isNull());
+ if (isErrorResponse) {
+ p->setState(QLowEnergyService::ServiceDiscovered);
+ break;
+ }
const quint8 format = response[1];
quint16 elementLength;
@@ -479,12 +478,14 @@ void QLowEnergyControllerNewPrivate::processReply(
if (descriptorHandle == p->characteristicList[charHandle].valueHandle)
continue;
+ QLowEnergyServicePrivate::DescData data;
+ data.uuid = uuid;
p->characteristicList[charHandle].descriptorList.insert(
- descriptorHandle, uuid);
+ descriptorHandle, data);
qCDebug(QT_BT_BLUEZ) << "Descriptor found, uuid:"
<< uuid.toString()
- << "descriptor handle:" << descriptorHandle;
+ << "descriptor handle:" << hex << descriptorHandle;
}
QLowEnergyHandle nextBorderHandle = 0;
diff --git a/src/bluetooth/qlowenergydescriptor.cpp b/src/bluetooth/qlowenergydescriptor.cpp
new file mode 100644
index 00000000..5987d91d
--- /dev/null
+++ b/src/bluetooth/qlowenergydescriptor.cpp
@@ -0,0 +1,254 @@
+/***************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** 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 <QtBluetooth/QLowEnergyService>
+#include "qlowenergyserviceprivate_p.h"
+#include "qlowenergydescriptor.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QLowEnergyDescriptor
+ \inmodule QtBluetooth
+ \brief The QLowEnergyDescriptor class stores information about the Bluetooth
+ Low Energy descriptor.
+ \since 5.4
+
+ QLowEnergyDescriptor provides information about a Bluetooth Low Energy
+ descriptor's name, UUID, value and handle. Descriptors are contained in the
+ Bluetooth Low Energy characteristic and they provide additional information
+ about the characteristic (data format, notification activation, etc).
+*/
+
+struct QLowEnergyDescriptorPrivate
+{
+ QLowEnergyHandle charHandle;
+ QLowEnergyHandle descHandle;
+};
+
+/*!
+ Destroys the QLowEnergyDescriptor object.
+*/
+QLowEnergyDescriptor::QLowEnergyDescriptor():
+ d_ptr(0), data(0)
+{
+}
+
+/*!
+ Construct a new QLowEnergyDesxcriptor that is a copy of \a other.
+
+ The two copies continue to share the same underlying data which does not detach
+ upon write.
+*/
+QLowEnergyDescriptor::QLowEnergyDescriptor(const QLowEnergyDescriptor &other):
+ d_ptr(other.d_ptr), data(0)
+{
+ if (other.data) {
+ data = new QLowEnergyDescriptorPrivate();
+ data->charHandle = other.data->charHandle;
+ data->descHandle = other.data->descHandle;
+ }
+}
+
+/*!
+ \internal
+
+*/
+QLowEnergyDescriptor::QLowEnergyDescriptor(QSharedPointer<QLowEnergyServicePrivate> p,
+ QLowEnergyHandle charHandle,
+ QLowEnergyHandle descHandle):
+ d_ptr(p)
+{
+ data = new QLowEnergyDescriptorPrivate();
+ data->charHandle = charHandle;
+ data->descHandle = descHandle;
+
+}
+
+/*!
+ Destroys the QLowEnergyDescriptor object.
+*/
+QLowEnergyDescriptor::~QLowEnergyDescriptor()
+{
+ delete data;
+}
+
+/*!
+ Makes a copy of \a other and assigns it to this QLowEnergyDescriptor object.
+ The two copies continue to share the same service and registration details.
+*/
+QLowEnergyDescriptor &QLowEnergyDescriptor::operator=(const QLowEnergyDescriptor &other)
+{
+ d_ptr = other.d_ptr;
+
+ if (!other.data) {
+ if (data) {
+ delete data;
+ data = 0;
+ }
+ } else {
+ if (!data)
+ data = new QLowEnergyDescriptorPrivate();
+
+ data->charHandle = other.data->charHandle;
+ data->descHandle = other.data->descHandle;
+ }
+
+ return *this;
+}
+
+/*!
+ Returns \c true if the QLowEnergyDescriptor object is valid, otherwise returns \c false.
+
+ An invalid descriptor instance is not associated to any service
+ or the associated service is no longer valid due to for example a disconnect from
+ the underlying Bluetooth Low Energy device. Once the object is invalid
+ it cannot become valid anymore.
+
+ \note If a QLowEnergyDescriptor instance turns invalid due to a disconnect
+ from the underlying device, the information encapsulated by the current
+ instance remains as it was at the time of the disconnect.
+*/
+bool QLowEnergyDescriptor::isValid() const
+{
+ if (d_ptr.isNull() || !data)
+ return false;
+
+ if (d_ptr->state == QLowEnergyService::InvalidService)
+ return false;
+
+ return true;
+}
+
+/*!
+ Returns the UUID of this descriptor.
+*/
+QBluetoothUuid QLowEnergyDescriptor::uuid() const
+{
+ if (d_ptr.isNull() || !data
+ || !d_ptr->characteristicList.contains(data->charHandle)
+ || !d_ptr->characteristicList[data->charHandle].
+ descriptorList.contains(data->descHandle))
+ return QBluetoothUuid::UnknownDescriptorType;
+
+ return d_ptr->characteristicList[data->charHandle].descriptorList[data->descHandle].uuid;
+}
+
+/*!
+ Returns the handle of the descriptor.
+*/
+QLowEnergyHandle QLowEnergyDescriptor::handle() const
+{
+ if (!data)
+ return 0;
+
+ return data->descHandle;
+}
+
+/*!
+ Returns the value of the descriptor.
+*/
+QByteArray QLowEnergyDescriptor::value() const
+{
+ if (d_ptr.isNull() || !data
+ || !d_ptr->characteristicList.contains(data->charHandle)
+ || !d_ptr->characteristicList[data->charHandle].
+ descriptorList.contains(data->descHandle))
+ return QByteArray();
+
+ return d_ptr->characteristicList[data->charHandle].descriptorList[data->descHandle].value;
+}
+
+/*!
+ Returns the name of the descriptor type.
+
+ \sa type()
+*/
+
+QString QLowEnergyDescriptor::name() const
+{
+ return QBluetoothUuid::descriptorToString(type());
+}
+
+/*!
+ Returns the type of descriptor.
+ */
+QBluetoothUuid::DescriptorType QLowEnergyDescriptor::type() const
+{
+ const QBluetoothUuid u = uuid();
+ bool ok = false;
+ quint16 shortUuid = u.toUInt16(&ok);
+
+ if (!ok)
+ return QBluetoothUuid::UnknownDescriptorType;
+
+ switch (shortUuid) {
+ case QBluetoothUuid::CharacteristicExtendedProperties:
+ case QBluetoothUuid::CharacteristicUserDescription:
+ case QBluetoothUuid::ClientCharacteristicConfiguration:
+ case QBluetoothUuid::ServerCharacteristicConfiguration:
+ case QBluetoothUuid::CharacteristicPresentationFormat:
+ case QBluetoothUuid::CharacteristicAggregateFormat:
+ case QBluetoothUuid::ValidRange:
+ case QBluetoothUuid::ExternalReportReference:
+ case QBluetoothUuid::ReportReference:
+ return (QBluetoothUuid::DescriptorType) shortUuid;
+ default:
+ break;
+ }
+
+ return QBluetoothUuid::UnknownDescriptorType;
+}
+
+/*!
+ Sets the value \a value of the descriptor. This only caches the value. To write
+ a value directly to the device QLowEnergyController class must be used.
+
+ \sa QLowEnergyController::writeDescriptor()
+*/
+void QLowEnergyDescriptor::setValue(const QByteArray &value)
+{
+ //TODO
+ //d_ptr->m_value = value;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergydescriptor.h b/src/bluetooth/qlowenergydescriptor.h
new file mode 100644
index 00000000..a3da83c4
--- /dev/null
+++ b/src/bluetooth/qlowenergydescriptor.h
@@ -0,0 +1,91 @@
+/***************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** 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 QLOWENERGYDESCRIPTOR_H
+#define QLOWENERGYDESCRIPTOR_H
+
+#include <QtCore/QSharedPointer>
+#include <QtCore/QVariantMap>
+#include <QtBluetooth/qbluetooth.h>
+#include <QtBluetooth/QBluetoothUuid>
+
+QT_BEGIN_NAMESPACE
+
+class QLowEnergyDescriptorPrivate;
+class QLowEnergyServicePrivate;
+
+//TODO rename to QLowEnergyDescriptor
+class Q_BLUETOOTH_EXPORT QLowEnergyDescriptor
+{
+ friend class QLowEnergyControllerPrivate;
+public:
+ QLowEnergyDescriptor();
+ QLowEnergyDescriptor(const QLowEnergyDescriptor &other);
+ ~QLowEnergyDescriptor();
+
+ QLowEnergyDescriptor &operator=(const QLowEnergyDescriptor &other);
+
+ bool isValid() const;
+
+ QByteArray value() const;
+ void setValue(const QByteArray &value); //TODO shift to QLowEnergyControllerNew
+
+ QBluetoothUuid uuid() const;
+ QLowEnergyHandle handle() const;
+ QString name() const;
+
+ QBluetoothUuid::DescriptorType type() const;
+
+protected:
+ QSharedPointer<QLowEnergyServicePrivate> d_ptr;
+
+ friend class QLowEnergyCharacteristic;
+ QLowEnergyDescriptorPrivate *data;
+
+ QLowEnergyDescriptor(QSharedPointer<QLowEnergyServicePrivate> p,
+ QLowEnergyHandle charHandle,
+ QLowEnergyHandle descHandle);
+};
+
+QT_END_NAMESPACE
+
+#endif // QLOWENERGYDESCRIPTOR_H
diff --git a/src/bluetooth/qlowenergyservice.h b/src/bluetooth/qlowenergyservice.h
index c2ecc6b0..9c53aea7 100644
--- a/src/bluetooth/qlowenergyservice.h
+++ b/src/bluetooth/qlowenergyservice.h
@@ -90,7 +90,7 @@ Q_SIGNALS:
void stateChanged(QLowEnergyService::ServiceState newState);
void characteristicChanged(const QLowEnergyCharacteristic &info,
const QByteArray &value);
- void descriptorChanged(const QLowEnergyDescriptorInfo &info,
+ void descriptorChanged(const QLowEnergyDescriptor &info,
const QByteArray &value);
void error(QLowEnergyService::ServiceError error);
diff --git a/src/bluetooth/qlowenergyserviceprivate_p.h b/src/bluetooth/qlowenergyserviceprivate_p.h
index 16b1ea31..72caeeac 100644
--- a/src/bluetooth/qlowenergyserviceprivate_p.h
+++ b/src/bluetooth/qlowenergyserviceprivate_p.h
@@ -59,12 +59,17 @@ public:
explicit QLowEnergyServicePrivate(QObject *parent = 0);
~QLowEnergyServicePrivate();
+ struct DescData {
+ QByteArray value;
+ QBluetoothUuid uuid;
+ };
+
struct CharData {
QLowEnergyHandle valueHandle;
QBluetoothUuid uuid;
QLowEnergyCharacteristic::PropertyTypes properties;
QByteArray value;
- QHash<QLowEnergyHandle, QBluetoothUuid> descriptorList;
+ QHash<QLowEnergyHandle, DescData> descriptorList;
};
enum GattAttributeTypes {