add generic callback signaler

This commit is contained in:
Morgan 'ARR\!' Allen 2024-11-29 21:15:19 -08:00
parent 85dc35dcc2
commit d4f0a3b90f
3 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,14 @@
typedef void (*cfglr_callback_t)(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig);
typedef struct {
cfglr_callback_t callback;
} cfglr_callback_handle_t;
void cfglr_signaler_callback_init(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_handle_t *handle);
void cfglr_signaler_callback_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig);
#define CFGLR_SIGNALER_CALLBACK(FN_CALLBACK) (cfglr_signaler_t){\
.init = &cfglr_signaler_callback_init,\
.dispatch = &cfglr_signaler_callback_dispatch,\
.handle = (void*)FN_CALLBACK\
}

View file

@ -115,7 +115,9 @@ struct cfglr_handle_struct {
uint8_t cfglr_init(cfglr_handle_t *handle);
uint8_t cfglr_fetch_data(cfglr_backend_t *backend, cfglr_element_t *element, cfglr_handle_t *handler);
#include "cfglr_log.h"
#include "cfglr_nvs.h"
#include "cfglr_signaler_callback.h"
#include "cfglr_signaler_idf_event.h"
#include "cfglr_signaler_lvgl.h"

View file

@ -0,0 +1,16 @@
#include "configulator.h"
#define TAG "CFGLR_SIG_CB"
void cfglr_signaler_callback_init(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_handle_t *handle) {
CFGLR_LOGI(TAG, "init");
}
void cfglr_signaler_callback_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig) {
CFGLR_LOGI(TAG, "dispatch");
if(signaler->handle != NULL) {
cfglr_callback_t callback = signaler->handle;
callback(signaler, element, sig);
}
}