summaryrefslogtreecommitdiffstats
path: root/src/direct_bt/GATTDescriptor.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-07-26 05:42:38 +0200
committerSven Gothel <[email protected]>2020-07-26 05:42:38 +0200
commitce4481eaf4856ab2d2e2c4a9f39093888b34617f (patch)
tree5afb24d72e91c155e1b7eda402b70bb351713206 /src/direct_bt/GATTDescriptor.cpp
parent74d41274760a9087c7a8c57e145fe531b035baae (diff)
Robustness: Distinguish between get<Type>Checked() and get<Type>Unchecked(): Use it accordingly, reducing duplicated code etc.
Diffstat (limited to 'src/direct_bt/GATTDescriptor.cpp')
-rw-r--r--src/direct_bt/GATTDescriptor.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/direct_bt/GATTDescriptor.cpp b/src/direct_bt/GATTDescriptor.cpp
index 5d23c97f..f646fdbb 100644
--- a/src/direct_bt/GATTDescriptor.cpp
+++ b/src/direct_bt/GATTDescriptor.cpp
@@ -43,19 +43,20 @@ const uuid16_t GATTDescriptor::TYPE_EXT_PROP(Type::CHARACTERISTIC_EXTENDED_PROPE
const uuid16_t GATTDescriptor::TYPE_USER_DESC(Type::CHARACTERISTIC_USER_DESCRIPTION);
const uuid16_t GATTDescriptor::TYPE_CCC_DESC(Type::CLIENT_CHARACTERISTIC_CONFIGURATION);
-std::shared_ptr<DBTDevice> GATTDescriptor::getDevice() const {
- std::shared_ptr<GATTCharacteristic> c = getCharacteristic();
- if( nullptr != c ) {
- return c->getDevice();
+std::shared_ptr<GATTCharacteristic> GATTDescriptor::getCharacteristicChecked() const {
+ std::shared_ptr<GATTCharacteristic> ref = wbr_characteristic.lock();
+ if( nullptr == ref ) {
+ throw IllegalStateException("GATTDescriptor's characteristic already destructed: "+toString(), E_FILE_LINE);
}
- return nullptr;
+ return ref;
+}
+
+std::shared_ptr<DBTDevice> GATTDescriptor::getDeviceChecked() const {
+ return getCharacteristicChecked()->getDeviceChecked();
}
bool GATTDescriptor::readValue(int expectedLength) {
- std::shared_ptr<DBTDevice> device = getDevice();
- if( nullptr == device ) {
- throw IllegalStateException("Descriptor's device already destructed: "+toString(), E_FILE_LINE);
- }
+ std::shared_ptr<DBTDevice> device = getDeviceChecked();
std::shared_ptr<GATTHandler> gatt = device->getGATTHandler();
if( nullptr == gatt ) {
throw IllegalStateException("Descriptor's device GATTHandle not connected: "+
@@ -65,10 +66,7 @@ bool GATTDescriptor::readValue(int expectedLength) {
}
bool GATTDescriptor::writeValue() {
- std::shared_ptr<DBTDevice> device = getDevice();
- if( nullptr == device ) {
- throw IllegalStateException("Descriptor's device already destructed: "+toString(), E_FILE_LINE);
- }
+ std::shared_ptr<DBTDevice> device = getDeviceChecked();
std::shared_ptr<GATTHandler> gatt = device->getGATTHandler();
if( nullptr == gatt ) {
throw IllegalStateException("Descriptor's device GATTHandle not connected: "+