Dear Nordic Team,
I was trying to understand event handlers from SDK5 examples. I understood that by using following macro we can register our event handlers, and afterwards receive BLE events and take appropriate actions either by using switch statements directly or by forwarding event data to other custom event handlers.
NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_NUS_C_BLE_OBSERVER_PRIO, ble_nus_c_on_ble_evt, &_name)
In NUS Central example, I came across following code snippet :
void ble_nus_c_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context) { ble_nus_c_t * p_ble_nus_c = (ble_nus_c_t *)p_context; ...
I can't understand meaning of "p_context" argument. How do we know that p_context variable holds NUS client instance? How does event handler link events with the object? Is it possible that generic softdevice event handler below is also receiving NUS client pointer?
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
I would appreciate if you can explain logic behind the context variable and how does it work.