/* evlist/evlist.h * * File/timed event list system. * * Copyright (C) 2003, 2004 * Andy Goth * * This code is available under the GNU General Public License; see COPYING. */ #ifndef SEEN_EVLIST_EVLIST_H #define SEEN_EVLIST_EVLIST_H #include #include #include #include "prjlibs/vec.h" typedef unsigned char byte_t; typedef struct pollfd pollfd_t; typedef struct timeval timeval_t; typedef int (*schedcb_t)(void*); struct sched ; typedef struct sched sched_t ; struct evlist; typedef struct evlist evlist_t; struct device; typedef struct device device_t; struct sched { timeval_t time; schedcb_t func; void* arg ; unsigned int id; }; struct evlist { VEC_T(device_t*) devices ; VEC_T(pollfd_t ) pollfds ; VEC_T(sched_t ) scheds ; unsigned int sched_id ; int loop_exit; }; struct device { char* name; char* path; int buf_cursor; int buf_size; VEC_T(byte_t) buf_in; VEC_T(byte_t) buf_out; evlist_t* evlist; pollfd_t* pollfd_in; pollfd_t* pollfd_out; void* hw_state; int (*hw_cleanup )(device_t*); int (*hw_open )(device_t*); int (*hw_close )(device_t*); int (*hw_readable)(device_t*); int (*hw_writable)(device_t*); void* sw_state; int (*sw_cleanup )(device_t*); int (*sw_open )(device_t*); int (*sw_close )(device_t*); int (*sw_incoming)(device_t*); int (*sw_outgoing)(device_t*); }; extern int evlist_init (evlist_t* el); extern int evlist_cleanup (evlist_t* el); extern int evlist_device_add (evlist_t* el, device_t* dev); extern int evlist_device_del (evlist_t* el, device_t* dev); extern int evlist_sched_add (evlist_t* el, int time, schedcb_t func, void* arg, unsigned int* id); extern int evlist_sched_del (evlist_t* el, unsigned int id); extern int evlist_loop (evlist_t* el); extern int evlist_loop_next (evlist_t* el, int timeout); extern int evlist_loop_exit (evlist_t* el); extern int device_init (device_t* dev, char* name); extern int device_cleanup (device_t* dev); extern int device_attach_fd (device_t* dev, int fd, int mode); extern int device_detatch_fd (device_t* dev, int mode); extern int device_readable (device_t* dev); extern int device_writable (device_t* dev); extern int device_sendf (device_t* dev, char* fmt, ...); extern int child_init (device_t* dev, char* cmd, char** envp, int mode); extern int fd_init (device_t* dev, char* path, int fd_in, int fd_out); extern int null_init (device_t* dev); extern int serial_init (device_t* dev, char* path, int data_bits, int stop_bits, int parity, int baud_rate, int sw_flow_ctrl, int hw_flow_ctrl); #endif /* vim: set ts=4 sts=4 sw=4 tw=80 et: */