diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-07-10 15:47:41 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-07-16 08:28:46 +0200 |
commit | f399837b3a723af9add6d9ea2d2e988f64f76ae0 (patch) | |
tree | 2c2a17ff5c4cfd007af98c98c70a2bf8c5fe8984 /src | |
parent | 8bf7e9986e359df46bb351dfb76e4140d9b04da7 (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')
-rw-r--r-- | src/bluetooth/qlowenergycharacteristic.cpp | 29 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristic.h | 2 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyservice.cpp | 25 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyservice.h | 2 |
4 files changed, 53 insertions, 5 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); } diff --git a/src/bluetooth/qlowenergycharacteristic.h b/src/bluetooth/qlowenergycharacteristic.h index 51cb70e6..5ed3dc55 100644 --- a/src/bluetooth/qlowenergycharacteristic.h +++ b/src/bluetooth/qlowenergycharacteristic.h @@ -87,7 +87,7 @@ public: QLowEnergyCharacteristic::PropertyTypes properties() const; QLowEnergyHandle handle() const; - // TODO: Simplify obtaining descriptor (e.g. via uuid) + QLowEnergyDescriptor descriptor(const QBluetoothUuid &uuid) const; QList<QLowEnergyDescriptor> descriptors() const; bool isValid() const; diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 30fe5733..401468f4 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -93,12 +93,35 @@ QLowEnergyService::ServiceState QLowEnergyService::state() const return d_ptr->state; } - QLowEnergyService::ServiceType QLowEnergyService::type() const { return d_ptr->type; } +/*! + Returns the matching characteristic for \a uuid; otherwise an invalid + characteristic. + + \sa characteristics() +*/ +QLowEnergyCharacteristic QLowEnergyService::characteristic(const QBluetoothUuid &uuid) const +{ + foreach (const QLowEnergyHandle handle, d_ptr->characteristicList.keys()) { + if (d_ptr->characteristicList[handle].uuid == uuid) + return QLowEnergyCharacteristic(d_ptr, handle); + } + + return QLowEnergyCharacteristic(); +} + +/*! + Returns all characteristics associated with this \c QLowEnergyService instance. + + The returned list will be empty if this service instance is invalid, + \l discoverDetails() was not yet called or there are no known characteristics. + + \sa characteristic(), state(), discoverDetails +*/ QList<QLowEnergyCharacteristic> QLowEnergyService::characteristics() const { diff --git a/src/bluetooth/qlowenergyservice.h b/src/bluetooth/qlowenergyservice.h index 1250e3a7..fcaf9496 100644 --- a/src/bluetooth/qlowenergyservice.h +++ b/src/bluetooth/qlowenergyservice.h @@ -79,7 +79,7 @@ public: QLowEnergyService::ServiceType type() const; QLowEnergyService::ServiceState state() const; - // TODO: Simplify obtaining characteristic (e.g. via uuid) + QLowEnergyCharacteristic characteristic(const QBluetoothUuid &uuid) const; QList<QLowEnergyCharacteristic> characteristics() const; QBluetoothUuid serviceUuid() const; QString serviceName() const; |