Files
relay_chn/test_apps/main/test_relay_chn_notify_common.c
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

49 lines
1.6 KiB
C

#include "test_relay_chn_notify_common.h"
listener_callback_info_t listener1_info;
listener_callback_info_t listener2_info;
// --- Globals for Advanced Tests ---
SemaphoreHandle_t blocking_listener_sem = NULL;
SemaphoreHandle_t log_check_sem = NULL;
volatile int blocking_listener_call_count = 0;
vprintf_like_t original_vprintf = NULL;
// --- Listener Test Helper Functions ---
// Clear the memory from possible garbage values
void reset_listener_info(listener_callback_info_t* info) {
memset(info, 0, sizeof(listener_callback_info_t));
}
void test_listener_1(uint8_t chn_id, relay_chn_state_t old_state, relay_chn_state_t new_state) {
listener1_info.chn_id = chn_id;
listener1_info.old_state = old_state;
listener1_info.new_state = new_state;
listener1_info.call_count++;
}
void test_listener_2(uint8_t chn_id, relay_chn_state_t old_state, relay_chn_state_t new_state) {
listener2_info.chn_id = chn_id;
listener2_info.old_state = old_state;
listener2_info.new_state = new_state;
listener2_info.call_count++;
}
void blocking_listener(uint8_t chn_id, relay_chn_state_t old_state, relay_chn_state_t new_state) {
blocking_listener_call_count++;
// Block until the main test task unblocks us
xSemaphoreTake(blocking_listener_sem, portMAX_DELAY);
}
int log_check_vprintf(const char *format, va_list args) {
// Buffer to hold the formatted log message
char buffer[256];
vsnprintf(buffer, sizeof(buffer), format, args);
if (strstr(buffer, "Notify queue is full")) {
xSemaphoreGive(log_check_sem);
}
return original_vprintf(format, args);
}