Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Stingray Foundation Library User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.5 Chaining Event Routers

It is useful to route events through numerous objects in a system. In other words, an event may be routed through multiple objects before reaching its final destination. MFC has hard-coded routing logic to get messages to views and documents. The Events package takes advantage of the more flexible publish-subscribe pattern to accomplish message routing. Event routers can also be event listeners, and therefore they can listen to the events of other event routers. This flexible design means that the event routing logic in a system can be very dynamic and easy to configure.

The CComboRouterListener template class can be used to mix the IEventListener interface with an event router. The template parameter passed to CComboRouterListener is the base class, which must be a class derived from both IEventListener and IEventRouter. The CComboRouterListener class basically just implements the HandleEvent() method by forwarding it to the RouteEvent() method. Example 47 shows the implementation of CComboRouterListener.

Example 47: Implementation of CComboRouterListener

The following code shows how you can use CComboRouterListener to create an object that is both an event router and an event listener. The CFoobarBase class inherits IEventRouterImpl and mixes in the IEventListener interface. CFoobarBase is an abstract base class because it does not implement the HandleEvent() method inherited from IEventListener. Wrapping CFoobarBase with the CComboRouterListener template class implements HandleEvent(). As a result, instances of CFoobar can be added as listeners to other event routers. They can also route events to listeners.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.