more job functions
[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_NEW     = 0,
34     EL_READING = 1,
35     EL_WRITING = 2,
36     EL_RDWR    = 3,
37     EL_IDLE    = 4,
38 } el_mode;
39
40 typedef enum el_status {
41     EL_SUCCESS,
42     EL_ERROR,
43     EL_KILLED,
44     EL_RDHUP,
45 } el_status;
46
47 typedef enum el_event {
48     EL_EVT_IN      = EL_READING,
49     EL_EVT_OUT     = EL_WRITING,
50     EL_EVT_INOUT   = EL_RDWR,
51     EL_EVT_RUNNING = 4,
52     EL_EVT_WAKEUP  = 5,
53 } el_event;
54
55 typedef struct job_t {
56     int fd;
57
58     el_state state : 2;
59     el_mode  mode  : 3;
60     el_mode  emode : 3;
61
62     int (*llp)(struct job_t *);
63     struct machine_t *m;
64     void *ptr;
65 } job_t;
66 DO_INIT(job_t, job);
67 DO_WIPE(job_t, job);
68 DO_NEW(job_t, job);
69 DO_DELETE(job_t, job);
70
71 typedef struct machine_t {
72     const char *name;
73     __must_check__ int (*setup)(job_t *w, void *);
74     int (*on_event)(job_t *w, el_event);
75     void (*finalize)(job_t *w, el_status);
76 } machine_t;
77
78 __must_check__ int el_job_setmode(job_t *w, el_mode);
79 __must_check__ int el_job_release(job_t *j, el_status);
80 __must_check__ int el_job_connect(job_t *w, struct sockaddr *, socklen_t len,
81                                   int type, int proto);
82
83 int el_dispatch(int timeout);
84
85 #endif