From 07aebf937a6a196114e7136f77eb5adefa2eeeb1 Mon Sep 17 00:00:00 2001 From: Sascha Volkenandt Date: Fri, 5 Jan 2007 20:31:33 +0000 Subject: - incorporated all code into one shared object - added several functions for timer identification --- timers.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ timers.h | 25 ++++++------------------- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/timers.cpp b/timers.cpp index e1689ce..de072dc 100644 --- a/timers.cpp +++ b/timers.cpp @@ -1,5 +1,7 @@ #include +#include #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 diff --git a/timers.h b/timers.h index 339ead4..e6a275d 100644 --- a/timers.h +++ b/timers.h @@ -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 -- cgit v1.2.3