CallBackTimer.h
См. документацию.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00023
00024 # ifndef CallBackTimer_H_
00025 # define CallBackTimer_H_
00026
00027 #include <list>
00028 #include "Exceptions.h"
00029 #include "ThreadCreator.h"
00030 #include "PassiveTimer.h"
00031
00037 namespace UniSetTypes
00038 {
00039 class LimitTimers:
00040 public UniSetTypes::Exception
00041 {
00042 public:
00043 LimitTimers():Exception("LimitTimers"){ printException(); }
00044
00046 LimitTimers(const std::string err):Exception(err){ printException(); }
00047 };
00048 };
00050
00051
00052
00080 template <class Caller>
00081 class CallBackTimer
00082
00083 {
00084 public:
00085
00087 static const int MAXCallBackTimer = 20;
00088
00090 typedef void(Caller::* Action)( int id );
00091
00092 CallBackTimer(Caller* r, Action a);
00093 ~CallBackTimer();
00094
00095
00096 void run();
00097 void terminate();
00099
00100 void reset(int id);
00101 void setTiming(int id, int timrMS);
00102 int getInterval(int id);
00103 int getCurrent(int id);
00106 void add( int id, int timeMS )throw(UniSetTypes::LimitTimers);
00107 void remove( int id );
00109 protected:
00110
00111 CallBackTimer();
00112 void work();
00113
00114 void startTimers();
00115 void clearTimers();
00116
00117 private:
00118
00119 typedef CallBackTimer<Caller> CBT;
00120 friend class ThreadCreator<CBT>;
00121 Caller* cal;
00122 Action act;
00123 ThreadCreator<CBT> *thr;
00124
00125 bool terminated;
00126
00127 struct TimerInfo
00128 {
00129 TimerInfo(int id, PassiveTimer& pt):
00130 id(id), pt(pt){};
00131
00132 int id;
00133 PassiveTimer pt;
00134 };
00135
00136 typedef std::list<TimerInfo> TimersList;
00137 TimersList lst;
00138
00139
00140 struct FindId_eq: public unary_function<TimerInfo, bool>
00141 {
00142 FindId_eq(const int id):id(id){}
00143 inline bool operator()(const TimerInfo& ti) const{return ti.id==id;}
00144 int id;
00145 };
00146 };
00147
00148 #include "CallBackTimer.tcc"
00149 # endif //CallBackTimer_H_