Blame | Last modification | View Log | RSS feed
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>liboop: How?</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head><body>
<h2>Overview of liboop.</h2>
<h4>The basic idea.</h4>
Liboop is primarily an <em>interface definition</em>. It defines an interface
which components may use to request notification when an <em>event</em>
(activity on a file descriptor, the real-time clock reaches a certain value,
a particular signal is received) occurs. The component which owns the event
loop -- the component whose code is active when the system is idle --
implements the interface; it is an <em>event source</em>. Components which
are interested in events register themselves with the event source; they are
<em>event sinks</em>. Event sinks may themselves source other, higher-level
events, but that is outside liboop's scope.
<h4>Control flow.</h4>
During initialization, the event source is created. At least one event sink
is also created, and registered with the event source. Once initialization
completes, control is transferred to the event source, which (at its core)
waits for events, usually using a system function like select() or poll().
When an event occurs, the event source gives a <em>callback</em> to all the
event sinks which registered interest in that event.
<p>
During callbacks, the event sinks react to the event as appropriate (usually
performing some I/O, or at least modifying internal state). Event sinks for
events which are no longer relevant may be unregistered; new event sinks may
be registered for additional events. Each event sink, when it finishes,
returns a value which tells the event source whether to continue processing
events or whether to terminate.
<p>
While the event source must be fully reentrant (registration and deregistration
may, and indeed usually are, performed within the context of an event), event
sinks need not be; no event sink will be called while another event sink is
active.
<p>
If no event sink instructs the event source to terminate, the event source
continues waiting for events. Otherwise, the event source returns to its
caller, which usually shuts down the system.
<h4>The system event source.</h4>
Liboop comes with a single "reference" implementation of an event source.
This event source uses select() to dispatch events. Most programs built
around liboop will probably use the standard system event source; legacy
programs with their own event loop, or programs with specialized needs may
implement their own event source.
<h4>Adapters.</h4>
Liboop supports <em>adapters</em> to enable legacy components to use the liboop
interface. For example, many widget sets have their own event loop and their
own mechanism for registering callbacks on timeouts and file descriptor
activity; liboop uses <em>source adapters</em> that accept registration,
register corresponding callbacks with the widget set's event loop, and route
events appropriately. Such adapters let general-purpose liboop-based
components work in an application based on that widget set.
<p>
Similarly, some components are designed to work in a non-blocking fashion, and
they might be used with a <em>sink adapter</em> to work with liboop. An
asynchronous DNS query package, for example, could work as a liboop sink that
ultimately generates a higher-level "success" or "failure" callback to the
invoking routine.
<h4>Code.</h4>
Liboop's abstract event source interface is implemented as a structure
containing C function pointers. These functions accept a pointer to the
structure as their first argument; sources are expected to include their
own data (in whatever format) with the core function pointers. Callbacks
are also C function pointers, with "void *" arguments to pass data.
<p>
For more about the liboop interface, see the <a href="ref">reference</a>.
<hr><a href="">liboop home</a></body></html>