Event Handling Subsystem, version 2


Event Handling Subsystem version 2 (EHS) provides a generic API for passing arbitary objects from a source to one or more handlers without coupling neither the source and handlers, nor coupling either of those with the EHS.


The original Event Handling Subsystem (version 1) had a number of issues that made the subsystem inconvenient to use, errorpone and hard to debug. Namely, the syntax for postingevents and/or setting handlers was so inconvenient that we had to resort to preprocessor macros to compensate for that. In addition, the original engine was based on CBFunctor library, which dates back to 1994, and thus breaks on some modern compilers. Thus, the system was rewritten.


The requirements for EHSv2 are:


There are two common operations needed to be done when it comes to event tables usage - setting up event handlers, and posting events. In order to provide maximum simplicity for those operations, there are a set of utility methods (defined in EHS namespace) which simplify the syntax. The basic usage of EHS goes as follows:

 // Initialize objects. Note: the first event (posted in MySource
 // constructor) is not handled.
 MyHandler *h = new MyHandler;
 MySource *s = new MySource;
 // Set up handler, and post an event
 EHS::addHandler(s, h, &MyHandler::handlerfunc);
 EHS::postEvent(s, MyEvent("Hello world!"));