diff options
author | horchi <vdr@jwendel.de> | 2018-02-24 17:29:07 +0100 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2018-02-24 18:34:40 +0100 |
commit | fb6de12636c538ab4ddaae0cc32089eac9584ed9 (patch) | |
tree | 6d769d1f32770fa90323028b4609c490a9a1cb86 /lib | |
parent | 49e5a4dd952d1fe444d40f107d5300132cef5eeb (diff) | |
download | vdr-plugin-epg2vdr-fb6de12636c538ab4ddaae0cc32089eac9584ed9.tar.gz vdr-plugin-epg2vdr-fb6de12636c538ab4ddaae0cc32089eac9584ed9.tar.bz2 |
2018-02-23 version 1.1.89 (horchi)\n - change: Improved switch timer 'timing'\n\n
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common.c | 48 | ||||
-rw-r--r-- | lib/common.h | 28 |
2 files changed, 76 insertions, 0 deletions
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 ;) +} diff --git a/lib/common.h b/lib/common.h index 28536ec..3d0aa95 100644 --- a/lib/common.h +++ b/lib/common.h @@ -414,6 +414,34 @@ class LogDuration }; //*************************************************************************** +// Timer Thread +//*************************************************************************** + +class cTimerThread : public cThread +{ + public: + + typedef void (*sendEventFct)(int event, void* userData); + + cTimerThread(sendEventFct fct, int aEvent, time_t aTime, void* aUserData = 0, bool aSelfDistroy = no); + + int isActive() { return active; } + + protected: + + virtual void Action(); + + int event; + time_t theTime; + void* userData; + bool selfdetroy; + cCondVar waitCondition; + int active; + + sendEventFct sendEvent; +}; + +//*************************************************************************** // Semaphore //*************************************************************************** |