00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _eoTimedMonitor_h
00028 #define _eoTimedMonitor_h
00029
00030 #include <ctime>
00031 #include <string>
00032
00033 #include <utils/eoMonitor.h>
00034 #include <eoObject.h>
00035
00040 class eoTimedMonitor : public eoMonitor
00041 {
00042 public:
00043
00049 eoTimedMonitor(unsigned seconds_) : last_tick(0), seconds(seconds_) {}
00050
00051 eoMonitor& operator()(void) {
00052 bool monitor = false;
00053 if (last_tick == 0) {
00054 monitor = true;
00055 last_tick = clock();
00056 }
00057
00058 clock_t tick = clock();
00059
00060 if ( (tick-last_tick) >= seconds * CLOCKS_PER_SEC) {
00061 monitor = true;
00062 }
00063
00064 if (monitor) {
00065 for (unsigned i = 0; i < monitors.size(); ++i) {
00066 (*monitors[i])();
00067 }
00068 last_tick = clock();
00069 }
00070 return *this;
00071 }
00072
00073 void add(eoMonitor& mon) { monitors.push_back(&mon); }
00074
00075 virtual std::string className(void) const { return "eoTimedMonitor"; }
00076
00077 private:
00078
00079 clock_t last_tick;
00080
00081 unsigned seconds;
00082
00083 std::vector<eoMonitor*> monitors;
00084 };
00085
00086 #endif