367f3b513e04085fdd87f869bba6b08066079511
[debian/amanda] / common-src / event.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1999 University of Maryland at College Park
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of U.M. not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  U.M. makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Authors: the Amanda Development Team.  Its members are listed in a
24  * file named AUTHORS, in the root directory of this distribution.
25  */
26 /*
27  * $Id: event.h,v 1.6 2005/11/30 22:35:11 martinea Exp $
28  */
29 #ifndef EVENT_H
30 #define EVENT_H
31
32 /*
33  * These functions define a generic event interface.  One can register a
34  * function vector and the type of events to act on, and the event handler
35  * will dispatch as necessary.
36  */
37
38 /*
39  * An opaque handle returned by the registry functions that can be
40  * used to unregister an event in the future.
41  */
42 struct event_handle;
43 typedef struct event_handle event_handle_t;
44
45 /*
46  * The 'id' of the event.  The meaning of this is dependant on the type
47  * of event we are registering.  This is hopefully wide enough that
48  * callers can cast pointers to it and keep the value untruncated and
49  * unique.
50  */
51 typedef unsigned long event_id_t;
52
53 /*
54  * The types of events we can register.
55  */
56 typedef enum {
57     EV_READFD,                  /* file descriptor is ready for reading */
58     EV_WRITEFD,                 /* file descriptor is ready for writing */
59     EV_SIG,                     /* signal has fired */
60     EV_TIME,                    /* n seconds have elapsed */
61     EV_WAIT,                    /* event_wakeup() was called with this id */
62     EV_DEAD                     /* internal use only */
63 } event_type_t;
64
65 /*
66  * The function signature for functions that get called when an event
67  * fires.
68  */
69 typedef void (*event_fn_t) P((void *));
70
71 /*
72  * Register an event handler.
73  *
74  * For readfd and writefd events, the first arg is the file descriptor.
75  * There can be multiple callers firing on the same file descriptor.
76  *
77  * For signal events, the first arg is the signal number as defined in
78  * <signal.h>.  There can only be one signal handler. (do we need more?)
79  *
80  * For time events, the first arg is the interval in seconds between
81  * pulses.  There can be multiple time events, of course.  Don't
82  * count on the time events being too accurate.  They depend on the
83  * caller calling event_loop() often enough.
84  */
85 event_handle_t *event_register P((event_id_t, event_type_t,
86     event_fn_t, void *));
87
88 /*
89  * Release an event handler.
90  */
91 void event_release P((event_handle_t *));
92
93 /*
94  * Wake up all EV_WAIT events waiting on a specific id
95  */
96 int event_wakeup P((event_id_t));
97
98 /*
99  * Process events.  If the argument is nonzero, then the loop does
100  * not block.
101  */
102 void event_loop P((const int));
103
104 #endif  /* EVENT_H */