diff options
author | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2008-03-12 17:09:27 +0100 |
---|---|---|
committer | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2008-03-12 17:09:27 +0100 |
commit | 8bb3ea736ccf17496f7767855729973451944be4 (patch) | |
tree | 6acb5fedf842447aadcc43076f4d16367bd42271 | |
parent | 8613cbc6223a4eb8ec470c6ff89032b54847a036 (diff) | |
download | vdr-plugin-live-8bb3ea736ccf17496f7767855729973451944be4.tar.gz vdr-plugin-live-8bb3ea736ccf17496f7767855729973451944be4.tar.bz2 |
Whitespace changes only. Adapted indentation to be usable with automatic
indentation editors.
-rw-r--r-- | timers.cpp | 484 | ||||
-rw-r--r-- | timers.h | 96 |
2 files changed, 290 insertions, 290 deletions
@@ -13,308 +13,308 @@ static bool operator<( cTimer const& left, cTimer const& right ) namespace vdrlive { -using namespace std; -using namespace vdrlive; + using namespace std; + using namespace vdrlive; -static char const* const TIMER_DELETE = "DELETE"; -static char const* const TIMER_TOGGLE = "TOGGLE"; + static char const* const TIMER_DELETE = "DELETE"; + static char const* const TIMER_TOGGLE = "TOGGLE"; -SortedTimers::SortedTimers(): + SortedTimers::SortedTimers(): m_state( 0 ) -{ - ReloadTimers( true ); -} - -string SortedTimers::GetTimerId( cTimer const& timer ) -{ - ostringstream builder; - builder << timer.Channel()->GetChannelID() << ":" << timer.WeekDays() << ":" - << timer.Day() << ":" << timer.Start() << ":" << timer.Stop(); - 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; + { + ReloadTimers( true ); } - cChannel* channel = Channels.GetByChannelID( tChannelID::FromString( parts[0].c_str() ) ); - if ( channel == 0 ) { - esyslog("GetByTimerId: no channel %s", parts[0].c_str() ); - return 0; + string SortedTimers::GetTimerId( cTimer const& timer ) + { + ostringstream builder; + builder << timer.Channel()->GetChannelID() << ":" << timer.WeekDays() << ":" + << timer.Day() << ":" << timer.Start() << ":" << timer.Stop(); + return builder.str(); } - 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; + 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"); } - } catch ( bad_lexical_cast const& ex ) { - esyslog("GetByTimer: bad cast"); + return 0; } - return 0; -} -void SortedTimers::ReloadTimers( bool initial ) -{ - dsyslog("live reloading timers"); + void SortedTimers::ReloadTimers( bool initial ) + { + dsyslog("live reloading timers"); - clear(); - for ( cTimer* timer = Timers.First(); timer != 0; timer = Timers.Next( timer ) ) { - push_back( *timer ); + clear(); + for ( cTimer* timer = Timers.First(); timer != 0; timer = Timers.Next( timer ) ) { + push_back( *timer ); + } + sort(); } - sort(); -} -string SortedTimers::GetTimerDays(cTimer const& timer) -{ - string currentDay = timer.WeekDays() > 0 ? + string SortedTimers::GetTimerDays(cTimer const& timer) + { + string currentDay = timer.WeekDays() > 0 ? #if VDRVERSNUM < 10503 - *cTimer::PrintDay(0, timer.WeekDays()) : + *cTimer::PrintDay(0, timer.WeekDays()) : #else - *cTimer::PrintDay(0, timer.WeekDays(), true) : + *cTimer::PrintDay(0, timer.WeekDays(), true) : #endif - FormatDateTime(tr("%A, %x"), timer.Day()); - return currentDay; -} - -string SortedTimers::GetTimerInfo(cTimer const& timer) -{ - ostringstream info; - info << trVDR("Priority") << ": " << timer.Priority() << endl; - info << trVDR("Lifetime") << ": " << timer.Lifetime() << endl; - info << trVDR("VPS") << ": " << (timer.HasFlags(tfVps)?trVDR("yes"):trVDR("no")) << endl; + FormatDateTime(tr("%A, %x"), timer.Day()); + return currentDay; + } - if (timer.Aux()) + string SortedTimers::GetTimerInfo(cTimer const& timer) { - string epgsearchinfo = GetXMLValue(timer.Aux(), "epgsearch"); - if (!epgsearchinfo.empty()) + ostringstream info; + info << trVDR("Priority") << ": " << timer.Priority() << endl; + info << trVDR("Lifetime") << ": " << timer.Lifetime() << endl; + info << trVDR("VPS") << ": " << (timer.HasFlags(tfVps)?trVDR("yes"):trVDR("no")) << endl; + + if (timer.Aux()) { - string searchtimer = GetXMLValue(epgsearchinfo, "searchtimer"); - if (!searchtimer.empty()) - info << tr("Searchtimer") << ": " << searchtimer << endl; - } + string epgsearchinfo = GetXMLValue(timer.Aux(), "epgsearch"); + if (!epgsearchinfo.empty()) + { + string searchtimer = GetXMLValue(epgsearchinfo, "searchtimer"); + if (!searchtimer.empty()) + info << tr("Searchtimer") << ": " << searchtimer << endl; + } + } + return info.str(); } - return info.str(); -} -TimerManager::TimerManager() -{ -} + TimerManager::TimerManager() + { + } -void TimerManager::UpdateTimer( cTimer* timer, int flags, tChannelID& channel, string const& weekdays, string const& day, - int start, int stop, int priority, int lifetime, string const& title, string const& aux ) -{ - cMutexLock lock( this ); + void TimerManager::UpdateTimer( cTimer* timer, int flags, tChannelID& channel, string const& weekdays, string const& day, + int start, int stop, int priority, int lifetime, string const& title, string const& aux ) + { + cMutexLock lock( this ); - ostringstream builder; - builder << flags << ":" << channel << ":" << ( weekdays != "-------" ? weekdays : "" ) - << ( weekdays == "-------" || day.empty() ? "" : "@" ) << day << ":" << start << ":" << stop << ":" - << priority << ":" << lifetime << ":" << title << ":" << aux; - dsyslog("%s", builder.str().c_str()); + ostringstream builder; + builder << flags << ":" << channel << ":" << ( weekdays != "-------" ? weekdays : "" ) + << ( weekdays == "-------" || day.empty() ? "" : "@" ) << day << ":" << start << ":" << stop << ":" + << priority << ":" << lifetime << ":" << title << ":" << aux; + dsyslog("%s", builder.str().c_str()); - TimerPair timerData( timer, builder.str() ); + TimerPair timerData( timer, builder.str() ); - dsyslog("SV: in UpdateTimer"); - m_updateTimers.push_back( timerData ); - dsyslog("SV: wait for update"); - m_updateWait.Wait( *this ); - dsyslog("SV: update done"); + dsyslog("SV: in UpdateTimer"); + m_updateTimers.push_back( timerData ); + dsyslog("SV: wait for update"); + m_updateWait.Wait( *this ); + dsyslog("SV: update done"); - string error = GetError( timerData ); - if ( !error.empty() ) - throw HtmlError( error ); -} + string error = GetError( timerData ); + if ( !error.empty() ) + throw HtmlError( error ); + } -void TimerManager::DelTimer( cTimer* timer ) -{ - cMutexLock lock( this ); + void TimerManager::DelTimer( cTimer* timer ) + { + cMutexLock lock( this ); - TimerPair timerData( timer, TIMER_DELETE ); + TimerPair timerData( timer, TIMER_DELETE ); - m_updateTimers.push_back( timerData ); - m_updateWait.Wait( *this ); + m_updateTimers.push_back( timerData ); + m_updateWait.Wait( *this ); - string error = GetError( timerData ); - if ( !error.empty() ) - throw HtmlError( error ); -} + string error = GetError( timerData ); + if ( !error.empty() ) + throw HtmlError( error ); + } -void TimerManager::ToggleTimerActive( cTimer* timer) -{ - cMutexLock lock( this ); + void TimerManager::ToggleTimerActive( cTimer* timer) + { + cMutexLock lock( this ); - TimerPair timerData( timer, TIMER_TOGGLE ); + TimerPair timerData( timer, TIMER_TOGGLE ); - m_updateTimers.push_back( timerData ); - m_updateWait.Wait( *this ); + m_updateTimers.push_back( timerData ); + m_updateWait.Wait( *this ); - string error = GetError( timerData ); - if ( !error.empty() ) - throw HtmlError( error ); -} + string error = GetError( timerData ); + if ( !error.empty() ) + throw HtmlError( error ); + } -void TimerManager::DoPendingWork() -{ - if ( m_updateTimers.size() == 0 && !m_timers.Modified() ) - return; + void TimerManager::DoPendingWork() + { + if ( m_updateTimers.size() == 0 && !m_timers.Modified() ) + return; - cMutexLock lock( this ); - if ( m_updateTimers.size() > 0 ) { - DoUpdateTimers(); + cMutexLock lock( this ); + if ( m_updateTimers.size() > 0 ) { + DoUpdateTimers(); + } + DoReloadTimers(); + dsyslog("SV: signalling waiters"); + m_updateWait.Broadcast(); } - DoReloadTimers(); - dsyslog("SV: signalling waiters"); - m_updateWait.Broadcast(); -} -void TimerManager::DoUpdateTimers() -{ - dsyslog("SV: updating timers"); - for ( TimerList::iterator timer = m_updateTimers.begin(); timer != m_updateTimers.end(); ++timer ) { - if ( timer->first == 0 ) // new timer - DoInsertTimer( *timer ); - else if ( timer->second == TIMER_DELETE ) // delete timer - DoDeleteTimer( *timer ); - else if ( timer->second == TIMER_TOGGLE ) // toggle timer - DoToggleTimer( *timer ); - else // update timer - DoUpdateTimer( *timer ); + void TimerManager::DoUpdateTimers() + { + dsyslog("SV: updating timers"); + for ( TimerList::iterator timer = m_updateTimers.begin(); timer != m_updateTimers.end(); ++timer ) { + if ( timer->first == 0 ) // new timer + DoInsertTimer( *timer ); + else if ( timer->second == TIMER_DELETE ) // delete timer + DoDeleteTimer( *timer ); + else if ( timer->second == TIMER_TOGGLE ) // toggle timer + DoToggleTimer( *timer ); + else // update timer + DoUpdateTimer( *timer ); + } + m_updateTimers.clear(); } - m_updateTimers.clear(); -} -void TimerManager::DoInsertTimer( TimerPair& timerData ) -{ - auto_ptr< cTimer > newTimer( new cTimer ); - if ( !newTimer->Parse( timerData.second.c_str() ) ) { - StoreError( timerData, tr("Error in timer settings") ); - return; - } + void TimerManager::DoInsertTimer( TimerPair& timerData ) + { + auto_ptr< cTimer > newTimer( new cTimer ); + if ( !newTimer->Parse( timerData.second.c_str() ) ) { + StoreError( timerData, tr("Error in timer settings") ); + return; + } + + cTimer* checkTimer = Timers.GetTimer( newTimer.get() ); + if ( checkTimer != 0 ) { + StoreError( timerData, tr("Timer already defined") ); + return; + } - cTimer* checkTimer = Timers.GetTimer( newTimer.get() ); - if ( checkTimer != 0 ) { - StoreError( timerData, tr("Timer already defined") ); - return; + Timers.Add( newTimer.get() ); + Timers.SetModified(); + isyslog( "live timer %s added", *newTimer->ToDescr() ); + newTimer.release(); } - Timers.Add( newTimer.get() ); - Timers.SetModified(); - isyslog( "live timer %s added", *newTimer->ToDescr() ); - newTimer.release(); -} + void TimerManager::DoUpdateTimer( TimerPair& timerData ) + { + if ( Timers.BeingEdited() ) { + StoreError( timerData, tr("Timers are being edited - try again later") ); + return; + } -void TimerManager::DoUpdateTimer( TimerPair& timerData ) -{ - if ( Timers.BeingEdited() ) { - StoreError( timerData, tr("Timers are being edited - try again later") ); - return; - } + cTimer* oldTimer = Timers.GetTimer( timerData.first ); + if ( oldTimer == 0 ) { + StoreError( timerData, tr("Timer not defined") ); + return; + } - cTimer* oldTimer = Timers.GetTimer( timerData.first ); - if ( oldTimer == 0 ) { - StoreError( timerData, tr("Timer not defined") ); - return; - } + cTimer copy = *oldTimer; + if ( !copy.Parse( timerData.second.c_str() ) ) { + StoreError( timerData, tr("Error in timer settings") ); + return; + } - cTimer copy = *oldTimer; - if ( !copy.Parse( timerData.second.c_str() ) ) { - StoreError( timerData, tr("Error in timer settings") ); - return; + *oldTimer = copy; + Timers.SetModified(); + isyslog("live timer %s modified (%s)", *oldTimer->ToDescr(), oldTimer->HasFlags(tfActive) ? "active" : "inactive"); } - *oldTimer = copy; - Timers.SetModified(); - isyslog("live timer %s modified (%s)", *oldTimer->ToDescr(), oldTimer->HasFlags(tfActive) ? "active" : "inactive"); -} + void TimerManager::DoDeleteTimer( TimerPair& timerData ) + { + if ( Timers.BeingEdited() ) { + StoreError( timerData, tr("Timers are being edited - try again later") ); + return; + } -void TimerManager::DoDeleteTimer( TimerPair& timerData ) -{ - if ( Timers.BeingEdited() ) { - StoreError( timerData, tr("Timers are being edited - try again later") ); - return; - } + cTimer* oldTimer = Timers.GetTimer( timerData.first ); + if ( oldTimer == 0 ) { + StoreError( timerData, tr("Timer not defined") ); + return; + } - cTimer* oldTimer = Timers.GetTimer( timerData.first ); - if ( oldTimer == 0 ) { - StoreError( timerData, tr("Timer not defined") ); - return; + cTimer copy = *oldTimer; + if ( oldTimer->Recording() ) { + oldTimer->Skip(); + cRecordControls::Process( time( 0 ) ); + } + Timers.Del( oldTimer ); + Timers.SetModified(); + isyslog("live timer %s deleted", *copy.ToDescr()); } - cTimer copy = *oldTimer; - if ( oldTimer->Recording() ) { - oldTimer->Skip(); - cRecordControls::Process( time( 0 ) ); - } - Timers.Del( oldTimer ); - Timers.SetModified(); - isyslog("live timer %s deleted", *copy.ToDescr()); -} + void TimerManager::DoToggleTimer( TimerPair& timerData ) + { + if ( Timers.BeingEdited() ) { + StoreError( timerData, tr("Timers are being edited - try again later") ); + return; + } -void TimerManager::DoToggleTimer( TimerPair& timerData ) -{ - if ( Timers.BeingEdited() ) { - StoreError( timerData, tr("Timers are being edited - try again later") ); - return; - } + cTimer* toggleTimer = Timers.GetTimer( timerData.first ); + if ( toggleTimer == 0 ) { + StoreError( timerData, tr("Timer not defined") ); + return; + } - cTimer* toggleTimer = Timers.GetTimer( timerData.first ); - if ( toggleTimer == 0 ) { - StoreError( timerData, tr("Timer not defined") ); - return; + toggleTimer->OnOff(); + Timers.SetModified(); + isyslog("live timer %s toggled %s", *toggleTimer->ToDescr(), toggleTimer->HasFlags(tfActive) ? "on" : "off"); } - toggleTimer->OnOff(); - Timers.SetModified(); - isyslog("live timer %s toggled %s", *toggleTimer->ToDescr(), toggleTimer->HasFlags(tfActive) ? "on" : "off"); -} - -void TimerManager::StoreError( TimerPair const& timerData, std::string const& error ) -{ - m_failedUpdates.push_back( ErrorPair( timerData, error ) ); -} + void TimerManager::StoreError( TimerPair const& timerData, std::string const& error ) + { + m_failedUpdates.push_back( ErrorPair( timerData, error ) ); + } -string TimerManager::GetError( TimerPair const& timerData ) -{ - for ( ErrorList::iterator error = m_failedUpdates.begin(); error != m_failedUpdates.end(); ++error ) { - if ( error->first == timerData ) { - string message = error->second; - m_failedUpdates.erase( error ); - return message; + string TimerManager::GetError( TimerPair const& timerData ) + { + for ( ErrorList::iterator error = m_failedUpdates.begin(); error != m_failedUpdates.end(); ++error ) { + if ( error->first == timerData ) { + string message = error->second; + m_failedUpdates.erase( error ); + return message; + } } + return ""; } - return ""; -} -const cTimer* TimerManager::GetTimer(tEventID eventid, tChannelID channelid) -{ - cMutexLock timersLock( &LiveTimerManager() ); - SortedTimers& timers = LiveTimerManager().GetTimers(); + const cTimer* TimerManager::GetTimer(tEventID eventid, tChannelID channelid) + { + cMutexLock timersLock( &LiveTimerManager() ); + SortedTimers& timers = LiveTimerManager().GetTimers(); + + for ( SortedTimers::iterator timer = timers.begin(); timer != timers.end(); ++timer ) + if (timer->Channel() && timer->Channel()->GetChannelID() == channelid) + { + if (!timer->Event()) timer->SetEventFromSchedule(); + if (timer->Event() && timer->Event()->EventID() == eventid) + return &*timer; + } + return NULL; + } - for ( SortedTimers::iterator timer = timers.begin(); timer != timers.end(); ++timer ) - if (timer->Channel() && timer->Channel()->GetChannelID() == channelid) - { - if (!timer->Event()) timer->SetEventFromSchedule(); - if (timer->Event() && timer->Event()->EventID() == eventid) - return &*timer; - } - return NULL; -} - -TimerManager& LiveTimerManager() -{ - static TimerManager instance; - return instance; -} + TimerManager& LiveTimerManager() + { + static TimerManager instance; + return instance; + } } // namespace vdrlive @@ -11,69 +11,69 @@ namespace vdrlive { -class SortedTimers: public std::list< cTimer > -{ - friend class TimerManager; + class SortedTimers: public std::list< cTimer > + { + friend class TimerManager; -public: - std::string GetTimerId( cTimer const& timer ); - cTimer* GetByTimerId( std::string const& timerid ); + public: + std::string GetTimerId( cTimer const& timer ); + cTimer* GetByTimerId( std::string const& timerid ); - bool Modified() { return Timers.Modified( m_state ); } - static std::string GetTimerDays(cTimer const& timer); - static std::string GetTimerInfo(cTimer const& timer); + bool Modified() { return Timers.Modified( m_state ); } + static std::string GetTimerDays(cTimer const& timer); + static std::string GetTimerInfo(cTimer const& timer); -private: - SortedTimers(); - SortedTimers( SortedTimers const& ); + private: + SortedTimers(); + SortedTimers( SortedTimers const& ); - int m_state; + int m_state; - void ReloadTimers( bool initial = false ); -}; + void ReloadTimers( bool initial = false ); + }; -class TimerManager: public cMutex -{ - friend TimerManager& LiveTimerManager(); + class TimerManager: public cMutex + { + friend TimerManager& LiveTimerManager(); -public: - SortedTimers& GetTimers() { return m_timers; } + public: + SortedTimers& GetTimers() { return m_timers; } - void UpdateTimer( cTimer* timer, int flags, tChannelID& channel, std::string const& weekdays, std::string const& day, - int start, int stop, int priority, int lifetime, std::string const& title, std::string const& aux ); + void UpdateTimer( cTimer* timer, int flags, tChannelID& channel, std::string const& weekdays, std::string const& day, + int start, int stop, int priority, int lifetime, std::string const& title, std::string const& aux ); - void DelTimer( cTimer* timer); - void ToggleTimerActive( cTimer* timer); - // may only be called from Plugin::MainThreadHook - void DoPendingWork(); - void DoReloadTimers() { m_timers.ReloadTimers(); } - const cTimer* GetTimer(tEventID eventid, tChannelID channelid); + void DelTimer( cTimer* timer); + void ToggleTimerActive( cTimer* timer); + // may only be called from Plugin::MainThreadHook + void DoPendingWork(); + void DoReloadTimers() { m_timers.ReloadTimers(); } + const cTimer* GetTimer(tEventID eventid, tChannelID channelid); -private: - typedef std::pair< cTimer*, std::string > TimerPair; - typedef std::pair< TimerPair, std::string > ErrorPair; - typedef std::list< TimerPair > TimerList; - typedef std::list< ErrorPair > ErrorList; + private: + typedef std::pair< cTimer*, std::string > TimerPair; + typedef std::pair< TimerPair, std::string > ErrorPair; + typedef std::list< TimerPair > TimerList; + typedef std::list< ErrorPair > ErrorList; - TimerManager(); - TimerManager( TimerManager const& ); + TimerManager(); + TimerManager( TimerManager const& ); - SortedTimers m_timers; - TimerList m_updateTimers; - ErrorList m_failedUpdates; - cCondVar m_updateWait; + SortedTimers m_timers; + TimerList m_updateTimers; + ErrorList m_failedUpdates; + cCondVar m_updateWait; - void DoUpdateTimers(); - void DoInsertTimer( TimerPair& timerData ); - void DoUpdateTimer( TimerPair& timerData ); - void DoDeleteTimer( TimerPair& timerData ); - void DoToggleTimer( TimerPair& timerData ); + void DoUpdateTimers(); + void DoInsertTimer( TimerPair& timerData ); + void DoUpdateTimer( TimerPair& timerData ); + void DoDeleteTimer( TimerPair& timerData ); + void DoToggleTimer( TimerPair& timerData ); - void StoreError( TimerPair const& timerData, std::string const& error ); - std::string GetError( TimerPair const& timerData ); -}; + void StoreError( TimerPair const& timerData, std::string const& error ); + std::string GetError( TimerPair const& timerData ); + }; -TimerManager& LiveTimerManager(); + TimerManager& LiveTimerManager(); } // namespace vdrlive |