Event API

From wiki.zmanda.com
Jump to navigation Jump to search
Deprecated
The Event API is deprecated, and should not be used in new code. Use Glib's GMainLoop directly, instead. The Security API will continue to use the Event API for the forseeable future

Introduction

This is a document of the API for the event handler. The purpose of the event handler is to allow scheduling and serialization of multiple different types of events.

API

event_register

event_handle_t *event_register(event_id_t data, event_type_t type, event_fn_t callback, void *arg);

Sets up an event of the given type to call the given function with the given argument.

The 'data' argument is type specific.

EV_READFD, EV_WRITEFD - the file descriptor to monitor EV_SIG - the signal number to monitor EV_TIME - the number of seconds between each pulse EV_WAIT - the wait identifier used with event_wakeup() EV_DEAD - internal use only

event_release

void event_release(event_handle_t *handle);

Remove an event from the queue. This can happen at any time, even while the event is firing.

event_loop

void event_loop(int dontblock);

Process all pending events. If the argument is zero, this will keep running until all events have been released. If the argument is nonzero, this will do one pass over all pending events, and fire the ones that are immediately ready, and then return.

event_wakeup

int event_wakeup(event_id_t id);

Fire all EV_WAIT events registered with an argument value of 'id' immediately. Returns the number of events that were fired.

event_wait

void event_wait(event_id_t id);

Like event_loop(0), except that it will stop as soon as the event id is serviced.

Data types

event_handle_t

This is an opaque structure that describes a registered event. It is only useful to keep if you need to unregister the event later.

event_id_t

This is type-specific data. The contents and format depend on on the type of the event. This is an unsigned integral type.

event_type_t

This is an enumerated type describing the different events we handle.

event_fn_t

typedef void (*event_fn_t)(void *arg);

This is a function signature for the type of function that needs to get passed to event_register. The argument to the function is a pointer of the caller's choosing.

Event Types

EV_READFD

This type of event will fire when the file descriptor passed to event_register has data waiting to be read.

EV_WRITEFD

This type of event will fire when the file descriptor passed to event_register can have data written to it without blocking.

EV_SIG

This type of event will fire when the signal number passed to event_register has been caught. Note that if a signal is caught while processing is not in event_loop(), the event will be delayed until processing returns to event_loop(). EV_SIG is no longer supported.

EV_TIME

This type of event will fire repeatedly with a delay of the number of seconds passed to event_register between each interval.

EV_WAIT

This type of event will fire when someone calls event_wakeup() with the numeric argument equal to the argument this event was registered with.