Line data Source code
1 : #ifndef _SENTINEL_MINIPOT_PIPE_HANDLER_H_ 2 : #define _SENTINEL_MINIPOT_PIPE_HANDLER_H_ 3 : 4 : #include <stdint.h> 5 : #include <string.h> 6 : 7 : struct minipot_pipe_handler; 8 : typedef struct minipot_pipe_handler* minipot_pipe_handler_t; 9 : 10 : typedef void (*minipot_pipe_callback)(uint8_t *payload, size_t payload_len, 11 : void *data); 12 : 13 : // Frees an instance. 14 0 : void minipot_pipe_handler_free(minipot_pipe_handler_t) __attribute__((nonnull)); 15 : 16 : // Allocates a new instance. If it fails returns NULL. 17 : // User provided callback with user provided data and received data is invoked 18 : // after every sucessfull receive from pipe. 19 0 : minipot_pipe_handler_t minipot_pipe_handler_new(int read_end_fd, 20 : minipot_pipe_callback cb, void *data) 21 : __attribute__((nonnull(2), malloc)); 22 : 23 : // Starts an event loop - starts handling events - read, SIGINT, SIGTERM. 24 : // Returns 0 if successful, -1 if an error occurred, 25 : // or 1 if no events were pending or active. 26 0 : int minipot_pipe_handler_run(minipot_pipe_handler_t) __attribute__((nonnull)); 27 : 28 : // Stops event loop - stops handling events. Returns 0 if successful otherwise -1. 29 0 : int minipot_pipe_handler_stop(minipot_pipe_handler_t) __attribute__((nonnull)); 30 : 31 : #endif