Extending EMan

The current event manager can be extended without having access to the source code. The use of EMan in an X or MOTIF application mentioned above is just one such example. Several other extensions are possible. For example, new event types can be defined by subclassing either directly from SOMEEvent class or from any of its subclasses in the framework. There are three main problems to solve in adding a new event type:

Because the registration information is supplied with appropriate "set" methods of a RegData object, the RegData object should be extended to include additional methods. This can be achieved by subclassing from SOMEEMRegisterData and building a new registration data class that has methods to "set" and "get" additional fields of information that are needed to describe the new event types fully. To handle registrations with instances of new registration data subclass, we must also subclass from SOMEEMan and override the someRegister and the someUnRegister methods. These methods should handle the information in the new fields introduced by the new registration data class and call parent methods to handle the rest.

Making EMan recognize the occurrence of the new event is primarily limited by the primitive events EMan can wait on. Thus the new event would have to be wrapped in a primitive event that EMan can recognize. For example, to wait on a message queue on OS/2 concurrently with other EMan events, a separate thread can be made to wait on the message queue and to enqueue a client event with EMan when a message arrives on this message queue. We can thus bring multiple event sources into the single EMan main loop.

The third problem of creating new event objects unknown to EMan can be easily done by applying the previous technique of wrapping the new event in terms of a known event. In a callback routine of the known event, we can create and dispatch the new event unknown to EMan. Of course, this does introduce an intermediate callback routine which would not be needed if EMan directly understood the new event type.

A general way of extending EMan is to look for newly defined event types by overriding someProcessEvent and someProcessEvents in a subclass of EMan.


[Back: Writing an X or MOTIF application]
[Next: Using EMan from C++]