Lay off the ground of our very efficient event loop.
[apps/madmutt.git] / lib-sys / evtloop.h
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or (at
5  *  your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful, but
8  *  WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15  *  MA 02110-1301, USA.
16  */
17 /*
18  *  Copyright © 2006 Pierre Habouzit
19  */
20
21 #ifndef MUTT_LIB_SYS_EVTLOOP_H
22 #define MUTT_LIB_SYS_EVTLOOP_H
23
24 #include <lib-lib/lib-lib.h>
25
26 typedef enum el_state {
27     EL_LLP_INIT,
28     EL_LLP_READY,
29     EL_LLP_FINI,
30 } el_state;
31
32 typedef enum el_mode {
33     EL_IDLE    = 0,
34     EL_READING = 1,
35     EL_WRITING = 2,
36     EL_RDWR    = 3,
37 } el_mode;
38
39 typedef enum el_status {
40     EL_SUCCESS,
41     EL_ERROR,
42     EL_KILLED,
43     EL_RDHUP,
44 } el_status;
45
46 typedef enum el_event {
47     EL_EVT_IN      = EL_READING,
48     EL_EVT_OUT     = EL_WRITING,
49     EL_EVT_INOUT   = EL_RDWR,
50     EL_EVT_RUNNING = 4,
51     EL_EVT_WAKEUP  = 5,
52 } el_event;
53
54 typedef struct job_t {
55     int fd;
56
57     el_state state : 2;
58     el_mode  mode  : 2;
59     el_mode  emode : 2;
60
61     int (*llp)(struct job_t *);
62     struct machine_t *m;
63     void *ptr;
64 } job_t;
65
66 typedef struct machine_t {
67     const char *name;
68     __must_check__ int (*setup)(job_t *w, void *);
69     int (*on_event)(job_t *w, el_event);
70     void (*finalize)(job_t *w, el_status);
71 } machine_t;
72
73 __must_check__ int el_job_release(job_t *j, el_status);
74 int el_dispatch(int timeout);
75
76 #endif