experimental stuff
authorMichal Voců <michal@ruk.cuni.cz>
Wed, 20 Jun 2007 09:00:17 +0000 (09:00 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Wed, 20 Jun 2007 09:00:17 +0000 (09:00 +0000)
org.glite.lb.logger/src-nt/EventManager.H

index 1fa4cab..2a12b7a 100644 (file)
@@ -1,59 +1,73 @@
 #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