1. Events design


1.1 Definitions

1.1.1 Event, Event data

An event is the fact that a certain point in the code and the value of certain variables, which are accessible at that point in the code for reading, is reached.  The content of these known variables is called the event data.

[--Example:

if (a >= 3 && a <= 4 && strcmp(s, "foobar"))
{
  handle_event(a, s); // Reaching this point means that the event happened.
                      // The `event data' is `a' and `s'.
}

--End of example]

1.1.2 Event type

An event type is the definition of the variables associated with an event, the event data, and the range of these variables.  This range may be limited to a part of the total variable space.

[--Example: In the above example, the event type is

int a;   // a == 3 || a == 4
char* s; // s is "bar" or "foo" or "barfoo" (determined by
         // previous code that lead to the event).

If `s' is known to have only a limited set of values, for instance "aaa", "bbb" or "ccc", then that is part of the event type too.

--End of example]

1.1.3 Event client

1.1.3.1

An event needs to be passed to zero or more objects by calling a method of those objects.  Those objects are called event clients.

1.1.3.2

All or a part of the event data may be needed to be passed to the event clients to describe the event.

[--Example:

if (3 < x && x < 7 && 9 < y && y < 20)
{
  cl_obj.event37920(x, y); // `cl_obj' is a `event client'.
}

--End of example]

1.1.3.3

No data is returned from the event clients.

1.1.3.4

An event is not dependant of the state of event client(s).

1.1.4 Event trigger

The member function call at the place in the code that signifies the event is called the event trigger.

[--Example:

if (3 < x && x > 7 && 9 < y && 20 > y)
{
  event_server.handle_event(EVENT_37920, x, y); // `handle_event' is the `event trigger'
}

--End of example]

1.1.5 Event generator

The object that calls the event trigger method is called the event generator.

1.1.6 Event server

The object that owns the event trigger method is the event server.

1.1.7 Busy interface

An event client can optionally pass a busy interface object along with its request for an event.

This busy interface object gets probed by the event server to see if the client is busy for that event type (it is possible to specify different busy interfaces per event request).

If the event client is not busy on that particular busy interface and an event occurs of that type, then the client must accept the event and process it immediately, before returning.  If the busy interface is marked busy it must queue the event and return immedeately.  Queued events must be processed immedeately as soon as the busy interface is marked not busy.

An event client is busy (for a given event type) in at least the following case: While processing an event (of that type).

1.1.8 Cookies

Cookies are arbitrary objects that can be passed along with a request and are passed back to the client when the event occurs.


1.2 Dependencies

1.2.1

An application is designed in the following chronological order and may therefore not have downwards dependencies (except virtual functions):

  1. This design

  2. Libcw interface

  3. Libcw implementation

  4. An application with for each event type:

    1. The event data object

    2. The event server, which owns the event trigger

    3. One or more event generators

    4. One or more event clients

A library would implement everything except the iv. (although example code of an event client should always be provided).

1.2.2

There is one event data class per event type.

1.2.3

There is one event server per event type.

1.2.4

There can be an arbitrary number of event generators per event type.

1.2.5

One event generator can contain an arbitrary number of event triggers of any event type (also more of the same type).

1.2.6

An event client can receive any number of events of any arbitary number of event types.  All events of the same type however, enter at the same point.

1.2.7

An event client can own an arbitrary number of busy interfaces.

1.3 Program Flow

The event client requests an event type by calling the request() method of the event server.  When that event occurs, the event generator passes the event data to the event server, which passes it on to all event clients that requested the event.  If a busy interface was passed along with the request, then the event server probes this busy interface to see if the client is busy.  If the client is busy, the busy interface queues the event and event data till it is not busy anymore.  Otherwise the event is passed directly to the client.


Copyright © 1999 Carlo Wood.  All rights reserved.