diff options
author | Johann Friedrichs <johann.friedrichs@web.de> | 2018-03-21 12:14:55 +0100 |
---|---|---|
committer | Johann Friedrichs <johann.friedrichs@web.de> | 2018-03-21 12:14:55 +0100 |
commit | e8a0e569152c50d6084f252d12854b8fd4e74466 (patch) | |
tree | 5a90ef7ea08ff2096df157ca109c5268cdc04903 /switchtimer_thread.c | |
parent | 9c7d95ff8d6ba965cb23147507a859b1fd0491d6 (diff) | |
download | vdr-plugin-epgsearch-e8a0e569152c50d6084f252d12854b8fd4e74466.tar.gz vdr-plugin-epgsearch-e8a0e569152c50d6084f252d12854b8fd4e74466.tar.bz2 |
unified indentation
Diffstat (limited to 'switchtimer_thread.c')
-rw-r--r-- | switchtimer_thread.c | 208 |
1 files changed, 102 insertions, 106 deletions
diff --git a/switchtimer_thread.c b/switchtimer_thread.c index be1c12a..5aea47b 100644 --- a/switchtimer_thread.c +++ b/switchtimer_thread.c @@ -33,125 +33,121 @@ The project's page is at http://winni.vdr-developer.org/epgsearch cSwitchTimerThread *cSwitchTimerThread::m_Instance = NULL; cSwitchTimerThread::cSwitchTimerThread(void) - : cThread("EPGSearch: switchtimer") + : cThread("EPGSearch: switchtimer") { - m_Active = false; - m_lastUpdate = time(NULL); + m_Active = false; + m_lastUpdate = time(NULL); } -cSwitchTimerThread::~cSwitchTimerThread() { - if (m_Active) - Stop(); +cSwitchTimerThread::~cSwitchTimerThread() +{ + if (m_Active) + Stop(); } -void cSwitchTimerThread::Init(void) { - if (m_Instance == NULL && SwitchTimers.Count() > 0) { - m_Instance = new cSwitchTimerThread; - m_Instance->Start(); - } +void cSwitchTimerThread::Init(void) +{ + if (m_Instance == NULL && SwitchTimers.Count() > 0) { + m_Instance = new cSwitchTimerThread; + m_Instance->Start(); + } } -void cSwitchTimerThread::Exit(void) { - if (m_Instance != NULL) { - m_Instance->Stop(); - DELETENULL(m_Instance); - } +void cSwitchTimerThread::Exit(void) +{ + if (m_Instance != NULL) { + m_Instance->Stop(); + DELETENULL(m_Instance); + } } -void cSwitchTimerThread::Stop(void) { - m_Active = false; - Wait.Signal(); - Cancel(6); +void cSwitchTimerThread::Stop(void) +{ + m_Active = false; + Wait.Signal(); + Cancel(6); } void cSwitchTimerThread::Action(void) { - m_Active = true; - - // let VDR do its startup - if (!cPluginEpgsearch::VDR_readyafterStartup) - LogFile.Log(2, "SwitchTimerThread: waiting for VDR to become ready..."); - while(m_Active && !cPluginEpgsearch::VDR_readyafterStartup) - Wait.Wait(1000); - - time_t nextUpdate = time(NULL); - while (m_Active) - { - time_t now = time(NULL); - if (now >= nextUpdate) - { - LogFile.Log(3,"locking switch timers"); - SwitchTimers.cMutex::Lock(); - LogFile.Log(3,"switch timer check started"); - cSwitchTimer* switchTimer = SwitchTimers.First(); - while (switchTimer && m_Active && Running()) - { - if (switchTimer->startTime - now < switchTimer->switchMinsBefore*60 + MSG_DELAY + 1) - { - LOCK_CHANNELS_READ; - const cChannel *channel = Channels->GetByChannelID(switchTimer->channelID, true, true); - bool doSwitch = (switchTimer->mode == 0); - bool doAsk = (switchTimer->mode == 2); - bool doUnmute = switchTimer->unmute; - SwitchTimers.Del(switchTimer); - - const cEvent* event = switchTimer->Event(); - if (event && channel && (event->EndTime() >= now)) - { - cString Message = cString::sprintf("%s: %s - %s", event->Title(), - CHANNELNAME(channel), GETTIMESTRING(event)); - cString SwitchCmd = cString::sprintf("CHAN %d", channel->Number()); - // switch - if (doSwitch) - { - LogFile.Log(1,"switching to channel %d", channel->Number()); - if (cDevice::CurrentChannel() != channel->Number()) - SendViaSVDRP(SwitchCmd); - - if (doUnmute && cDevice::PrimaryDevice()->IsMute()) - cDevice::PrimaryDevice()->ToggleMute(); - } - if (!doAsk) - SendMsg(Message); - - if (doAsk) - { - cString Message = cString::sprintf(tr("Switch to (%d) '%s'?"), channel->Number(), event->Title()); - if(SendMsg(Message, true, MSG_DELAY) == kOk) - { - LogFile.Log(1,"switching to channel %d", channel->Number()); - if (cDevice::CurrentChannel() != channel->Number()) - SendViaSVDRP(SwitchCmd); - - if (doUnmute && cDevice::PrimaryDevice()->IsMute()) - cDevice::PrimaryDevice()->ToggleMute(); - - } - } - - if (m_Active && Running()) - Wait.Wait(1000 * MSG_DELAY); - } - SwitchTimers.Save(); - break; + m_Active = true; + + // let VDR do its startup + if (!cPluginEpgsearch::VDR_readyafterStartup) + LogFile.Log(2, "SwitchTimerThread: waiting for VDR to become ready..."); + while (m_Active && !cPluginEpgsearch::VDR_readyafterStartup) + Wait.Wait(1000); + + time_t nextUpdate = time(NULL); + while (m_Active) { + time_t now = time(NULL); + if (now >= nextUpdate) { + LogFile.Log(3, "locking switch timers"); + SwitchTimers.cMutex::Lock(); + LogFile.Log(3, "switch timer check started"); + cSwitchTimer* switchTimer = SwitchTimers.First(); + while (switchTimer && m_Active && Running()) { + if (switchTimer->startTime - now < switchTimer->switchMinsBefore * 60 + MSG_DELAY + 1) { + LOCK_CHANNELS_READ; + const cChannel *channel = Channels->GetByChannelID(switchTimer->channelID, true, true); + bool doSwitch = (switchTimer->mode == 0); + bool doAsk = (switchTimer->mode == 2); + bool doUnmute = switchTimer->unmute; + SwitchTimers.Del(switchTimer); + + const cEvent* event = switchTimer->Event(); + if (event && channel && (event->EndTime() >= now)) { + cString Message = cString::sprintf("%s: %s - %s", event->Title(), + CHANNELNAME(channel), GETTIMESTRING(event)); + cString SwitchCmd = cString::sprintf("CHAN %d", channel->Number()); + // switch + if (doSwitch) { + LogFile.Log(1, "switching to channel %d", channel->Number()); + if (cDevice::CurrentChannel() != channel->Number()) + SendViaSVDRP(SwitchCmd); + + if (doUnmute && cDevice::PrimaryDevice()->IsMute()) + cDevice::PrimaryDevice()->ToggleMute(); + } + if (!doAsk) + SendMsg(Message); + + if (doAsk) { + cString Message = cString::sprintf(tr("Switch to (%d) '%s'?"), channel->Number(), event->Title()); + if (SendMsg(Message, true, MSG_DELAY) == kOk) { + LogFile.Log(1, "switching to channel %d", channel->Number()); + if (cDevice::CurrentChannel() != channel->Number()) + SendViaSVDRP(SwitchCmd); + + if (doUnmute && cDevice::PrimaryDevice()->IsMute()) + cDevice::PrimaryDevice()->ToggleMute(); + + } + } + + if (m_Active && Running()) + Wait.Wait(1000 * MSG_DELAY); + } + SwitchTimers.Save(); + break; + } + switchTimer = SwitchTimers.Next(switchTimer); } - switchTimer = SwitchTimers.Next(switchTimer); - } - SwitchTimers.Unlock(); - LogFile.Log(3,"switch timer check finished"); - if (m_Active && Running()) - Wait.Wait(1000 * MSG_DELAY); - m_lastUpdate = time(NULL); - nextUpdate = long(m_lastUpdate/60)*60+ 60 - MSG_DELAY ; // check at each full minute minus 5sec - if (SwitchTimers.Count() == 0) - m_Active = false; - if (!Running()) - m_Active = false; - } - while (m_Active && time(NULL)%MSG_DELAY != 0) // sync heart beat to MSG_DELAY - Wait.Wait(1000); - Wait.Wait(1000); - }; - m_Instance = NULL; + SwitchTimers.Unlock(); + LogFile.Log(3, "switch timer check finished"); + if (m_Active && Running()) + Wait.Wait(1000 * MSG_DELAY); + m_lastUpdate = time(NULL); + nextUpdate = long(m_lastUpdate / 60) * 60 + 60 - MSG_DELAY ; // check at each full minute minus 5sec + if (SwitchTimers.Count() == 0) + m_Active = false; + if (!Running()) + m_Active = false; + } + while (m_Active && time(NULL) % MSG_DELAY != 0) // sync heart beat to MSG_DELAY + Wait.Wait(1000); + Wait.Wait(1000); + }; + m_Instance = NULL; } |