// SIMPLE FILE DESCRIPTOR // #ifndef FD_H #define FD_H #include #include #include "fifo.h" #include "ringbuffer.h" /* typedef struct { int(* seek)(int offset, int whence); int(* read)(char *buf, int len); int(* wrtie)(char *buf, int len); int(* close)(); int(* stat)(void *buf); void *data; //opaque }file; */ enum FD_TYPE{ FD_TYPE_FIFO_BUFFERED=1, FD_TYPE_EXT2_FILE=2, FD_TYPE_EXT2_DIR=3, FD_TYPE_SYSFS=4 }; typedef struct fd_struct { bool (*write)(struct fd_struct*,uint8_t); uint8_t (*read)(struct fd_struct*); bool (*has)(struct fd_struct*); bool (*eof)(struct fd_struct*); bool (*close)(struct fd_struct*); uint8_t type; void *data; // opaque data }fd; uint8_t fd_read(fd*); bool fd_has(fd*); bool fd_eof(fd*); bool fd_write(fd*,uint8_t); bool fd_close(fd*); fd fd_from_fifo(fifo* f); fd fd_from_path(char *path); fd fd_from_sysfs(void(*g)(ringbuffer *r,void (*f)(ringbuffer *r,char *fmt, ...))); #endif