2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1999 University of Maryland at College Park
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.
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.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: event.h,v 1.9 2006/06/16 10:55:05 martinea Exp $
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.
39 * An opaque handle returned by the registry functions that can be
40 * used to unregister an event in the future.
43 typedef struct event_handle event_handle_t;
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
50 * FIXME: THIS IS NOT 64-BIT CLEAN!
52 typedef unsigned long event_id_t;
55 * The types of events we can register.
58 EV_READFD, /* file descriptor is ready for reading */
59 EV_WRITEFD, /* file descriptor is ready for writing */
60 EV_SIG, /* signal has fired */
61 EV_TIME, /* n seconds have elapsed */
62 EV_WAIT, /* event_wakeup() was called with this id */
63 EV_DEAD /* internal use only */
67 * The function signature for functions that get called when an event
70 typedef void (*event_fn_t)(void *);
73 * Register an event handler.
75 * For readfd and writefd events, the first arg is the file descriptor.
76 * There can be multiple callers firing on the same file descriptor.
78 * For signal events, the first arg is the signal number as defined in
79 * <signal.h>. There can only be one signal handler. (do we need more?)
81 * For time events, the first arg is the interval in seconds between
82 * pulses. There can be multiple time events, of course. Don't
83 * count on the time events being too accurate. They depend on the
84 * caller calling event_loop() often enough.
86 event_handle_t *event_register(event_id_t, event_type_t, event_fn_t, void *);
89 * Release an event handler.
91 void event_release(event_handle_t *);
94 * Wake up all EV_WAIT events waiting on a specific id
96 int event_wakeup(event_id_t);
99 * Block until the event is terminated.
101 int event_wait(event_handle_t *);
104 * Process events. If the argument is nonzero, then the loop does
107 void event_loop(const int);