Blame common-src/event.h

Packit Service 392537
/*
Packit Service 392537
 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
Packit Service 392537
 * Copyright (c) 1999 University of Maryland at College Park
Packit Service 392537
 * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
Packit Service 392537
 * Copyright (c) 2013-2016 Carbonite, Inc.  All Rights Reserved.
Packit Service 392537
 * All Rights Reserved.
Packit Service 392537
 *
Packit Service 392537
 * Permission to use, copy, modify, distribute, and sell this software and its
Packit Service 392537
 * documentation for any purpose is hereby granted without fee, provided that
Packit Service 392537
 * the above copyright notice appear in all copies and that both that
Packit Service 392537
 * copyright notice and this permission notice appear in supporting
Packit Service 392537
 * documentation, and that the name of U.M. not be used in advertising or
Packit Service 392537
 * publicity pertaining to distribution of the software without specific,
Packit Service 392537
 * written prior permission.  U.M. makes no representations about the
Packit Service 392537
 * suitability of this software for any purpose.  It is provided "as is"
Packit Service 392537
 * without express or implied warranty.
Packit Service 392537
 *
Packit Service 392537
 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
Packit Service 392537
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
Packit Service 392537
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
Packit Service 392537
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
Packit Service 392537
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
Packit Service 392537
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Packit Service 392537
 *
Packit Service 392537
 * Authors: the Amanda Development Team.  Its members are listed in a
Packit Service 392537
 * file named AUTHORS, in the root directory of this distribution.
Packit Service 392537
 */
Packit Service 392537
/*
Packit Service 392537
 * $Id: event.h,v 1.9 2006/06/16 10:55:05 martinea Exp $
Packit Service 392537
 */
Packit Service 392537
#ifndef EVENT_H
Packit Service 392537
#define EVENT_H
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * These functions define a generic event interface.  One can register a
Packit Service 392537
 * function vector and the type of events to act on, and the event handler
Packit Service 392537
 * will dispatch as necessary.
Packit Service 392537
 */
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * An opaque handle returned by the registry functions that can be
Packit Service 392537
 * used to unregister an event in the future.
Packit Service 392537
 */
Packit Service 392537
struct event_handle;
Packit Service 392537
typedef struct event_handle event_handle_t;
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * The 'id' of the event.  The meaning of this depends on the type of
Packit Service 392537
 * event we are registering -- see event_register.  The name 'id' is
Packit Service 392537
 * historical: it is quite possible to have many outstanding events with
Packit Service 392537
 * the same ID (same timeout or same file descriptor).
Packit Service 392537
 *
Packit Service 392537
 * Event id's are supplied by the caller, and in some cases are cast from
Packit Service 392537
 * pointers, so this value must be wide enough to hold a pointer without
Packit Service 392537
 * truncation.
Packit Service 392537
 */
Packit Service 392537
typedef	intmax_t event_id_t;
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * The types of events we can register.
Packit Service 392537
 */
Packit Service 392537
typedef enum {
Packit Service 392537
    EV_READFD,			/* file descriptor is ready for reading */
Packit Service 392537
    EV_WRITEFD,			/* file descriptor is ready for writing */
Packit Service 392537
    EV_TIME,			/* n seconds have elapsed */
Packit Service 392537
    EV_WAIT,			/* event_wakeup() was called with this id */
Packit Service 392537
} event_type_t;
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * The function signature for functions that get called when an event
Packit Service 392537
 * fires.
Packit Service 392537
 */
Packit Service 392537
typedef void (*event_fn_t)(void *);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Register an event handler.
Packit Service 392537
 *
Packit Service 392537
 * For readfd and writefd events, the first arg is the file descriptor.
Packit Service 392537
 * There can be multiple callers firing on the same file descriptor.
Packit Service 392537
 *
Packit Service 392537
 * For signal events, the first arg is the signal number as defined in
Packit Service 392537
 * <signal.h>.  There can only be one signal handler. (do we need more?)
