From 00e2a4d8f46a67f2eb5549fc9be6631c1e142490 Mon Sep 17 00:00:00 2001 From: Jasmin Jessich Date: Sat, 17 Jun 2017 23:38:14 +0200 Subject: Use a cStateKey for SortedTimers::Modified changed detection - Added SortedTimers::m_TimersStateKey to store the last timers list state. - SortedTimers::Modified uses now the new m_TimersStateKey to check, if the list has been modified. --- timers.cpp | 43 ++++++++++++++----------------------------- timers.h | 8 +++++++- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/timers.cpp b/timers.cpp index 7f46cab..bb31ac8 100644 --- a/timers.cpp +++ b/timers.cpp @@ -23,10 +23,12 @@ namespace vdrlive { static char const* const TIMER_DELETE = "DELETE"; static char const* const TIMER_TOGGLE = "TOGGLE"; - SortedTimers::SortedTimers(): - m_state( 0 ) + SortedTimers::SortedTimers() +#if VDRVERSNUM < 20301 + : m_state( 0 ) +#endif { - ReloadTimers( true ); + ReloadTimers(); } string SortedTimers::GetTimerId( cTimer const& timer ) @@ -62,6 +64,8 @@ namespace vdrlive { int start = lexical_cast< int >( parts[3] ); int stop = lexical_cast< int >( parts[4] ); + cMutexLock MutexLock(&m_mutex); + for ( SortedTimers::iterator timer = begin(); timer != end(); ++timer ) { if ( timer->Channel() == channel && ( ( weekdays != 0 && timer->WeekDays() == weekdays ) || ( weekdays == 0 && timer->Day() == day ) ) && @@ -92,10 +96,12 @@ namespace vdrlive { } - void SortedTimers::ReloadTimers( bool initial ) + void SortedTimers::ReloadTimers() { // dsyslog("live reloading timers"); + cMutexLock MutexLock(&m_mutex); + clear(); #if VDRVERSNUM >= 20301 { @@ -159,33 +165,12 @@ namespace vdrlive { #if VDRVERSNUM >= 20301 bool SortedTimers::Modified() { - // the global(!) list of known timers - static vector knownTimers; - bool modified = false; - LOCK_TIMERS_READ; - for ( const cTimer* timer = Timers->First(); timer; timer = Timers->Next( timer ) ) { - bool known_id = false; - for (vector::iterator it = knownTimers.begin(); it != knownTimers.end(); ++it) { - if (timer->Id() == it->Id()) { - known_id = true; - string timer_txt = *timer->ToText (true); - string known_txt = *it->ToText (true); - modified = timer_txt != known_txt; - break; - } - } - if (!known_id) { - modified = true; - break; - } - } - if (modified) { - knownTimers.clear(); - for (const cTimer* Timer = Timers->First(); Timer; Timer = Timers->Next (Timer)) { - knownTimers.push_back (*Timer); - } + // will return != 0 only, if the Timers List has been changed since last read + if (cTimers::GetTimersRead(m_TimersStateKey)) { + modified = true; + m_TimersStateKey.Remove(); } return modified; diff --git a/timers.h b/timers.h index 5f62f76..1fc86ff 100644 --- a/timers.h +++ b/timers.h @@ -35,9 +35,15 @@ namespace vdrlive { SortedTimers(); SortedTimers( SortedTimers const& ); + cMutex m_mutex; + +#if VDRVERSNUM >= 20301 + cStateKey m_TimersStateKey; +#else int m_state; +#endif - void ReloadTimers( bool initial = false ); + void ReloadTimers(); }; class TimerManager: public cMutex -- cgit v1.2.3