summaryrefslogtreecommitdiffstats
path: root/src/bluetooth
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-06-04 15:01:30 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-11 12:03:22 +0200
commit1a9a359b9bdee646cd964fd5af13b239da79f9c9 (patch)
treec69d6c1fe6389a44856284ceaeacd05bab9b41ed /src/bluetooth
parent516bc395a69f5dbe965c1e1da8580b5a6c38779f (diff)
Provide means of translating descriptor types to user strings
Also, this patch fixes the uninitialised m_type member in the QLowEnergyDescriptorInfo private implementation Change-Id: I6736d5f38738490bc4f0f53908f925361f1843bd Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r--src/bluetooth/qbluetoothuuid.cpp38
-rw-r--r--src/bluetooth/qbluetoothuuid.h1
-rw-r--r--src/bluetooth/qlowenergycharacteristicinfo.cpp2
-rw-r--r--src/bluetooth/qlowenergydescriptorinfo.cpp32
-rw-r--r--src/bluetooth/qlowenergydescriptorinfo.h2
-rw-r--r--src/bluetooth/qlowenergydescriptorinfo_p.h1
6 files changed, 50 insertions, 26 deletions
diff --git a/src/bluetooth/qbluetoothuuid.cpp b/src/bluetooth/qbluetoothuuid.cpp
index 3c112775..b68e6e1f 100644
--- a/src/bluetooth/qbluetoothuuid.cpp
+++ b/src/bluetooth/qbluetoothuuid.cpp
@@ -754,7 +754,7 @@ QString QBluetoothUuid::protocolToString(QBluetoothUuid::ProtocolUuid uuid)
}
/*!
- Returns a human-readable and translated name for the given characteristic
+ Returns a human-readable and translated name for the given characteristic type
represented by \a uuid.
\sa QBluetoothUuid::CharacteristicType
@@ -873,6 +873,42 @@ QString QBluetoothUuid::characteristicToString(CharacteristicType uuid)
}
/*!
+ Returns a human-readable and translated name for the given descriptor type
+ represented by \a uuid.
+
+ \sa QBluetoothUuid::CharacteristicType
+
+ \since 5.4
+*/
+QString QBluetoothUuid::descriptorToString(QBluetoothUuid::DescriptorType uuid)
+{
+ switch (uuid) {
+ case QBluetoothUuid::CharacteristicExtendedProperties:
+ return QBluetoothServiceDiscoveryAgent::tr("Characteristic Extended Properties");
+ case QBluetoothUuid::CharacteristicUserDescription:
+ return QBluetoothServiceDiscoveryAgent::tr("Characteristic User Description");
+ case QBluetoothUuid::ClientCharacteristicConfiguration:
+ return QBluetoothServiceDiscoveryAgent::tr("Client Characteristic Configuration");
+ case QBluetoothUuid::ServerCharacteristicConfiguration:
+ return QBluetoothServiceDiscoveryAgent::tr("Server Characteristic Configuratio");
+ case QBluetoothUuid::CharacteristicPresentationFormat:
+ return QBluetoothServiceDiscoveryAgent::tr("Characteristic Presentation Format");
+ case QBluetoothUuid::CharacteristicAggregateFormat:
+ return QBluetoothServiceDiscoveryAgent::tr("Characteristic Aggregate Format");
+ case QBluetoothUuid::ValidRange:
+ return QBluetoothServiceDiscoveryAgent::tr("Valid Range");
+ case QBluetoothUuid::ExternalReportReference:
+ return QBluetoothServiceDiscoveryAgent::tr("External Report Reference");
+ case QBluetoothUuid::ReportReference:
+ return QBluetoothServiceDiscoveryAgent::tr("Report Reference");
+ default:
+ break;
+ }
+
+ return QString();
+}
+
+/*!
Returns true if \a other is equal to this Bluetooth UUID, otherwise false.
*/
bool QBluetoothUuid::operator==(const QBluetoothUuid &other) const
diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h
index c5f9224c..66be1b18 100644
--- a/src/bluetooth/qbluetoothuuid.h
+++ b/src/bluetooth/qbluetoothuuid.h
@@ -296,6 +296,7 @@ public:
static QString serviceClassToString(ServiceClassUuid uuid);
static QString protocolToString(ProtocolUuid uuid);
static QString characteristicToString(CharacteristicType uuid);
+ static QString descriptorToString(DescriptorType uuid);
};
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/bluetooth/qlowenergycharacteristicinfo.cpp b/src/bluetooth/qlowenergycharacteristicinfo.cpp
index aea4be5e..0d2f8c81 100644
--- a/src/bluetooth/qlowenergycharacteristicinfo.cpp
+++ b/src/bluetooth/qlowenergycharacteristicinfo.cpp
@@ -118,7 +118,7 @@ QLowEnergyCharacteristicInfo::~QLowEnergyCharacteristicInfo()
}
/*!
- Returns the name of the gatt characteristic.
+ Returns the name of the gatt characteristic type.
*/
QString QLowEnergyCharacteristicInfo::name() const
{
diff --git a/src/bluetooth/qlowenergydescriptorinfo.cpp b/src/bluetooth/qlowenergydescriptorinfo.cpp
index b71d7b4b..430220fc 100644
--- a/src/bluetooth/qlowenergydescriptorinfo.cpp
+++ b/src/bluetooth/qlowenergydescriptorinfo.cpp
@@ -58,26 +58,9 @@ QT_BEGIN_NAMESPACE
about the characteristic (data format, notification activation, etc).
*/
-QString parseDescriptorUuid(const QBluetoothUuid &uuid)
-{
- static QHash<int, QString> uuidnames;
- if ( uuidnames.isEmpty() ) {
- uuidnames[0x2905] = QStringLiteral("Characteristic Aggregate Format");
- uuidnames[0x2900] = QStringLiteral("Characteristic Extended Properties");
- uuidnames[0x2904] = QStringLiteral("Characteristic Presentation Format");
- uuidnames[0x2901] = QStringLiteral("Characteristic User Description");
- uuidnames[0x2902] = QStringLiteral("Client Characteristic Configuration");
- uuidnames[0x2907] = QStringLiteral("External Report Reference");
- uuidnames[0x2908] = QStringLiteral("Report Reference");
- uuidnames[0x2903] = QStringLiteral("Server Characteristic Configuration");
- uuidnames[0x2906] = QStringLiteral("Valid Range");
- }
- QString name = uuidnames.value(uuid.toUInt16(), QStringLiteral("Unknow Descriptor"));
- return name;
-}
-
QLowEnergyDescriptorInfoPrivate::QLowEnergyDescriptorInfoPrivate(const QBluetoothUuid &uuid, const QString &handle)
- : m_uuid(uuid), m_handle(handle)
+ : m_uuid(uuid), m_handle(handle),
+ m_type(QBluetoothUuid::ClientCharacteristicConfiguration) //by default a notification
{
#ifdef QT_QNX_BLUETOOTH
instance = -1;
@@ -95,7 +78,6 @@ QLowEnergyDescriptorInfoPrivate::~QLowEnergyDescriptorInfoPrivate()
QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid):
d_ptr(new QLowEnergyDescriptorInfoPrivate(uuid, QStringLiteral("0x0000")))
{
-
}
/*!
@@ -109,7 +91,6 @@ QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid,
d_ptr(new QLowEnergyDescriptorInfoPrivate(uuid, handle))
{
d_ptr->m_type = type;
- d_ptr->m_name = parseDescriptorUuid(uuid);
}
/*!
@@ -157,11 +138,16 @@ QByteArray QLowEnergyDescriptorInfo::value() const
}
/*!
- Returns the name of the descriptor.
+ Returns the name of the descriptor type.
+
+ \sa type()
*/
+//TODO check that we really need this function. The static
+// QBluetoothUuid::descriptorToString should actually be sufficient.
QString QLowEnergyDescriptorInfo::name() const
{
- return d_ptr->m_name;
+ return QBluetoothUuid::descriptorToString(
+ static_cast<QBluetoothUuid::DescriptorType>(d_ptr->m_type));
}
/*!
diff --git a/src/bluetooth/qlowenergydescriptorinfo.h b/src/bluetooth/qlowenergydescriptorinfo.h
index 64233776..f54e3662 100644
--- a/src/bluetooth/qlowenergydescriptorinfo.h
+++ b/src/bluetooth/qlowenergydescriptorinfo.h
@@ -57,6 +57,8 @@ class Q_BLUETOOTH_EXPORT QLowEnergyDescriptorInfo
{
friend class QLowEnergyControllerPrivate;
public:
+ //TODO - add QLowEnergyDescriptorInfo() <- for invalid descriptor object
+ // - remove QLowEnergyDescriptorInfo(QBluetoothUuid) <- not really needed
explicit QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid);
~QLowEnergyDescriptorInfo();
diff --git a/src/bluetooth/qlowenergydescriptorinfo_p.h b/src/bluetooth/qlowenergydescriptorinfo_p.h
index fb177dfe..3ec1cb26 100644
--- a/src/bluetooth/qlowenergydescriptorinfo_p.h
+++ b/src/bluetooth/qlowenergydescriptorinfo_p.h
@@ -55,7 +55,6 @@ public:
QByteArray m_value;
QBluetoothUuid m_uuid;
QString m_handle;
- QString m_name;
QBluetoothUuid::DescriptorType m_type;
#ifdef QT_QNX_BLUETOOTH
int instance;