ROOTANA
Loading...
Searching...
No Matches
TPeriodicClass.cxx
Go to the documentation of this file.
1#include "TPeriodicClass.hxx"
2#include <sys/time.h>
3#include <assert.h>
4
5
6double GetTimeSec()
7{
8 struct timeval tv;
9 gettimeofday(&tv,NULL);
10 return tv.tv_sec + 0.000001*tv.tv_usec;
11}
12
13TPeriodicClass::TPeriodicClass(int period_msec,TimerHandler handler)
14{
15 assert(handler != NULL);
16 fPeriod_msec = period_msec;
17 fHandler = handler;
19 Start(period_msec,kTRUE);
20}
21
23{
24 double t = GetTimeSec();
25 //printf("timer notify, period %f should be %f!\n",t-fLastTime,fPeriod_msec*0.001);
26
27 if (t - fLastTime >= 0.9*fPeriod_msec*0.001)
28 {
29 //printf("timer: call handler %p\n",fHandler);
30 if (fHandler)
31 (*fHandler)();
32
33 fLastTime = t;
34 }
35
36 Reset();
37 return kTRUE;
38}
double GetTimeSec()
double GetTimeSec()
TimerHandler fHandler
TPeriodicClass(int period_msec, TimerHandler handler)