#ifndef _EVENT_MANAGER_H
#define _EVENT_MANAGER_H
+#include <list>
-class EventManager {
+#include "Singleton.H"
+
+// interface
+
+// type for return code of event handler
+typedef enum {
+ NOT_HANDLED, // the event was not handled at all
+ HANDLED, // the event was handled succesfully
+ HANDLED_FINAL // the event was handled,
+ // no other handlers should be called
+} eventstatus_t;
+
+
+class Event {
+};
+
+
+template<class T>
+class EventHandler {
public:
- // type for return code of event handler
- typedef enum {
- NOT_HANDLED, // the event was not handled at all
- HANDLED, // the event was handled succesfully
- HANDLED_FINAL // the event was handled,
- // no other handlers should be called
- } eventstatus_t;
+ virtual eventstatus_t handleEvent(T *&e);
+};
-
- static EventManager* getEventManager() { return &theEventManager; };
- class Event {
- public:
- };
+template <class T>
+class EventManagerForType: public Singleton< EventManagerForType<T> > {
+public:
- template<class T>
- class EventHandler {
- public:
+protected:
+ void registerHandler(EventHandler<T> *);
+ void registerHandlerFirst(EventHandler<T> *);
- virtual eventstatus_t handleEvent(T *&e);
+private:
- eventstatus_t dispatchEvent(Event *&e) {
- T *event = dynamic_cast<T*>(e);
-
- if(event)
- return(handleEvent(event));
- else
- return(NOT_HANDLED);
- }
- };
+};
- void postEvent(Event &);
+class EventManager: public Singleton<EventManager> {
+public:
+ eventstatus_t postEvent(Event *);
template<class T>
- bool registerHandler(EventHandler<T> *);
+ void registerHandler(EventHandler<T> *h) {
+ EventManagerForType<T>::instance()->registerHandler(h);
+ }
template<class T>
- bool registerHandlerFirst(EventHandler<T> *);
+ void registerHandlerFirst(EventHandler<T> *) {
+ EventManagerForType<T>::instance()->registerHandlerFirst(h);
+ }
+
+protected:
+ EventManager()
+ {}
+
+ virtual ~EventManager()
+ {}
private:
- // the event manager
- static EventManager theEventManager;
+};
+
- // private default constructor for singleton instance
- EventManager()
- {};
-};
+// implementation
#endif