29 #ifndef TRM_QT_TIMER_H_
30 #define TRM_QT_TIMER_H_
41 #include "trm/Timer.h"
45 extern std::ostream & Log(
void) ;
49 #define _TRIM_QT_TIMER_BYPASS_PRECISION_CHECK_ 0
58 timer.setSingleShot(
true);
61 QObject::connect(&timer, SIGNAL(timeout()),
this, SLOT(onExpiration()));
65 void schedule(
TimerTask &task, int64_t expireAt, int64_t milliSecs)
68 int32_t max32 = std::numeric_limits<int32_t>::max();
72 milliSecs = (milliSecs <= ((int64_t)max32)) ? milliSecs : max32;
73 timer.start(milliSecs);
86 void onExpiration(
void)
88 qint64 now = QDateTime::currentMSecsSinceEpoch();
89 if (_TRIM_QT_TIMER_BYPASS_PRECISION_CHECK_ || now >= future) {
98 int64_t milliSecs = future - now + 1;
99 milliSecs = ((milliSecs > 0) ? milliSecs : 0);
100 Log() <<
"WARN::Timer " << (
void *)
this <<
" Expired Earlyy, Reschedule " << (milliSecs) <<
" with future " << future << std::endl;
103 timer.setSingleShot(
true);
104 timer.start(milliSecs);