2019-03-07 15:57:02 +00:00
|
|
|
#pragma once
|
|
|
|
#include <glib-2.0/glib.h>
|
|
|
|
#include <glib-2.0/gmodule.h>
|
|
|
|
#include <glib-2.0/glib-object.h>
|
2019-04-24 14:23:41 +00:00
|
|
|
#include "packet.h"
|
|
|
|
#include "evt_core.h"
|
2019-05-24 14:16:39 +00:00
|
|
|
#define PACKET_BUFFER_SIZE 1024
|
2019-03-15 15:44:47 +00:00
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
struct algo_params {
|
|
|
|
uint8_t is_waiting_bootstrap;
|
|
|
|
uint8_t is_healing;
|
|
|
|
char* algo_name;
|
2019-05-09 13:33:27 +00:00
|
|
|
int links, fresh_data, redundant_data;
|
2019-04-24 14:23:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-03-15 15:44:47 +00:00
|
|
|
typedef void (*algo_ctx_free_misc)(void*);
|
2019-03-07 15:57:02 +00:00
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
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_err;
|
|
|
|
};
|
|
|
|
|
2019-03-07 15:57:02 +00:00
|
|
|
struct algo_ctx {
|
2019-04-24 14:23:41 +00:00
|
|
|
struct algo_desc* desc;
|
2019-03-28 14:58:18 +00:00
|
|
|
uint8_t link_count;
|
|
|
|
uint8_t is_rdy;
|
|
|
|
struct algo_params ap;
|
2019-03-07 15:57:02 +00:00
|
|
|
int ref_count;
|
2019-03-19 12:50:38 +00:00
|
|
|
struct buffer_packet bps[PACKET_BUFFER_SIZE];
|
2019-03-20 14:13:16 +00:00
|
|
|
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
|
2019-03-07 15:57:02 +00:00
|
|
|
};
|
|
|
|
|
2019-03-20 14:13:16 +00:00
|
|
|
void mv_buffer_rtow(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, struct evt_core_fdinfo* to);
|
2019-05-06 12:52:57 +00:00
|
|
|
void mv_buffer_rtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from);
|
2019-03-20 14:13:16 +00:00
|
|
|
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);
|
2019-05-13 16:37:49 +00:00
|
|
|
struct buffer_packet* dup_buffer_tow(struct algo_ctx* app_ctx, struct buffer_packet* bp, struct evt_core_fdinfo* to);
|
2019-05-24 13:51:49 +00:00
|
|
|
guint write_queue_len(struct algo_ctx *app_ctx, struct evt_core_fdinfo *fdinfo);
|
2019-03-20 14:13:16 +00:00
|
|
|
|
2019-05-14 09:23:23 +00:00
|
|
|
int append_buffer(union abstract_packet* dest, int pos, union abstract_packet* src);
|
2019-05-09 17:53:47 +00:00
|
|
|
|
2019-03-07 15:57:02 +00:00
|
|
|
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);
|
2019-03-20 14:13:16 +00:00
|
|
|
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);
|
|
|
|
|
2019-03-07 15:57:02 +00:00
|
|
|
void free_naive(void* app_ctx);
|
|
|
|
void free_nothing(void* app_ctx);
|
|
|
|
void naive_free_simple(void* v);
|