Event management


Compounds

struct  event
struct  event_callout
struct  event_def

Typedefs

typedef event_def * event_type
typedef event event
typedef event_callout event_callout
typedef void(* event_handler_t )(event_callout *, event *)

Functions

void event_initialize (event *queue, unsigned short size)
void event_post (event_type type, unsigned short data)
void event_add_callout (event_type type, event_callout *callout)
void event_remove_callout (event_callout *callout)
void event_register (event_type type, event_callout *callout, event_handler_t handler, void *client_data)
void event_unregister (event_callout *)
void event_loop (unsigned long tick, unsigned char *bool)
void event_wait (unsigned long nticks, event_type type)

Variables

unsigned long event_idle_counter
unsigned char event_false

Detailed Description

This module is a small event manager. It contains a queue of events and allows other modules to subscribe to a particular event type.

Subscribing to an event means connecting a callout object to the event type. The callout contains a function which is called by the event manager when an event of the corresponding type is received. The callout object should be a static object. It should be registered only once with the event_register method.

Posting an event is an asynchronous operation which does not block. The event is marked with a time stamp and inserted in the event queue. The event is posted using the event_post function.

The event manager does not use threads to report events to its subscribers. It is necessary to call explicitly the event manager so that it dispatches the pending events.

Function Documentation

void event_add_callout event_type    type,
event_callout *    callout
 

Register an event handler.

Register an handler to receive events of a given type.

Parameters:
type  the type of the event to subscribe
callout 
handler  operation to be called when the event is received
client_data  specifies the argument of the handler

void event_initialize event   queue,
unsigned short    size
 

Initialize the event package.

The event buffer queue is passed in 'queue' and it can contain up to 'size' events. Initialization should be done only once and before using any other event method.

Parameters:
queue  the event buffer queue
size  the size in element of that buffer
See also:
event_post

void event_post event_type    type,
unsigned short    data
 

Post an event.

An event of the specified type is queued at the end of the event queue. The event queue contains a fixed number of elements. It does not grow. If the event queue was full, the oldest event is forgotten. The event is marked with the free running timer counter. This operation is designed to be efficient and can be called from an interrupt handler. When the event is queued, the data parameter is saved with it. This value is not interpreted and can be used to pass some additional information related to the event itself.

Events are dispatched synchronously by `event_dispatch' which activates the handlers that were registered.

Parameters:
type  the type of the event
data  the data value associated with the event
See also:
event_initialize, event_register, event_dispatch

void event_register event_type    type,
event_callout *    callout,
event_handler_t    handler,
void *    client_data
[inline]
 

Register an event handler.

Register an handler to receive events of a given type.

Parameters:
type  the type of the event to subscribe
callout 
handler  operation to be called when the event is received
client_data  specifies the argument of the handler

Definition at line 153 of file event.h.

void event_remove_callout event_callout *    callout
 

Remove an event callout.