00001 /* 00002 * EventSwitch.h 00003 * 00004 * Created on: 05.03.2009 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef EVENTSWITCH_H_ 00009 #define EVENTSWITCH_H_ 00010 00011 #include "core/Event.h" 00012 #include "core/EventReceiver.h" 00013 #include "Component.h" 00014 #include <ibrcommon/Exceptions.h> 00015 #include <ibrcommon/thread/Mutex.h> 00016 #include <ibrcommon/thread/Conditional.h> 00017 #include <ibrcommon/thread/ThreadSafeQueue.h> 00018 #include "core/EventDebugger.h" 00019 00020 #include <list> 00021 #include <map> 00022 #include <queue> 00023 00024 namespace dtn 00025 { 00026 namespace core 00027 { 00028 class EventException : public ibrcommon::Exception 00029 { 00030 00031 }; 00032 00033 class NoSuchEventException : public EventException 00034 { 00035 00036 }; 00037 00038 class NoReceiverFoundException : public ibrcommon::Exception 00039 { 00040 00041 }; 00042 00043 class EventSwitch : public dtn::daemon::IntegratedComponent 00044 { 00045 private: 00046 EventSwitch(); 00047 virtual ~EventSwitch(); 00048 00049 ibrcommon::Mutex _receiverlock; 00050 std::map<std::string,std::list<EventReceiver*> > _list; 00051 ibrcommon::ThreadSafeQueue<dtn::core::Event*> _queue; 00052 bool _running; 00053 00054 // create event debugger 00055 EventDebugger _debugger; 00056 00057 const std::list<EventReceiver*>& getReceivers(std::string eventName) const; 00058 00059 protected: 00060 virtual void componentUp(); 00061 virtual void componentDown(); 00062 00063 friend class Event; 00064 friend class EventReceiver; 00065 00066 static void registerEventReceiver(string eventName, EventReceiver *receiver); 00067 static void unregisterEventReceiver(string eventName, EventReceiver *receiver); 00068 static void raiseEvent(Event *evt); 00069 00070 public: 00071 static EventSwitch& getInstance(); 00072 void loop(); 00073 }; 00074 } 00075 } 00076 00077 #endif /* EVENTSWITCH_H_ */
1.6.3