Event Handling Techniques

Started by
1 comment, last by kspansel 20 years, 10 months ago
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
"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein
Advertisement
I'm working on mine at the moment. Its Win32-only right now. Here's a quick rundown of how it works.
EventNotifier |-AsyncSocketManager   |-AsyncSocket  

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]
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Hey,
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?

Thanks,
Kory
"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein

This topic is closed to new replies.

Advertisement