aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-26 07:02:34 +0200
committerSven Gothel <[email protected]>2020-06-26 07:02:34 +0200
commitaf5f9b2897ba50063b4e5af73190b32846413625 (patch)
treec6bb7ff610f87a731b4fa3300bd5dad8e92d355f
parent5d63b10a7628a4f58030dc0a206cde3aed8ccae0 (diff)
DBTDevice::pingGATT(): Catch exception and simply report, just the awaited potential disconnect
-rw-r--r--src/direct_bt/DBTDevice.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index bb71c8d1..a132c936 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -493,21 +493,26 @@ std::vector<std::shared_ptr<GATTService>> DBTDevice::getGATTServices() {
bool DBTDevice::pingGATT() {
const std::lock_guard<std::recursive_mutex> lock(mtx_gatt); // RAII-style acquire and relinquish via destructor
- if( nullptr == gattHandler || !gattHandler->isOpen() ) {
- connectGATT();
+ try {
if( nullptr == gattHandler || !gattHandler->isOpen() ) {
- ERR_PRINT("DBTDevice::getServices: connectGATT failed");
- return false;
+ connectGATT();
+ if( nullptr == gattHandler || !gattHandler->isOpen() ) {
+ ERR_PRINT("DBTDevice::getServices: connectGATT failed");
+ return false;
+ }
}
- }
- std::vector<std::shared_ptr<GATTService>> & gattServices = gattHandler->getServices(); // reference of the GATTHandler's list
- if( gattServices.size() == 0 ) { // discover services
- gattServices = gattHandler->discoverCompletePrimaryServices(); // same reference of the GATTHandler's list
- if( gattServices.size() == 0 ) { // nothing discovered
- return false;
+ std::vector<std::shared_ptr<GATTService>> & gattServices = gattHandler->getServices(); // reference of the GATTHandler's list
+ if( gattServices.size() == 0 ) { // discover services
+ gattServices = gattHandler->discoverCompletePrimaryServices(); // same reference of the GATTHandler's list
+ if( gattServices.size() == 0 ) { // nothing discovered
+ return false;
+ }
}
+ return gattHandler->ping();
+ } catch (std::exception &e) {
+ INFO_PRINT("DBTDevice::pingGATT: Potential disconnect, exception: '%s' on %s", e.what(), toString().c_str());
}
- return gattHandler->ping();
+ return false;
}
std::shared_ptr<GenericAccess> DBTDevice::getGATTGenericAccess() {