X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fevent.h;h=e2059d8e0ec75de5032e4ee131d83ed51f2cf2ed;hb=d28952249e392eb31bc8eecc53f6c477f30c617b;hp=367f3b513e04085fdd87f869bba6b08066079511;hpb=1194fb66aa28d9929c3f2bef3cc6c1c3f40a60a4;p=debian%2Famanda diff --git a/common-src/event.h b/common-src/event.h index 367f3b5..e2059d8 100644 --- a/common-src/event.h +++ b/common-src/event.h @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1999 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -24,7 +25,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: event.h,v 1.6 2005/11/30 22:35:11 martinea Exp $ + * $Id: event.h,v 1.9 2006/06/16 10:55:05 martinea Exp $ */ #ifndef EVENT_H #define EVENT_H @@ -43,12 +44,16 @@ struct event_handle; typedef struct event_handle event_handle_t; /* - * The 'id' of the event. The meaning of this is dependant on the type - * of event we are registering. This is hopefully wide enough that - * callers can cast pointers to it and keep the value untruncated and - * unique. + * The 'id' of the event. The meaning of this depends on the type of + * event we are registering -- see event_register. The name 'id' is + * historical: it is quite possible to have many outstanding events with + * the same ID (same timeout or same file descriptor). + * + * Event id's are supplied by the caller, and in some cases are cast from + * pointers, so this value must be wide enough to hold a pointer without + * truncation. */ -typedef unsigned long event_id_t; +typedef intmax_t event_id_t; /* * The types of events we can register. @@ -56,17 +61,15 @@ typedef unsigned long event_id_t; typedef enum { EV_READFD, /* file descriptor is ready for reading */ EV_WRITEFD, /* file descriptor is ready for writing */ - EV_SIG, /* signal has fired */ EV_TIME, /* n seconds have elapsed */ EV_WAIT, /* event_wakeup() was called with this id */ - EV_DEAD /* internal use only */ } event_type_t; /* * The function signature for functions that get called when an event * fires. */ -typedef void (*event_fn_t) P((void *)); +typedef void (*event_fn_t)(void *); /* * Register an event handler. @@ -82,23 +85,66 @@ typedef void (*event_fn_t) P((void *)); * count on the time events being too accurate. They depend on the * caller calling event_loop() often enough. */ -event_handle_t *event_register P((event_id_t, event_type_t, - event_fn_t, void *)); +event_handle_t *event_register(event_id_t, event_type_t, event_fn_t, void *); +event_handle_t *event_create(event_id_t, event_type_t, event_fn_t, void *); +void event_activate(event_handle_t *); /* * Release an event handler. */ -void event_release P((event_handle_t *)); +void event_release(event_handle_t *); /* - * Wake up all EV_WAIT events waiting on a specific id + * Wake up all EV_WAIT events waiting on a specific id. This happens immediately, + * not in the next iteration of the event loop. If callbacks made during the wakeup + * register a new event with the same ID, that new event will *not* be awakened. */ -int event_wakeup P((event_id_t)); +int event_wakeup(event_id_t); + +/* + * Call event_loop, returning when one of the following conditions is + * true: + * evt is EV_WAIT, and it is released; or + * evt is EV_READFD, EV_WRITEFD, or EV_TIME, and it is fired. + */ +void event_wait(event_handle_t *evt); /* * Process events. If the argument is nonzero, then the loop does * not block. */ -void event_loop P((const int)); +void event_loop(int nonblock); + +/* + * Get the default GMainLoop object. Applications which use the Glib + * main loop directly should use this object for calls to e.g., + * g_main_loop_run(loop). + */ +GMainLoop *default_main_loop(void); + +/* + * Utility GSources + */ + +/* Create a GSource that will callback when the given file descriptor is in + * any of the given conditions. The callback is a simple GSourceFunc. + * + * @param fd: the file descriptr + * @param events: the conditions (GIOCondition flags) + * @return: GSource object + */ +GSource * new_fdsource(gint fd, GIOCondition events); + +/* Create a GSource that will callback when the given child dies. The callback + * should match ChildWatchFunc. Once the callback is made, it will not be called + * again by this source. + * + * Note: This is provided by glib in later versions, but not in version 2.2.0. + * This function and callback is modeled on g_child_watch_source_new. + * + * @param pid: the process ID @return: GSource object + */ +typedef void (*ChildWatchFunc)(pid_t pid, gint status, gpointer data); +GSource * new_child_watch_source(pid_t pid); #endif /* EVENT_H */