This topic is now archived and is closed to further replies.

Event Handling Techniques

This topic is 5307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, does anyone know where I can get some good information on event handling? I''m trying to create an event handling system flexible enough to be reusable in other projects. I like the way java has event listeners for various event types (i.e. ComponentListener, MouseListener, etc.). Here''s what I was thinking: 1. Window''s message is sent to my message router 2. Message router finds appropriate component from the HWND 3. Message router collects event parameters 4. Message router dispatchers event to component. 5. Component sends event to the correct event listener The problem is that I''m not sure how I should send each event to the right event listener. I could group events into similar categories like Mouse, Window, Keyboard and route the events to the event listeners using this information. But that kind of seems like a pain in the ass, this also doesn''t seem like it''s very generic and adept to modification. If anyone has any experience with this, any input would be greatly appreciated. Kory

Share this post

Link to post
Share on other sites
I'm working on mine at the moment. Its Win32-only right now. Here's a quick rundown of how it works.


EventNotifier: singleton class that creates a message-only window in the constructor. Allows you to register function callbacks for specific windows messages. Legit use of singleton even.

AsyncSocketManager: static(possibly, I broke it tonight playing with it, may put it back to nifty-counted singletons actually) class that is notified by EventNotifier of socket events and notifies AsyncSockets of the events. AsyncSockets register themselves transparently in their constructor and destructor. All the AsyncSocketManager class is take a socket event (generated by WSAAsyncSelect()) and map it to the correct AsyncSocket instance.

AsyncSocket: contains virtual methods like onReceiveNotification, onSendNotification. These are used internally to maintain state in the object and its derived classes. Also contains boost::function callbacks that allow users to attach their own event handlers to events.

[edited by - antareus on June 3, 2003 9:22:46 PM]

Share this post

Link to post
Share on other sites
Thanks for the reply. I think I''ve found a good way of handling events. I basically wanted a generic and clean way to handling win32 and user events. Here''s what I got:

1. class IEventModel
a. Routes the events to the dispatchers
b. Wraps the window callback

2. class IEventDispatcher
a. Responsible for sending the events to the correct listener
b. Any object that wants to receive events must own a
dispatcher and register it with event model

3. class IEventListener
a. Handles events that it is registered to

I''m not sure, yet, whether I want to use generic callbacks for the event listeners or not. How flexible is the boost::function callbacks?


Share this post

Link to post
Share on other sites