diff options
| author | Dan Halbert <halbert@halwitz.org> | 2019-01-03 21:42:42 -0500 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2019-01-03 21:42:42 -0500 |
| commit | a77b2363eff14ae5b19c50a7d25b3db4ef6b200c (patch) | |
| tree | 3b27fef3faf091e584b9990bf4a6f51cc1edb2c4 /ports/nrf/bluetooth | |
| parent | 8dea6f53bbba5b76a5ed0965b44ad1bde4640609 (diff) | |
evt handler list bugs; unique evt handler names; remove uuid128_reference
Diffstat (limited to 'ports/nrf/bluetooth')
| -rw-r--r-- | ports/nrf/bluetooth/ble_drv.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/ports/nrf/bluetooth/ble_drv.c b/ports/nrf/bluetooth/ble_drv.c index 62820289b..7082b1e59 100644 --- a/ports/nrf/bluetooth/ble_drv.c +++ b/ports/nrf/bluetooth/ble_drv.c @@ -53,27 +53,22 @@ void ble_drv_reset() { } void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param) { - event_handler_t *handler = m_new_ll(event_handler_t, 1); - handler->next = NULL; - handler->param = param; - handler->func = func; - - if (m_event_handlers == NULL) { - m_event_handlers = handler; - return; - } - event_handler_t *it = m_event_handlers; - while (it->next != NULL) { + while (it != NULL) { + // If event handler and its corresponding param are already on the list, don't add again. if ((it->func == func) && (it->param == param)) { - m_free(handler); return; } - it = it->next; } - it->next = handler; + // Add a new handler to the front of the list + event_handler_t *handler = m_new_ll(event_handler_t, 1); + handler->next = m_event_handlers; + handler->param = param; + handler->func = func; + + m_event_handlers = handler; } void SD_EVT_IRQHandler(void) { |
