From f399837b3a723af9add6d9ea2d2e988f64f76ae0 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 10 Jul 2014 15:47:41 +0200 Subject: 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 --- src/bluetooth/qlowenergycharacteristic.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/qlowenergycharacteristic.cpp') 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 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 QLowEnergyCharacteristic::descriptors() const { @@ -291,7 +316,7 @@ QList 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); } -- cgit v1.2.3