diff options
author | Sven Gothel <[email protected]> | 2022-04-23 01:05:06 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-04-23 04:44:28 +0200 |
commit | 6b5e060dcacb58824a90520fb07522d5b4192749 (patch) | |
tree | 4d8856d33ca5f4ca95dbbcb827a7d7c8fd1de64a /src/direct_bt/BTGattDesc.cpp | |
parent | 90975ae1c2a4e36761419f94a8f418f445833661 (diff) |
noexcept: BTGattChar + BTGattDesc
Diffstat (limited to 'src/direct_bt/BTGattDesc.cpp')
-rw-r--r-- | src/direct_bt/BTGattDesc.cpp | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/direct_bt/BTGattDesc.cpp b/src/direct_bt/BTGattDesc.cpp index ef737e50..ce518ef0 100644 --- a/src/direct_bt/BTGattDesc.cpp +++ b/src/direct_bt/BTGattDesc.cpp @@ -52,28 +52,46 @@ std::shared_ptr<BTGattChar> BTGattDesc::getGattCharChecked() const { return ref; } -std::shared_ptr<BTGattHandler> BTGattDesc::getGattHandlerChecked() const { - return getGattCharChecked()->getGattHandlerChecked(); +std::shared_ptr<BTGattHandler> BTGattDesc::getGattHandlerUnchecked() const noexcept { + std::shared_ptr<BTGattChar> c = getGattCharUnchecked(); + if( nullptr != c ) { + return c->getGattHandlerUnchecked(); + } + return nullptr; } -std::shared_ptr<BTDevice> BTGattDesc::getDeviceChecked() const { - return getGattCharChecked()->getDeviceChecked(); +std::shared_ptr<BTDevice> BTGattDesc::getDeviceUnchecked() const noexcept { + std::shared_ptr<BTGattChar> c = getGattCharUnchecked(); + if( nullptr != c ) { + return c->getDeviceUnchecked(); + } + return nullptr; } -bool BTGattDesc::readValue(int expectedLength) { - std::shared_ptr<BTDevice> device = getDeviceChecked(); +bool BTGattDesc::readValue(int expectedLength) noexcept { + std::shared_ptr<BTDevice> device = getDeviceUnchecked(); + if( nullptr == device ) { + ERR_PRINT("Descriptor's device null: %s", toShortString().c_str()); + return false; + } std::shared_ptr<BTGattHandler> gatt = device->getGattHandler(); if( nullptr == gatt ) { - throw jau::IllegalStateException("Descriptor's device GATTHandle not connected: "+toShortString(), E_FILE_LINE); + ERR_PRINT("Descriptor's device GATTHandle not connected: %s", toShortString().c_str()); + return false; } return gatt->readDescriptorValue(*this, expectedLength); } -bool BTGattDesc::writeValue() { - std::shared_ptr<BTDevice> device = getDeviceChecked(); +bool BTGattDesc::writeValue() noexcept { + std::shared_ptr<BTDevice> device = getDeviceUnchecked(); + if( nullptr == device ) { + ERR_PRINT("Descriptor's device null: %s", toShortString().c_str()); + return false; + } std::shared_ptr<BTGattHandler> gatt = device->getGattHandler(); if( nullptr == gatt ) { - throw jau::IllegalStateException("Descriptor's device GATTHandle not connected: "+toShortString(), E_FILE_LINE); + ERR_PRINT("Descriptor's device GATTHandle not connected: %s", toShortString().c_str()); + return false; } return gatt->writeDescriptorValue(*this); } |