aboutsummaryrefslogtreecommitdiffstats
path: root/src/direct_bt/BTDevice.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-05-15 01:23:18 +0200
committerSven Gothel <[email protected]>2022-05-15 01:23:18 +0200
commit82ecfd8e19c88e3e4d0ddb04796874834292a05e (patch)
treea18d4972d9600521e2e830b0e541196d562e5066 /src/direct_bt/BTDevice.cpp
parent919cf46dd36e7c97a5784d86b5313f024212a756 (diff)
noexcept: BTGattHandler::send*(): Fix BTDevice::getGattService(): Return zero sized array of BTGattServices on error
BTGattHandler::discoverCompletePrimaryServices(): - just discover the services and its characteristics and descriptors - return bool, success of failor as returned by discovery methods (incl. their send*() command) BTGattHandler::initClientGatt(): - clear services before retrieval and on error - error response on - BTGattHandler::discoverCompletePrimaryServices() failure - no services - no GenericAccess services - only return true and leave services if no error BTDevice::getGattService(): - perform BTGattHandler::initClientGatt() error checks as well - update method API doc, describing failure included no GenericAccess service
Diffstat (limited to 'src/direct_bt/BTDevice.cpp')
-rw-r--r--src/direct_bt/BTDevice.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/direct_bt/BTDevice.cpp b/src/direct_bt/BTDevice.cpp
index 22887aee..1f89018d 100644
--- a/src/direct_bt/BTDevice.cpp
+++ b/src/direct_bt/BTDevice.cpp
@@ -1962,41 +1962,41 @@ jau::darray<BTGattServiceRef> BTDevice::getGattServices() noexcept {
}
bool gatt_already_init = false;
- const bool gatt_client_init = gh->initClientGatt(gh, gatt_already_init);
- jau::darray<BTGattServiceRef>& gattServices = gh->getServices();
- if( !gatt_client_init ) {
- ERR_PRINT2("BTDevice::getGattServices: Client GATT Initialization failed");
- return gattServices; // copy previous discovery result (zero sized)
+ if( !gh->initClientGatt(gh, gatt_already_init) ) {
+ ERR_PRINT2("Client GATT Initialization failed");
+ return jau::darray<BTGattServiceRef>(); // return zero size
}
if( gatt_already_init ) {
- return gattServices; // copy previous discovery result
+ return gh->getServices(); // copy previous discovery result
}
- // FIXME: GATTHandler::sendWithReply() == nullptr but gattServices.size() > 0 !!!
- if( gattServices.size() == 0 ) { // nothing discovered
- ERR_PRINT2("BTDevice::getGattServices: No primary services discovered");
- return gattServices;
+
+ jau::darray<BTGattServiceRef> result = gh->getServices(); // copy
+ if( result.size() == 0 ) { // nothing discovered, actually a redundant check done @ BTGattHandler::initClientGatt() 1st
+ ERR_PRINT2("No primary services discovered");
+ return jau::darray<BTGattServiceRef>(); // return zero size
}
// discovery success, parse GenericAccess
std::shared_ptr<GattGenericAccessSvc> gattGenericAccess = gh->getGenericAccess();
- if( nullptr != gattGenericAccess ) {
- const uint64_t ts = jau::getCurrentMilliseconds();
- EIRDataType updateMask = update(*gattGenericAccess, ts);
- DBG_PRINT("BTDevice::getGattServices: GenericAccess updated %s:\n %s\n -> %s",
- to_string(updateMask).c_str(), gattGenericAccess->toString().c_str(), toString().c_str());
- if( EIRDataType::NONE != updateMask ) {
- std::shared_ptr<BTDevice> sharedInstance = getSharedInstance();
- if( nullptr == sharedInstance ) {
- ERR_PRINT("Device unknown to adapter and not tracked: %s", toString().c_str());
- } else {
- adapter.sendDeviceUpdated("getGattServices", sharedInstance, ts, updateMask);
- }
+ if( nullptr == gattGenericAccess ) {
+ // no GenericAccess discovered, actually a redundant check done @ BTGattHandler::initClientGatt() 1st
+ ERR_PRINT2("No GenericAccess: %s", toString().c_str());
+ return jau::darray<BTGattServiceRef>(); // return zero size
+ }
+
+ const uint64_t ts = jau::getCurrentMilliseconds();
+ EIRDataType updateMask = update(*gattGenericAccess, ts);
+ DBG_PRINT("BTDevice::getGattServices: GenericAccess updated %s:\n %s\n -> %s",
+ to_string(updateMask).c_str(), gattGenericAccess->toString().c_str(), toString().c_str());
+ if( EIRDataType::NONE != updateMask ) {
+ std::shared_ptr<BTDevice> sharedInstance = getSharedInstance();
+ if( nullptr == sharedInstance ) {
+ ERR_PRINT("Device unknown to adapter and not tracked: %s", toString().c_str());
+ } else {
+ adapter.sendDeviceUpdated("getGattServices", sharedInstance, ts, updateMask);
}
- } else {
- // else: Actually an error w/o valid mandatory GenericAccess
- WARN_PRINT("No GenericAccess: %s", toString().c_str());
}
- return gattServices; // return copy
+ return result; // return the copy, copy elision shall be used
}
std::shared_ptr<GattGenericAccessSvc> BTDevice::getGattGenericAccess() {