Files
relay_chn/private_include/relay_chn_notify.h
ismail 5e8e5a4cab 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
2025-09-02 15:46:48 +03:00

52 lines
1.3 KiB
C

/*
* SPDX-FileCopyrightText: 2025 Kozmotronik Tech
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include "esp_err.h"
#include <stdint.h>
#include "relay_chn_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Init the notify module.
*
* @return
* - ESP_OK: Success
* - ESP_ERR_NO_MEM: Not enough memory to create notify queue
*/
esp_err_t relay_chn_notify_init(void);
/**
* @brief Deinit the notify module.
*
* This function cleans up resources used by the notify module.
*/
void relay_chn_notify_deinit(void);
/**
* @brief Notify all registered listeners about a state change.
*
* This function sends a state change event to an internal queue, which will then
* be processed by a dedicated task to notify all registered listeners. This
* function is typically called internally by the relay channel core logic.
*
* @param chn_id The ID of the relay channel whose state has changed.
* @param old_state The previous state of the relay channel.
* @param new_state The new state of the relay channel.
*/
esp_err_t relay_chn_notify_state_change(uint8_t chn_id,
relay_chn_state_t old_state,
relay_chn_state_t new_state);
#ifdef __cplusplus
}
#endif