summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp11
7 files changed, 58 insertions, 29 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;
diff --git a/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp b/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp
index e53523a1..e10d248e 100644
--- a/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp
+++ b/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp
@@ -96,7 +96,10 @@ void tst_QLowEnergyDescriptorInfo::tst_construction()
QCOMPARE(descriptorInfo.uuid(), QBluetoothUuid());
QCOMPARE(descriptorInfo.value(), QByteArray());
QCOMPARE(descriptorInfo.handle(), QString("0x0000"));
- QCOMPARE(descriptorInfo.name(), QString(""));
+ QCOMPARE(descriptorInfo.name(),
+ QBluetoothUuid::descriptorToString(descriptorInfo.type()));
+ QCOMPARE(descriptorInfo.type(),
+ QBluetoothUuid::ClientCharacteristicConfiguration);
}
{
@@ -106,7 +109,8 @@ void tst_QLowEnergyDescriptorInfo::tst_construction()
QLowEnergyDescriptorInfo copyInfo = descriptorInfo;
QCOMPARE(copyInfo.uuid().toString(), descriptorUuid.toString());
- QCOMPARE(copyInfo.name(), QString(""));
+ QCOMPARE(copyInfo.name(),
+ QBluetoothUuid::descriptorToString(copyInfo.type()));
copyInfo.setValue(QByteArray("test"));
QCOMPARE(copyInfo.value(), QByteArray("test"));
@@ -121,7 +125,8 @@ void tst_QLowEnergyDescriptorInfo::tst_construction()
QCOMPARE(copyInfo.uuid(), alternateDescriptorUuid);
QCOMPARE(copyInfo.value(), QByteArray());
QCOMPARE(copyInfo.handle(), QString("0x0000"));
- QCOMPARE(copyInfo.name(), QString(""));
+ QCOMPARE(copyInfo.name(),
+ QBluetoothUuid::descriptorToString(copyInfo.type()));
}
}