#ifndef __H2201_DISPATCHER_H__
#define __H2201_DISPATCHER_H__
#include "esp_event.h"
#include "esp_timer.h"

#define H2201_DISPATCHER_TAG "H2201_DISPATCHER"

#define H2201_DISPATCHER_QUEUE_SIZE 50

#define H2201_DISPATCHER_SIG_DOWORK (0x01)

/**
 * @brief     handler for the dispatched work
 */
typedef void (*h2201_dispatcher_cb_t)(uint16_t event, void *param);

typedef struct
{
    uint16_t sig;             /*!< signal type */
    uint16_t event;           /*!< message event id */
    h2201_dispatcher_cb_t cb; /*!< context switch callback */
    void *param; /*!< parameter area needs to be last */
} h2201_dispatcher_msg_t;

/**
 * @brief     parameter deep-copy function to be customized
 */
typedef void (*h2201_dispatcher_copy_cb_t)(h2201_dispatcher_msg_t *msg, void *p_dest, void *p_src);

/**
 * @brief     work dispatcher for the application task
 */
bool h2201_dispatcher_dowork(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len, h2201_dispatcher_copy_cb_t p_copy_cback);
bool h2201_dispatcher_dowork_simple(h2201_dispatcher_cb_t p_cback, uint16_t event);
void h2201_dispatcher_dowork_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len);
bool h2201_dispatcher_dowork_simple_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event);

void H2201_dispacther_init(void);

#endif /* __H2201_DISPATCHER_H__ */