pub unsafe extern "C" fn esp_event_handler_register(
event_base: *const u8,
event_id: i32,
event_handler: Option<unsafe extern "C" fn(*mut c_void, *const u8, i32, *mut c_void)>,
event_handler_arg: *mut c_void,
) -> i32Expand description
@brief Register an event handler to the system event loop (legacy).
This function can be used to register a handler for either: (1) specific events, (2) all events of a certain event base, or (3) all events known by the system event loop.
- specific events: specify exact event_base and event_id
- all events of a certain base: specify exact event_base and use ESP_EVENT_ANY_ID as the event_id
- all events known by the loop: use ESP_EVENT_ANY_BASE for event_base and ESP_EVENT_ANY_ID as the event_id
Registering multiple handlers to events is possible. Registering a single handler to multiple events is also possible. However, registering the same handler to the same event multiple times would cause the overwriting of the event_handler_arg but the handler will be kept at the same position in the list associated with the event that triggers it. It means that the call order of registered handlers for that event will remain the same.
@param[in] event_base the base ID of the event to register the handler for @param[in] event_id the ID of the event to register the handler for @param[in] event_handler the handler function which gets called when the event is dispatched @param[in] event_handler_arg data, aside from event data, that is passed to the handler when it is called
@note the event loop library does not maintain a copy of event_handler_arg, therefore the user should ensure that event_handler_arg still points to a valid location by the time the handler gets called
@return
- ESP_OK: Success
- ESP_ERR_NO_MEM: Cannot allocate memory for the handler
- ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID
- Others: Fail