From 004491a61de53d128aade26d497dcf7a557e09c4 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 24 Jun 2014 15:08:44 +0200 Subject: Introduce QLowEnergyDescriptor The class is based in QLowEnergyDescriptorInfo and exposes the found descriptor information. The only missing piece of information is the descriptor value. Extends the QLowEnergyController unit test in such a way that descriptor information is tested too (except for values). Change-Id: I6ba6a862fff48fbdd27cd8219d2eb8f6d0058aea Reviewed-by: Fabian Bumberger Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycharacteristic.cpp | 34 ++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/bluetooth/qlowenergycharacteristic.cpp') diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp index 10136c10..f74aa808 100644 --- a/src/bluetooth/qlowenergycharacteristic.cpp +++ b/src/bluetooth/qlowenergycharacteristic.cpp @@ -219,9 +219,16 @@ QLowEnergyCharacteristic &QLowEnergyCharacteristic::operator=(const QLowEnergyCh } /*! - Returns true if the QLowEnergyCharacteristic object is valid, otherwise returns false. - If it returns \c false, it means that this instance is not associated to any service - or the associated service is no longer valid. + Returns \c true if the QLowEnergyCharacteristic object is valid, otherwise returns \c false. + + An invalid characteristic object is not associated to any service + or the associated service is no longer valid due to for example a disconnect from + the underlying Bluetooth Low Energy device. Once the object is invalid + it cannot become valid anymore. + + \note If a QLowEnergyCharacteristic instance turns invalid due to a disconnect + from the underlying device, the information encapsulated by the current + instance remains as it was at the time of the disconnect. */ bool QLowEnergyCharacteristic::isValid() const { @@ -239,12 +246,25 @@ bool QLowEnergyCharacteristic::isValid() const /*! Returns the list of characteristic descriptors. */ -QList QLowEnergyCharacteristic::descriptors() const +QList QLowEnergyCharacteristic::descriptors() const { - // TODO QLowEnergyCharacteristic::descriptors() - QList result; - return result; + QList result; + + if (d_ptr.isNull() || !data + || !d_ptr->characteristicList.contains(data->handle)) + return result; + QList descriptorKeys = d_ptr->characteristicList[data->handle]. + descriptorList.keys(); + + std::sort(descriptorKeys.begin(), descriptorKeys.end()); + + foreach (QLowEnergyHandle descHandle, descriptorKeys) { + QLowEnergyDescriptor descriptor(d_ptr, data->handle, descHandle); + result.append(descriptor); + } + + return result; } QT_END_NAMESPACE -- cgit v1.2.3