IBR-DTNSuite 0.6

daemon/src/core/EventSwitch.h

Go to the documentation of this file.
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/Queue.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::Queue<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 
00062                         virtual const std::string getName() const;
00063 
00064                 protected:
00065                         virtual void componentUp();
00066                         virtual void componentDown();
00067 
00068                         friend class Event;
00069                         friend class EventReceiver;
00070 
00071                         static void registerEventReceiver(string eventName, EventReceiver *receiver);
00072                         static void unregisterEventReceiver(string eventName, EventReceiver *receiver);
00073                         static void raiseEvent(Event *evt);
00074 
00075                 public:
00076                         static EventSwitch& getInstance();
00077                         void loop();
00078                         void clear();
00079                 };
00080         }
00081 }
00082 
00083 #endif /* EVENTSWITCH_H_ */