From 99d62bcce229ab2807f0ea5b8a0f618b4e93c665 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 1 Apr 2015 13:43:42 +0200 Subject: Emit OperationError if char or desc is not part of current service So far, the OperationError was not set. This improves the error feedback to the user. Change-Id: I37eccb2419d6ede3b9bd4e94b9e0538182d1db7e Reviewed-by: Timur Pocheptsov --- src/bluetooth/qlowenergyservice.cpp | 42 ++++++++++++++++------------------ src/bluetooth/qlowenergyservice_osx.mm | 22 ++++-------------- 2 files changed, 24 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 0db349f1..21090c77 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -558,7 +558,8 @@ bool QLowEnergyService::contains(const QLowEnergyCharacteristic &characteristic) A characteristic can only be read if the service is in the \l ServiceDiscovered state, belongs to the service and is readable. If \a characteristic is readable its - \l QLowEnergyCharacteristic::Read property is set. + \l QLowEnergyCharacteristic::Read property is set. If one of those conditions is + not true the \l QLowEnergyService::OperationError is set. \sa characteristicRead() @@ -569,11 +570,9 @@ void QLowEnergyService::readCharacteristic( { Q_D(QLowEnergyService); - // not a characteristic of this service - if (!contains(characteristic)) - return; - - if (state() != ServiceDiscovered || !d->controller) { + if (!contains(characteristic) + || state() != ServiceDiscovered + || !d->controller) { d->setError(QLowEnergyService::OperationError); return; } @@ -603,7 +602,8 @@ void QLowEnergyService::readCharacteristic( Bluetooth specification. A characteristic can only be written if this service is in the \l ServiceDiscovered state, - belongs to the service and is writable. + belongs to the service and is writable. If one of those conditions is + not true the \l QLowEnergyService::OperationError is set. \sa QLowEnergyCharacteristic::properties() */ @@ -614,11 +614,9 @@ void QLowEnergyService::writeCharacteristic( //TODO check behavior when writing to WriteSigned characteristic Q_D(QLowEnergyService); - // not a characteristic of this service - if (!contains(characteristic)) - return; - - if (state() != ServiceDiscovered || !d->controller) { + if (!contains(characteristic) + || state() != ServiceDiscovered + || !d->controller) { d->setError(QLowEnergyService::OperationError); return; } @@ -674,7 +672,8 @@ bool QLowEnergyService::contains(const QLowEnergyDescriptor &descriptor) const The queue does not eliminate duplicated read requests for the same descriptor. A descriptor can only be written if the service is in the \l ServiceDiscovered state, - belongs to the service and is readable. + belongs to the service and is readable. If one of those conditions is + not true the \l QLowEnergyService::OperationError is set. \sa descriptorRead() @@ -685,10 +684,9 @@ void QLowEnergyService::readDescriptor( { Q_D(QLowEnergyService); - if (!contains(descriptor)) - return; - - if (state() != ServiceDiscovered || !d->controller) { + if (!contains(descriptor) + || state() != ServiceDiscovered + || !d->controller) { d->setError(QLowEnergyService::OperationError); return; } @@ -710,17 +708,17 @@ void QLowEnergyService::readDescriptor( to B, the two write request are executed in the given order. A descriptor can only be written if this service is in the \l ServiceDiscovered state, - belongs to the service and is writable. + belongs to the service and is writable. If one of those conditions is + not true the \l QLowEnergyService::OperationError is set. */ void QLowEnergyService::writeDescriptor(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue) { Q_D(QLowEnergyService); - if (!contains(descriptor)) - return; - - if (state() != ServiceDiscovered || !d->controller) { + if (!contains(descriptor) + || state() != ServiceDiscovered + || !d->controller) { d->setError(QLowEnergyService::OperationError); return; } diff --git a/src/bluetooth/qlowenergyservice_osx.mm b/src/bluetooth/qlowenergyservice_osx.mm index 80ab6eaa..51b0f53d 100644 --- a/src/bluetooth/qlowenergyservice_osx.mm +++ b/src/bluetooth/qlowenergyservice_osx.mm @@ -179,12 +179,8 @@ bool QLowEnergyService::contains(const QLowEnergyCharacteristic &characteristic) void QLowEnergyService::readCharacteristic(const QLowEnergyCharacteristic &characteristic) { - // not a characteristic of this service - if (!contains(characteristic)) - return; - QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr); - if (state() != ServiceDiscovered || !controller) { + if (!contains(characteristic) || state() != ServiceDiscovered || !controller) { d_ptr->setError(OperationError); return; } @@ -196,13 +192,9 @@ void QLowEnergyService::readCharacteristic(const QLowEnergyCharacteristic &chara void QLowEnergyService::writeCharacteristic(const QLowEnergyCharacteristic &ch, const QByteArray &newValue, WriteMode mode) { - // Not a characteristic of this service - if (!contains(ch)) - return; - QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr); - if (state() != ServiceDiscovered || !controller) { + if (!contains(ch) || state() != ServiceDiscovered || !controller) { d_ptr->setError(QLowEnergyService::OperationError); return; } @@ -236,11 +228,8 @@ bool QLowEnergyService::contains(const QLowEnergyDescriptor &descriptor) const void QLowEnergyService::readDescriptor(const QLowEnergyDescriptor &descriptor) { - if (!contains(descriptor)) - return; - QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr); - if (state() != ServiceDiscovered || !controller) { + if (!contains(descriptor) || state() != ServiceDiscovered || !controller) { d_ptr->setError(OperationError); return; } @@ -251,11 +240,8 @@ void QLowEnergyService::readDescriptor(const QLowEnergyDescriptor &descriptor) void QLowEnergyService::writeDescriptor(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue) { - if (!contains(descriptor)) - return; - QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr); - if (state() != ServiceDiscovered || !controller) { + if (!contains(descriptor) || state() != ServiceDiscovered || !controller) { d_ptr->setError(OperationError); return; } -- cgit v1.2.3