From edd7678cfc83eefe6dbf745656867ab1dfc77561 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Tue, 9 Feb 2021 19:43:33 +0000 Subject: [PATCH] BLE: Add API to test the presence of an event handler in a chain. --- .../ble/common/ChainableEventHandler.h | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/connectivity/FEATURE_BLE/include/ble/common/ChainableEventHandler.h b/connectivity/FEATURE_BLE/include/ble/common/ChainableEventHandler.h index 7e3f06237d..616980154b 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/ChainableEventHandler.h +++ b/connectivity/FEATURE_BLE/include/ble/common/ChainableEventHandler.h @@ -71,14 +71,14 @@ public: * * @param[in] event_handler Pointer to event handler to remove */ - void removeEventHandler(T* target) { + void removeEventHandler(T* event_handler) { node_t* to_remove = head; - if(head->eh == target) { + if(head->eh == event_handler) { head = head->next; } else { auto* it = head; while(it->next) { - if(it->next->eh == target) { + if(it->next->eh == event_handler) { to_remove = it->next; break; } @@ -94,6 +94,22 @@ public: delete to_remove; } + /** + * Test if an event handler is present in the chain or not. + * + * @param[in] event_handler Pointer to event handler to check + */ + bool isEventHandlerPresent(T* event_handler) { + auto* it = head; + while (it) { + if (it == event_handler) { + return true; + } + it = it->next; + } + return false; + } + protected: template