Add notification system for relay channel state changes
- Introduced a new notification module to handle state change listeners. - Added functions to register and unregister listeners for relay channel state changes. - Implemented a queue-based system to manage notifications and listener callbacks. - Updated core relay channel logic to utilize the new notification system. - Removed old listener management code from relay channel core. - Refactored the former listener tests to notify tests and added tests for the notification system, including handling of multiple listeners and queue overflow scenarios. - Updated CMakeLists.txt to include new source files and headers for the notification module. - Revised README.md to include warnings about callback execution context and performance considerations. Refs #1096, #1085 and closes #1097
This commit is contained in:
@@ -13,6 +13,36 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Register a channel state change listener.
|
||||
*
|
||||
* @param listener A function that implements relay_chn_state_listener_t interface.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_ERR_INVALID_ARG: Invalid argument
|
||||
* - ESP_ERR_NO_MEM: No enough memory
|
||||
* - ESP_FAIL: General failure
|
||||
*/
|
||||
extern esp_err_t relay_chn_notify_add_listener(relay_chn_state_listener_t listener);
|
||||
|
||||
/**
|
||||
* @brief Unregister a channel state change listener.
|
||||
*
|
||||
* @param listener A function that implements relay_chn_state_listener_t interface.
|
||||
*/
|
||||
extern void relay_chn_notify_remove_listener(relay_chn_state_listener_t listener);
|
||||
|
||||
static inline esp_err_t relay_chn_register_listener(relay_chn_state_listener_t listener)
|
||||
{
|
||||
return relay_chn_notify_add_listener(listener);
|
||||
}
|
||||
|
||||
static inline void relay_chn_unregister_listener(relay_chn_state_listener_t listener)
|
||||
{
|
||||
relay_chn_notify_remove_listener(listener);
|
||||
}
|
||||
|
||||
#if CONFIG_RELAY_CHN_COUNT > 1
|
||||
/**
|
||||
* @brief Get the current state of a relay channel.
|
||||
|
||||
Reference in New Issue
Block a user