Updated source file headers with new year and no CVS Id.
[pazpar2-moved-to-github.git] / src / eventl.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2008 Index Data
3
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #ifndef EVENTL_H
21 #define EVENTL_H
22
23 #include <time.h>
24
25 struct iochan;
26
27 typedef void (*IOC_CALLBACK)(struct iochan *i, int event);
28
29 typedef struct iochan
30 {
31     int fd;
32     int flags;
33 #define EVENT_INPUT     0x01
34 #define EVENT_OUTPUT    0x02
35 #define EVENT_EXCEPT    0x04
36 #define EVENT_TIMEOUT   0x08
37 #define EVENT_WORK      0x10
38     int force_event;
39     IOC_CALLBACK fun;
40     void *data;
41     int destroyed;
42     time_t last_event;
43     time_t max_idle;
44     
45     struct iochan *next;
46 } *IOCHAN;
47
48 #define iochan_destroy(i) (void)((i)->destroyed = 1)
49 #define iochan_getfd(i) ((i)->fd)
50 #define iochan_setfd(i, f) ((i)->fd = (f))
51 #define iochan_getdata(i) ((i)->data)
52 #define iochan_setdata(i, d) ((i)->data = d)
53 #define iochan_getflags(i) ((i)->flags)
54 #define iochan_setflags(i, d) ((i)->flags = d)
55 #define iochan_setflag(i, d) ((i)->flags |= d)
56 #define iochan_clearflag(i, d) ((i)->flags &= ~(d))
57 #define iochan_getflag(i, d) ((i)->flags & d ? 1 : 0)
58 #define iochan_getfun(i) ((i)->fun)
59 #define iochan_setfun(i, d) ((i)->fun = d)
60 #define iochan_setevent(i, e) ((i)->force_event = (e))
61 #define iochan_getnext(i) ((i)->next)
62 #define iochan_settimeout(i, t) ((i)->max_idle = (t), (i)->last_event = time(0))
63 #define iochan_activity(i) ((i)->last_event = time(0))
64
65 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags);
66 int event_loop(IOCHAN *iochans);
67
68 #endif