From fb6de12636c538ab4ddaae0cc32089eac9584ed9 Mon Sep 17 00:00:00 2001 From: horchi Date: Sat, 24 Feb 2018 17:29:07 +0100 Subject: 2018-02-23 version 1.1.89 (horchi)\n - change: Improved switch timer 'timing'\n\n --- lib/common.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'lib/common.c') diff --git a/lib/common.c b/lib/common.c index 413b9f5..cf68ffa 100644 --- a/lib/common.c +++ b/lib/common.c @@ -1919,3 +1919,51 @@ int urlUnescape(char* dst, const char* src, int normalize) return (dst - org_dst) - 1; } + +//*************************************************************************** +//*************************************************************************** +// Timer Thread +//*************************************************************************** + +cTimerThread::cTimerThread(sendEventFct fct, int aEvent, time_t aTime, void* aUserData, bool aSelfDistroy) +{ + sendEvent = fct; + event = aEvent; + theTime = aTime; + userData = aUserData; + selfdetroy = aSelfDistroy; + active = no; + + Start(); +} + +//*************************************************************************** +// Action +//*************************************************************************** + +void cTimerThread::Action() +{ + cMutex mutex; + + active = yes; + + mutex.Lock(); + tell(1, "Info: Started timer thread, event (%d) scheduled for '%s'", event, l2pTime(theTime).c_str()); + + while (time(0) < theTime && Running() && active) + { + // loop every 10 seconds + + waitCondition.TimedWait(mutex, (theTime - time(0)) * 1000); + } + + if (time(0) >= theTime && sendEvent) + sendEvent(event, userData); + + tell(3, "Info: Finished timer thread"); + + active = no; + + // if (selfdetroy) + // delete this; // :o :o ;) +} -- cgit v1.2.3