#ifndef _MAINLOOP_H #define _MAINLOOP_H #include #include "jobqueue.h" #include "epoll.h" typedef struct MainLoop MainLoop; typedef void (* MainFdFunc) (int fd, EPollEventType mask, gpointer data); MainLoop *main_loop_new (Executor *executor); Executor *main_loop_get_executor (MainLoop *loop); void main_loop_add_fd (MainLoop *loop, int fd, JobQueue *queue, MainFdFunc func, gpointer data); void main_loop_set_fd_poll_mask (MainLoop *loop, int fd, EPollEventType poll_mask); void main_loop_remove_fd (MainLoop *loop, int fd); /* Missing: */ /* Maybe these functions really belong in the JobQueue? * That would require support from the executor though. * But fundamentally these are valid (in a threaded server) * without fds, which is what the main loop provides. * The executor already has a gcond_wait() that could be * made a timed one. * * Note that a good priority queue is going to be needed in * whatever class eventually implements these. * * Also, note that cancellation support is essential for these * tasks. * * Yes, should probably happen in JobQueue + Executor: * * executor should maintain all jobs in a priority queue * sorted by execution time. * * normal jobs get an execution time of "now", where timeout * jobs get an execution of sometime in the future. * * this avoids starvation of timeouts since a timeout will * eventually move to the front of the queue (with a time * in the past possibly) * * * */ #if 0 void main_loop_add_timeout (MainLoop *loop, JobQueue *queue, MainFunc *task); void main_loop_add_idle (MainLoop *loop, JobQueue *queue, MainFunc *task); #endif #endif /* _MAINLOO_H_ */