X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fmainloop.h;h=136d90e04858c1c3b4112c41d8c21dd9c53475d4;hb=d5e8872563f6fde8299db971ffb6494c2438c590;hp=24e2377e8f37205697508bda74c4568f2ed2d72c;hpb=cad27e97e6370f96903d42aaf345c099af0a03bd;p=libucw.git diff --git a/lib/mainloop.h b/lib/mainloop.h index 24e2377e..136d90e0 100644 --- a/lib/mainloop.h +++ b/lib/mainloop.h @@ -1,15 +1,19 @@ /* * UCW Library -- Main Loop * - * (c) 2004 Martin Mares + * (c) 2004--2005 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. */ +#ifndef _UCW_MAINLOOP_H +#define _UCW_MAINLOOP_H + #include "lib/clists.h" -extern sh_time_t now; /* Current time */ +extern timestamp_t main_now; /* Current time in milliseconds since UNIX epoch */ +extern sh_time_t main_now_seconds; /* Current time in seconds since the epoch */ extern uns main_shutdown; extern clist main_timer_list, main_file_list, main_hook_list, main_process_list; @@ -19,14 +23,16 @@ extern clist main_timer_list, main_file_list, main_hook_list, main_process_list; struct main_timer { cnode n; - sh_time_t expires; + timestamp_t expires; void (*handler)(struct main_timer *tm); /* [*] Function to be called when the timer expires. Must re-add/del the timer.*/ void *data; /* [*] Data for use by the handler */ }; -void timer_add(struct main_timer *tm, sh_time_t expires); /* Can modify a running timer, too */ +void timer_add(struct main_timer *tm, timestamp_t expires); /* Can modify a running timer, too */ void timer_del(struct main_timer *tm); +void main_get_time(void); /* Refresh main_now */ + /* Files to poll */ struct main_file { @@ -57,16 +63,24 @@ void file_chg(struct main_file *fi); void file_del(struct main_file *fi); void file_read(struct main_file *fi, void *buf, uns len); void file_write(struct main_file *fi, void *buf, uns len); -void file_set_timeout(struct main_file *fi, sh_time_t expires); +void file_set_timeout(struct main_file *fi, timestamp_t expires); +void file_close_all(void); /* Close all known main_file's; frequently used before fork() */ /* Hooks to be called in each iteration of the main loop */ struct main_hook { cnode n; - int (*handler)(struct main_hook *ho); /* [*] Hook function; returns 1 if should be called again */ + int (*handler)(struct main_hook *ho); /* [*] Hook function; returns HOOK_xxx */ void *data; /* [*] For use by the handler */ }; +enum main_hook_return { + HOOK_IDLE, /* Call again when the main loop becomes idle again */ + HOOK_RETRY, /* Call again as soon as possible */ + HOOK_DONE = -1, /* Shut down the main loop if all hooks return this value */ + HOOK_SHUTDOWN = -2 /* Shut down the main loop immediately */ +}; + void hook_add(struct main_hook *ho); void hook_del(struct main_hook *ho); @@ -90,3 +104,5 @@ int process_fork(struct main_process *mp); void main_init(void); void main_loop(void); void main_debug(void); + +#endif