diff options
-rw-r--r-- | timers.cpp | 41 | ||||
-rw-r--r-- | timers.h | 25 |
2 files changed, 47 insertions, 19 deletions
@@ -1,5 +1,7 @@ #include <sstream> +#include <vector> #include "timers.h" +#include "tools.h" static bool operator<( cTimer const& left, cTimer const& right ) { @@ -9,6 +11,7 @@ static bool operator<( cTimer const& left, cTimer const& right ) namespace vdrlive { using namespace std; +using namespace vdrlive; SortedTimers::SortedTimers(): m_state( 0 ) @@ -24,6 +27,38 @@ string SortedTimers::GetTimerId( cTimer const& timer ) return builder.str(); } +cTimer* SortedTimers::GetByTimerId( string const& timerid ) +{ + vector< string > parts = StringSplit( timerid, ':' ); + if ( parts.size() < 5 ) { + esyslog("GetByTimerId: invalid format %s", timerid.c_str() ); + return 0; + } + + cChannel* channel = Channels.GetByChannelID( tChannelID::FromString( parts[0].c_str() ) ); + if ( channel == 0 ) { + esyslog("GetByTimerId: no channel %s", parts[0].c_str() ); + return 0; + } + + try { + int weekdays = lexical_cast< int >( parts[1] ); + time_t day = lexical_cast< time_t >( parts[2] ); + int start = lexical_cast< int >( parts[3] ); + int stop = lexical_cast< int >( parts[4] ); + + for ( SortedTimers::iterator timer = begin(); timer != end(); ++timer ) { + if ( timer->Channel() == channel && + ( ( weekdays != 0 && timer->WeekDays() == weekdays ) || ( weekdays == 0 && timer->Day() == day ) ) && + timer->Start() == start && timer->Stop() == stop ) + return &*timer; + } + } catch ( bad_lexical_cast const& ex ) { + esyslog("GetByTimer: bad cast"); + } + return 0; +} + void SortedTimers::ReloadTimers( bool initial ) { if ( !Timers.Modified( m_state ) && !initial ) @@ -48,4 +83,10 @@ void TimerManager::DoPendingWork() m_timers.ReloadTimers(); } +TimerManager& LiveTimerManager() +{ + static TimerManager instance; + return instance; +} + } // namespace vdrlive @@ -9,39 +9,29 @@ namespace vdrlive { -class Plugin; - -class SortedTimersInterface: public std::list< cTimer > -{ -public: - virtual ~SortedTimersInterface() {} - - virtual std::string GetTimerId( cTimer const& timer ) = 0; -}; - -class SortedTimers: public SortedTimersInterface +class SortedTimers: public std::list< cTimer > { friend class TimerManager; public: - virtual std::string GetTimerId( cTimer const& timer ); + std::string GetTimerId( cTimer const& timer ); + cTimer* GetByTimerId( std::string const& timerid ); private: SortedTimers(); SortedTimers( SortedTimers const& ); int m_state; - int m_refs; void ReloadTimers( bool initial = false ); }; class TimerManager: public cMutex { - friend TimerManager& Plugin::GetLiveTimerManager(); + friend TimerManager& LiveTimerManager(); public: - SortedTimersInterface& GetTimers() { return m_timers; } + SortedTimers& GetTimers() { return m_timers; } // may only be called from Plugin::MainThreadHook void DoPendingWork(); @@ -53,10 +43,7 @@ private: SortedTimers m_timers; }; -inline TimerManager& LiveTimerManager() -{ - return LivePlugin().GetLiveTimerManager(); -} +TimerManager& LiveTimerManager(); } // namespace vdrlive |