Packit Service 392537
 *
Packit Service 392537
 * For time events, the first arg is the interval in seconds between
Packit Service 392537
 * pulses.  There can be multiple time events, of course.  Don't
Packit Service 392537
 * count on the time events being too accurate.  They depend on the
Packit Service 392537
 * caller calling event_loop() often enough.
Packit Service 392537
 */
Packit Service 392537
//event_handle_t *event_register(event_id_t, event_type_t, event_fn_t, void *);
Packit Service 392537
event_handle_t *event_create(event_id_t, event_type_t, event_fn_t, void *);
Packit Service 392537
void event_activate(event_handle_t *);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Release an event handler.
Packit Service 392537
 */
Packit Service 392537
void event_release(event_handle_t *);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Wake up all EV_WAIT events waiting on a specific id.  This happens immediately,
Packit Service 392537
 * not in the next iteration of the event loop.  If callbacks made during the wakeup
Packit Service 392537
 * register a new event with the same ID, that new event will *not* be awakened.
Packit Service 392537
 */
Packit Service 392537
int event_wakeup(event_id_t);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Call event_loop, returning when one of the following conditions is
Packit Service 392537
 * true:
Packit Service 392537
 *  evt is EV_WAIT, and it is released; or
Packit Service 392537
 *  evt is EV_READFD, EV_WRITEFD, or EV_TIME, and it is fired.
Packit Service 392537
 */
Packit Service 392537
void event_wait(event_handle_t *evt);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Process events.  If the argument is nonzero, then the loop does
Packit Service 392537
 * not block.
Packit Service 392537
 */
Packit Service 392537
void event_loop(int nonblock);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Process events, not even stopping when there are no more event API events
Packit Service 392537
 * left (there may be other GMainLoop events pending); similar to
Packit Service 392537
 * g_main_loop_run, but compatible with the event API.
Packit Service 392537
 */
Packit Service 392537
void event_loop_run(void);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Stop an event_loop_run invocation; similar to g_main_loop_quit, but
Packit Service 392537
 * compatible with the event API
Packit Service 392537
 */
Packit Service 392537
void event_loop_quit(void);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Get the default GMainLoop object.  Applications which use the Glib
Packit Service 392537
 * main loop directly should use this object for calls to e.g.,
Packit Service 392537
 * g_main_loop_run(loop).
Packit Service 392537
 */
Packit Service 392537
GMainLoop *default_main_loop(void);
Packit Service 392537
Packit Service 392537
/*
Packit Service 392537
 * Utility GSources
Packit Service 392537
 */
Packit Service 392537
Packit Service 392537
/* Create a GSource that will callback when the given file descriptor is in
Packit Service 392537
 * any of the given conditions.  The callback is a simple GSourceFunc.
Packit Service 392537
 *
Packit Service 392537
 * @param fd: the file descriptr
Packit Service 392537
 * @param events: the conditions (GIOCondition flags)
Packit Service 392537
 * @return: GSource object
Packit Service 392537
 */
Packit Service 392537
GSource * new_fdsource(gint fd, GIOCondition events);
Packit Service 392537
Packit Service 392537
/* Create a GSource that will callback when the given child dies.  The callback
Packit Service 392537
 * should match ChildWatchFunc.  Once the callback is made, it will not be called
Packit Service 392537
 * again by this source.
Packit Service 392537
 *
Packit Service 392537
 * Note: This is provided by glib in later versions, but not in version 2.2.0.
Packit Service 392537
 * This function and callback is modeled on g_child_watch_source_new.
Packit Service 392537
 *
Packit Service 392537
 * @param pid: the process ID @return: GSource object
Packit Service 392537
 */
Packit Service 392537
typedef void (*ChildWatchFunc)(pid_t pid, gint status, gpointer data); 
Packit Service 392537
GSource * new_child_watch_source(pid_t pid);
Packit Service 392537
Packit Service 392537
#endif	/* EVENT_H */