00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef SST_CORE_CLOCK_H
00014 #define SST_CORE_CLOCK_H
00015
00016 #include <sst/core/serialization.h>
00017
00018
00019
00020 #include <vector>
00021
00022 #include <sst/core/action.h>
00023
00024
00025 #define _CLE_DBG( fmt, args...)__DBG( DBG_CLOCK, Clock, fmt, ## args )
00026
00027 namespace SST {
00028
00029 class TimeConverter;
00030
00031
00032
00033
00034
00035
00036 class Clock : public Action
00037 {
00038 public:
00039
00040
00041 Clock( TimeConverter* period, int priority = CLOCKPRIORITY);
00042 ~Clock();
00043
00044
00045 class HandlerBase {
00046 public:
00047
00048 virtual bool operator()(Cycle_t) = 0;
00049 virtual ~HandlerBase() {}
00050 };
00051
00052
00053
00054
00055
00056
00057 template <typename classT, typename argT = void>
00058 class Handler : public HandlerBase {
00059 private:
00060 typedef bool (classT::*PtrMember)(Cycle_t, argT);
00061 classT* object;
00062 const PtrMember member;
00063 argT data;
00064
00065 public:
00066
00067
00068
00069
00070
00071 Handler( classT* const object, PtrMember member, argT data ) :
00072 object(object),
00073 member(member),
00074 data(data)
00075 {}
00076
00077 bool operator()(Cycle_t cycle) {
00078 return (object->*member)(cycle,data);
00079 }
00080 };
00081
00082
00083
00084
00085 template <typename classT>
00086 class Handler<classT, void> : public HandlerBase {
00087 private:
00088 typedef bool (classT::*PtrMember)(Cycle_t);
00089 classT* object;
00090 const PtrMember member;
00091
00092 public:
00093
00094
00095
00096
00097 Handler( classT* const object, PtrMember member ) :
00098 object(object),
00099 member(member)
00100 {}
00101
00102 bool operator()(Cycle_t cycle) {
00103 return (object->*member)(cycle);
00104 }
00105 };
00106
00107
00108
00109
00110
00111 void schedule();
00112
00113
00114 Cycle_t getNextCycle();
00115
00116
00117 bool registerHandler( Clock::HandlerBase* handler );
00118
00119 bool unregisterHandler( Clock::HandlerBase* handler, bool& empty );
00120
00121 void print(const std::string& header, Output &out) const;
00122
00123 private:
00124
00125 typedef std::vector<Clock::HandlerBase*> StaticHandlerMap_t;
00126
00127
00128 Clock() { }
00129
00130 void execute( void );
00131
00132 Cycle_t currentCycle;
00133 TimeConverter* period;
00134 StaticHandlerMap_t staticHandlerMap;
00135 SimTime_t next;
00136 bool scheduled;
00137
00138 friend class boost::serialization::access;
00139 template<class Archive>
00140 void serialize(Archive & ar, const unsigned int version )
00141 {
00142 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Action);
00143 ar & BOOST_SERIALIZATION_NVP(currentCycle);
00144 ar & BOOST_SERIALIZATION_NVP(period);
00145 ar & BOOST_SERIALIZATION_NVP(staticHandlerMap);
00146 ar & BOOST_SERIALIZATION_NVP(scheduled);
00147 }
00148 };
00149
00150 }
00151
00152 BOOST_CLASS_EXPORT_KEY(SST::Clock)
00153
00154 #endif // SST_CORE_CLOCK_H