Loading minui/events.c +22 −3 Original line number Original line Diff line number Diff line Loading @@ -25,17 +25,19 @@ #include "minui.h" #include "minui.h" #define MAX_DEVICES 16 #define MAX_DEVICES 16 #define MAX_MISC_FDS 16 struct fd_info { struct fd_info { ev_callback cb; ev_callback cb; void *data; void *data; }; }; static struct pollfd ev_fds[MAX_DEVICES]; static struct pollfd ev_fds[MAX_DEVICES + MAX_MISC_FDS]; static struct fd_info ev_fdinfo[MAX_DEVICES]; static struct fd_info ev_fdinfo[MAX_DEVICES + MAX_MISC_FDS]; static unsigned ev_count = 0; static unsigned ev_count = 0; static unsigned ev_dev_count = 0; static unsigned ev_dev_count = 0; static unsigned ev_misc_count = 0; int ev_init(ev_callback input_cb, void *data) int ev_init(ev_callback input_cb, void *data) { { Loading @@ -56,18 +58,35 @@ int ev_init(ev_callback input_cb, void *data) ev_fdinfo[ev_count].cb = input_cb; ev_fdinfo[ev_count].cb = input_cb; ev_fdinfo[ev_count].data = data; ev_fdinfo[ev_count].data = data; ev_count++; ev_count++; if(ev_count == MAX_DEVICES) break; ev_dev_count++; if(ev_dev_count == MAX_DEVICES) break; } } } } return 0; return 0; } } int ev_add_fd(int fd, ev_callback cb, void *data) { if (ev_misc_count == MAX_MISC_FDS || cb == NULL) return -1; ev_fds[ev_count].fd = fd; ev_fds[ev_count].events = POLLIN; ev_fdinfo[ev_count].cb = cb; ev_fdinfo[ev_count].data = data; ev_count++; ev_misc_count++; return 0; } void ev_exit(void) void ev_exit(void) { { while (ev_count > 0) { while (ev_count > 0) { close(ev_fds[--ev_count].fd); close(ev_fds[--ev_count].fd); } } ev_misc_count = 0; ev_dev_count = 0; } } int ev_wait(int timeout) int ev_wait(int timeout) Loading minui/minui.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -49,6 +49,7 @@ typedef int (*ev_callback)(int fd, short revents, void *data); int ev_init(ev_callback input_cb, void *data); int ev_init(ev_callback input_cb, void *data); void ev_exit(void); void ev_exit(void); int ev_add_fd(int fd, ev_callback cb, void *data); /* timeout has the same semantics as for poll /* timeout has the same semantics as for poll * 0 : don't block * 0 : don't block Loading Loading
minui/events.c +22 −3 Original line number Original line Diff line number Diff line Loading @@ -25,17 +25,19 @@ #include "minui.h" #include "minui.h" #define MAX_DEVICES 16 #define MAX_DEVICES 16 #define MAX_MISC_FDS 16 struct fd_info { struct fd_info { ev_callback cb; ev_callback cb; void *data; void *data; }; }; static struct pollfd ev_fds[MAX_DEVICES]; static struct pollfd ev_fds[MAX_DEVICES + MAX_MISC_FDS]; static struct fd_info ev_fdinfo[MAX_DEVICES]; static struct fd_info ev_fdinfo[MAX_DEVICES + MAX_MISC_FDS]; static unsigned ev_count = 0; static unsigned ev_count = 0; static unsigned ev_dev_count = 0; static unsigned ev_dev_count = 0; static unsigned ev_misc_count = 0; int ev_init(ev_callback input_cb, void *data) int ev_init(ev_callback input_cb, void *data) { { Loading @@ -56,18 +58,35 @@ int ev_init(ev_callback input_cb, void *data) ev_fdinfo[ev_count].cb = input_cb; ev_fdinfo[ev_count].cb = input_cb; ev_fdinfo[ev_count].data = data; ev_fdinfo[ev_count].data = data; ev_count++; ev_count++; if(ev_count == MAX_DEVICES) break; ev_dev_count++; if(ev_dev_count == MAX_DEVICES) break; } } } } return 0; return 0; } } int ev_add_fd(int fd, ev_callback cb, void *data) { if (ev_misc_count == MAX_MISC_FDS || cb == NULL) return -1; ev_fds[ev_count].fd = fd; ev_fds[ev_count].events = POLLIN; ev_fdinfo[ev_count].cb = cb; ev_fdinfo[ev_count].data = data; ev_count++; ev_misc_count++; return 0; } void ev_exit(void) void ev_exit(void) { { while (ev_count > 0) { while (ev_count > 0) { close(ev_fds[--ev_count].fd); close(ev_fds[--ev_count].fd); } } ev_misc_count = 0; ev_dev_count = 0; } } int ev_wait(int timeout) int ev_wait(int timeout) Loading
minui/minui.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -49,6 +49,7 @@ typedef int (*ev_callback)(int fd, short revents, void *data); int ev_init(ev_callback input_cb, void *data); int ev_init(ev_callback input_cb, void *data); void ev_exit(void); void ev_exit(void); int ev_add_fd(int fd, ev_callback cb, void *data); /* timeout has the same semantics as for poll /* timeout has the same semantics as for poll * 0 : don't block * 0 : don't block Loading