From: Michal Voců Date: Wed, 20 Jun 2007 09:00:17 +0000 (+0000) Subject: experimental stuff X-Git-Tag: gridsite-core_R_1_5_1~5 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=b1b65d3575f3843dfb564e9e75f521b58054b0c2;p=jra1mw.git experimental stuff --- diff --git a/org.glite.lb.logger/src-nt/EventManager.H b/org.glite.lb.logger/src-nt/EventManager.H index 1fa4cab..2a12b7a 100644 --- a/org.glite.lb.logger/src-nt/EventManager.H +++ b/org.glite.lb.logger/src-nt/EventManager.H @@ -1,59 +1,73 @@ #ifndef _EVENT_MANAGER_H #define _EVENT_MANAGER_H +#include -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 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 EventManagerForType: public Singleton< EventManagerForType > { +public: - template - class EventHandler { - public: +protected: + void registerHandler(EventHandler *); + void registerHandlerFirst(EventHandler *); - virtual eventstatus_t handleEvent(T *&e); +private: - eventstatus_t dispatchEvent(Event *&e) { - T *event = dynamic_cast(e); - - if(event) - return(handleEvent(event)); - else - return(NOT_HANDLED); - } - }; +}; - void postEvent(Event &); +class EventManager: public Singleton { +public: + eventstatus_t postEvent(Event *); template - bool registerHandler(EventHandler *); + void registerHandler(EventHandler *h) { + EventManagerForType::instance()->registerHandler(h); + } template - bool registerHandlerFirst(EventHandler *); + void registerHandlerFirst(EventHandler *) { + EventManagerForType::instance()->registerHandlerFirst(h); + } + +protected: + EventManager() + {} + + virtual ~EventManager() + {} private: - // the event manager - static EventManager theEventManager; +}; + - // private default constructor for singleton instance - EventManager() - {}; -}; +// implementation #endif