#pragma once #include #include #include #include "packet.h" #include "evt_core.h" #define PACKET_BUFFER_SIZE 20 struct algo_params { uint8_t is_waiting_bootstrap; uint8_t is_healing; char* algo_name; }; struct algo_ctx; typedef void (*algo_init)(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struct algo_params* ap); typedef int (*algo_ctx_on_buffer)(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp); typedef int (*algo_ctx_on_event)(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo); typedef void (*algo_ctx_free_misc)(void*); struct algo_desc { char* name; algo_init init; algo_ctx_on_buffer on_stream; algo_ctx_on_buffer on_datagram; algo_ctx_on_event on_timer; algo_ctx_on_event on_err; }; struct algo_ctx { struct algo_desc* desc; uint8_t link_count; uint8_t is_rdy; struct algo_params ap; int ref_count; struct buffer_packet bps[PACKET_BUFFER_SIZE]; GQueue* free_buffer; // Available buffers GHashTable* used_buffer; // Buffers used for reading or writing GQueue* read_waiting; // Who wait to be notified for a read GHashTable* application_waiting; // Structure that can be used by the algo for its internal logic GHashTable* write_waiting; // Structure to track packets waiting to be written void* misc; // Additional structures algo_ctx_free_misc free_misc; // Fx ptr to free misc }; void mv_buffer_rtow(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, struct evt_core_fdinfo* to); void mv_buffer_wtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from); void mv_buffer_rtoa(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, void* to); void mv_buffer_atow(struct algo_ctx* app_ctx, void* from, struct evt_core_fdinfo* to); void mv_buffer_atof(struct algo_ctx* app_ctx, void* from); void dup_buffer_tow(struct algo_ctx* app_ctx, struct buffer_packet* bp, struct evt_core_fdinfo* to); struct buffer_packet* get_write_buffer(struct algo_ctx *app_ctx, struct evt_core_fdinfo *fdinfo); struct buffer_packet* get_read_buffer(struct algo_ctx *app_ctx, struct evt_core_fdinfo *fdinfo); struct buffer_packet* get_app_buffer(struct algo_ctx *app_ctx, void* idx); void notify_read(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx); void free_naive(void* app_ctx); void free_nothing(void* app_ctx); void naive_free_simple(void* v);