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
51 typedef unsigned long event_id_t;
54 * The types of events we can register.
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 */
66 * The function signature for functions that get called when an event
69 typedef void (*event_fn_t)(void *);
72 * Register an event handler.
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.
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?)
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.
85 event_handle_t *event_register(event_id_t, event_type_t, event_fn_t, void *);
88 * Release an event handler.
90 void event_release(event_handle_t *);
93 * Wake up all EV_WAIT events waiting on a specific id
95 int event_wakeup(event_id_t);
98 * Block until the event is terminated.
100 int event_wait(event_handle_t *);
103 * Process events. If the argument is nonzero, then the loop does
106 void event_loop(const int);