AbstractEventSource.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 #ifndef ABSTRACT_EVENT_SOURCE_H_
00003 #define ABSTRACT_EVENT_SOURCE_H_
00004 
00005 #include <fesa-core/Diagnostic/DiagnosticUtils.h>
00006 #include <fesa-core/Utilities/Thread.h>
00007 #include <fesa-core/Exception/FesaException.h>
00008 #include <fesa-core/Utilities/ConditionalVariable.h>
00009 #include <fesa-core/Utilities/Mutex.h>
00010 #include <boost/shared_ptr.hpp>
00011 
00012 #include <map>
00013 #include <vector>
00014 
00015 namespace fesa
00016 {
00017 
00018 class EventElement;
00019 class RTScheduler;
00020 class FesaStream;
00021 class RTEvent;
00022 
00023 enum EventSourceType
00024 {
00025         TimingSource, TimerSource, OnDemandSource, OnSubscriptionSource, CustomSource, TimingSimulationSource
00026 };
00027 
00033 class AbstractEventSource : protected Thread
00034 {
00035         public:
00036 
00041                 virtual void enable();
00042 
00047                 virtual void disable();
00048 
00054                 virtual void enableEvent(const std::string& logicalEventName);
00055 
00061                 virtual void disableEvent(const std::string& logicalEventName);
00062 
00068                 void printConfig(FesaStream* fesaStream) const;
00069 
00075                 void printState(FesaStream* fesaStream, double elapsedTime);
00076 
00080                 virtual ~AbstractEventSource();
00081 
00085                 const std::string& getName() const;
00086 
00091                 EventSourceType getType() const;
00092 
00097                 uint32_t getEvtSrcPriority() const;
00098 
00103                 uint32_t getEvtSrcID() const;
00104 
00109                 bool isEventEnabled(const std::string& logicalEventName) const;
00110 
00111         protected:
00112 
00113                 friend class RTEvent;
00114                 friend class RTController;
00115                 friend class AbstractEventSourceFactory;
00116 
00123                 AbstractEventSource(const std::string eventSourceName,EventSourceType type_);
00124 
00129                 void run();
00130 
00138                 virtual void addRTScheduler(boost::shared_ptr<fesa::EventElement>& element, RTScheduler* scheduler);
00139 
00144                 virtual RTEvent* wait() = 0;
00145 
00151                 virtual void connect(boost::shared_ptr<fesa::EventElement>& eventElement) = 0;
00152 
00153         private:
00154 
00155                 struct SubscribedScheduler
00156                 {
00157                         RTScheduler* scheduler_;
00158                         std::string logicalEventName_;
00159                         bool isEnabled_;
00160                 };
00161                 typedef std::string ConcreteEventName;
00162                 typedef std::map< ConcreteEventName, std::vector< SubscribedScheduler > > ConcreteEventMap;
00163 
00167                 ConcreteEventMap eventMap_;
00168 
00172                 bool sourceIsEnabled_;
00173 
00177                 ConditionalVariable waitIfDisabled_;
00178                 Mutex mutex_waitIfDisabled_;
00179 
00183                 std::string eventSourceName_;
00184 
00188                 EventSourceType type_;
00189 
00193                 DiagnosticUtils::DiagStateCounter firedEventCount_;
00194 
00198                 void postEventToSchedulers(boost::shared_ptr<RTEvent>& event);
00199 
00203                 void waitTillSourceEnabled();
00204 
00208                 void setLogicalEventEnableState(bool newState,const std::string& logicalEventName);
00209 
00210 };
00211 
00212 } // fesa
00213 
00214 #endif // ABSTRACT_EVENT_SOURCE_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1