2 * Sherlock Library -- Main Loop
4 * (c) 2004 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
10 #include "lib/clists.h"
12 extern sh_time_t now; /* Current time */
13 extern uns main_shutdown;
15 /* User-defined fields are marked with [*], all other fields must be initialized to zero. */
22 void (*handler)(struct main_timer *tm); /* [*] Function to be called when the timer expires. Must re-add/del the timer.*/
23 void *data; /* [*] Data for use by the handler */
26 void timer_add(struct main_timer *tm, sh_time_t expires); /* Can modify a running timer, too */
27 void timer_del(struct main_timer *tm);
33 int fd; /* [*] File descriptor */
34 int (*read_handler)(struct main_file *fi); /* [*] To be called when ready for reading/writing; must call file_chg() afterwards */
35 int (*write_handler)(struct main_file *fi);
36 void (*error_handler)(struct main_file *fi, int cause); /* [*] Handler to call on errors */
37 void *data; /* [*] Data for use by the handlers */
38 byte *rbuf; /* Read/write pointers for use by file_read/write */
42 void (*read_done)(struct main_file *fi); /* [*] Called when file_read is finished; rpos < rlen if EOF */
43 void (*write_done)(struct main_file *fi); /* [*] Called when file_write is finished */
44 struct main_timer timer;
45 struct pollfd *pollfd;
48 enum main_file_err_cause {
54 void file_add(struct main_file *fi);
55 void file_chg(struct main_file *fi);
56 void file_del(struct main_file *fi);
57 void file_read(struct main_file *fi, byte *buf, uns len);
58 void file_write(struct main_file *fi, byte *buf, uns len);
59 void file_set_timeout(struct main_file *fi, sh_time_t expires);
61 /* Hooks to be called in each iteration of the main loop */
65 int (*handler)(struct main_hook *ho); /* [*] Hook function; returns 1 if should be called again */
66 void *data; /* [*] For use by the handler */
69 void hook_add(struct main_hook *ho);
70 void hook_del(struct main_hook *ho);
72 /* Processes to watch */
77 int status; /* Exit status */
78 void (*handler)(struct main_process *mp); /* [*] Called when the process exits; process_del done automatically */
79 void *data; /* [*] For use by the handler */
82 void process_add(struct main_process *mp);
83 void process_del(struct main_process *mp);
84 int process_fork(struct main_process *mp);
90 void main_debug(void);