X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fevent.h;h=e2059d8e0ec75de5032e4ee131d83ed51f2cf2ed;hb=HEAD;hp=402d899c8e1f0a418bc50d839b16f794e1423d94;hpb=e442edb4d5816c4ad107ad9e71164f845eba70ad;p=debian%2Famanda diff --git a/common-src/event.h b/common-src/event.h index 402d899..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 @@ -43,13 +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. - * FIXME: THIS IS NOT 64-BIT CLEAN! + * 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. @@ -57,10 +61,8 @@ 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; /* @@ -84,6 +86,8 @@ typedef void (*event_fn_t)(void *); * caller calling event_loop() often enough. */ 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. @@ -91,19 +95,56 @@ event_handle_t *event_register(event_id_t, event_type_t, event_fn_t, void *); 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(event_id_t); /* - * Block until the event is terminated. + * 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. */ -int event_wait(event_handle_t *); +void event_wait(event_handle_t *evt); /* * Process events. If the argument is nonzero, then the loop does * not block. */ -void event_loop(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 */