summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycharacteristic.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-07-10 15:47:41 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-07-16 08:28:46 +0200
commitf399837b3a723af9add6d9ea2d2e988f64f76ae0 (patch)
tree2c2a17ff5c4cfd007af98c98c70a2bf8c5fe8984 /src/bluetooth/qlowenergycharacteristic.cpp
parent8bf7e9986e359df46bb351dfb76e4140d9b04da7 (diff)
Add simpler API to retrieve descriptor/characteristic for certain uuid
This new API is mostly syntactic sugar and reduces the amount of code to be written by API users. Change-Id: I51ff1ea706ac97199646d211e39e79c8140ee74b Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'src/bluetooth/qlowenergycharacteristic.cpp')
-rw-r--r--src/bluetooth/qlowenergycharacteristic.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp
index d1c1a14c..bba5b7a0 100644
--- a/src/bluetooth/qlowenergycharacteristic.cpp
+++ b/src/bluetooth/qlowenergycharacteristic.cpp
@@ -275,8 +275,33 @@ QLowEnergyHandle QLowEnergyCharacteristic::attributeHandle() const
return data->handle;
}
+
+/*!
+ Returns the descriptor with \a uuid; otherwise an invalid \c QLowEnergyDescriptor
+ instance.
+
+ \sa descriptors()
+*/
+QLowEnergyDescriptor QLowEnergyCharacteristic::descriptor(const QBluetoothUuid &uuid) const
+{
+ if (d_ptr.isNull() || !data)
+ return QLowEnergyDescriptor();
+
+ QList<QLowEnergyHandle> descriptorKeys = d_ptr->characteristicList[data->handle].
+ descriptorList.keys();
+ foreach (const QLowEnergyHandle descHandle, descriptorKeys) {
+ if (uuid == d_ptr->characteristicList[data->handle].descriptorList[descHandle].uuid)
+ return QLowEnergyDescriptor(d_ptr, data->handle, descHandle);
+ }
+
+ return QLowEnergyDescriptor();
+}
+
/*!
- Returns the list of characteristic descriptors.
+ Returns the list of descriptors belonging to this characteristic; otherwise
+ an empty list.
+
+ \sa descriptor()
*/
QList<QLowEnergyDescriptor> QLowEnergyCharacteristic::descriptors() const
{
@@ -291,7 +316,7 @@ QList<QLowEnergyDescriptor> QLowEnergyCharacteristic::descriptors() const
std::sort(descriptorKeys.begin(), descriptorKeys.end());
- foreach (QLowEnergyHandle descHandle, descriptorKeys) {
+ foreach (const QLowEnergyHandle descHandle, descriptorKeys) {
QLowEnergyDescriptor descriptor(d_ptr, data->handle, descHandle);
result.append(descriptor);
}