Merge pull request #12384 from s-hadinger/ble_no_exceptions

Remove exceptions from BLE
This commit is contained in:
Theo Arends 2021-06-17 09:36:18 +02:00 committed by GitHub
commit 542074ec69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 57 additions and 93 deletions

View File

@ -1408,7 +1408,6 @@ class BLEAdvCallbacks: public NimBLEAdvertisedDeviceCallbacks {
// call anyone who asked about advertisements
for (int i = 0; i < advertismentCallbacks.size(); i++) {
try {
ADVERTISMENT_CALLBACK* pFN;
pFN = advertismentCallbacks[i];
int res = pFN(&BLEAdvertisment);
@ -1420,11 +1419,6 @@ class BLEAdvCallbacks: public NimBLEAdvertisedDeviceCallbacks {
if (2 == res) {
//BLEScan->erase(address);
}
} catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG
AddLog(LOG_LEVEL_ERROR,PSTR("BLE: exception in advertismentCallbacks"));
#endif
}
}
}
@ -1444,17 +1438,11 @@ static void BLEscanEndedCB(NimBLEScanResults results){
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: Scan ended"));
#endif
for (int i = 0; i < scancompleteCallbacks.size(); i++){
try {
SCANCOMPLETE_CALLBACK *pFn = scancompleteCallbacks[i];
int callbackres = pFn(results);
#ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: scancompleteCallbacks %d %d"), i, callbackres);
#endif
} catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG
AddLog(LOG_LEVEL_ERROR,PSTR("BLE: exception in operationsCallbacks"));
#endif
}
}
BLERunningScan = 2;
@ -1659,7 +1647,6 @@ static void BLETaskStopStartNimBLE(NimBLEClient **ppClient, bool start = true){
(*ppClient)->setClientCallbacks(nullptr, false);
try {
if ((*ppClient)->isConnected()){
#ifdef BLE_ESP32_DEBUG
AddLog(LOG_LEVEL_INFO,PSTR("BLE: disconnecting connected client"));
@ -1671,11 +1658,6 @@ static void BLETaskStopStartNimBLE(NimBLEClient **ppClient, bool start = true){
#ifdef BLE_ESP32_DEBUG
AddLog(LOG_LEVEL_INFO,PSTR("BLE: deleted client"));
#endif
} catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG
AddLog(LOG_LEVEL_ERROR,PSTR("BLE: Stopping NimBLE:exception in delete client"));
#endif
}
if (ble32Scan){
ble32Scan->setAdvertisedDeviceCallbacks(nullptr,true);
@ -2089,7 +2071,6 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
// for safety's sake, only call from the run task
static void BLETaskRunTaskDoneOperation(BLE_ESP32::generic_sensor_t** op, NimBLEClient **ppClient){
try {
if ((*ppClient)->isConnected()){
#ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: runTaskDoneOperation: disconnecting connected client"));
@ -2126,11 +2107,6 @@ static void BLETaskRunTaskDoneOperation(BLE_ESP32::generic_sensor_t** op, NimBLE
}
} while ((*ppClient)->isConnected());
}
} catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG
AddLog(LOG_LEVEL_ERROR,PSTR("BLE: runTaskDoneOperation: exception in disconnect"));
#endif
}
{
@ -3322,22 +3298,15 @@ static void mainThreadOpCallbacks() {
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: op->completecallback is %u opid %d"), op->completecallback, op->opid);
if (op->completecallback){
try {
OPCOMPLETE_CALLBACK *pFn = (OPCOMPLETE_CALLBACK *)(op->completecallback);
callbackres = pFn(op);
#ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: op->completecallback %d opid %d"), callbackres, op->opid);
#endif
} catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG
AddLog(LOG_LEVEL_ERROR,PSTR("BLE: exception in op->completecallback"));
#endif
}
}
if (!callbackres){
for (int i = 0; i < operationsCallbacks.size(); i++){
try {
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: operationsCallbacks %d is %u"), i, operationsCallbacks[i]);
OPCOMPLETE_CALLBACK *pFn = operationsCallbacks[i];
callbackres = pFn(op);
@ -3347,11 +3316,6 @@ static void mainThreadOpCallbacks() {
if (callbackres){
break; // this callback ate the op.
}
} catch(const std::exception& e){
#ifdef BLE_ESP32_DEBUG
AddLog(LOG_LEVEL_ERROR,PSTR("BLE: exception in operationsCallbacks"));
#endif
}
}
}