diff options
Diffstat (limited to 'src/bluetooth/qlowenergycharacteristic.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycharacteristic.cpp | 29 |
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); } |