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