diff options
Diffstat (limited to 'recmanager.c')
-rw-r--r-- | recmanager.c | 185 |
1 files changed, 183 insertions, 2 deletions
diff --git a/recmanager.c b/recmanager.c index 7ad6f4c..3ad735c 100644 --- a/recmanager.c +++ b/recmanager.c @@ -10,6 +10,7 @@ #include "tools.h" #include "switchtimer.h" #include "timerconflict.h" +#include <vdr/timers.h> #include "recmanager.h" static int CompareRecording(const void *p1, const void *p2) { @@ -55,15 +56,27 @@ bool cRecManager::CheckEventForTimer(const cEvent *event) { return hasTimer; } +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) +const cTimer *cRecManager::GetTimerForEvent(const cEvent *event) { + const cTimer *timer = NULL; +#else cTimer *cRecManager::GetTimerForEvent(const cEvent *event) { cTimer *timer = NULL; +#endif if (tvguideConfig.useRemoteTimers && pRemoteTimers) { RemoteTimers_GetMatch_v1_0 rtMatch; rtMatch.event = event; pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch); timer = rtMatch.timer; +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + return timer; + } + LOCK_TIMERS_READ; + timer = Timers->GetMatch(event); +#else } else timer = Timers.GetMatch(event); +#endif return timer; } @@ -79,19 +92,36 @@ cTimer *cRecManager::createTimer(const cEvent *event, std::string path) { cTimer *cRecManager::createLocalTimer(const cEvent *event, std::string path) { cTimer *timer = new cTimer(event); +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_TIMERS_WRITE; + cTimer *t = Timers->GetTimer(timer); +#else cTimer *t = Timers.GetTimer(timer); +#endif if (t) { t->OnOff(); +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + t->SetEvent(event); +#else t->SetEventFromSchedule(); +#endif delete timer; timer = t; isyslog("timer %s reactivated", *t->ToDescr()); } else { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + Timers->Add(timer); +#else Timers.Add(timer); +#endif isyslog("timer %s added (active)", *timer->ToDescr()); } SetTimerPath(timer, event, path); +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + Timers->SetModified(); +#else Timers.SetModified(); +#endif return timer; } @@ -148,7 +178,12 @@ void cRecManager::SetTimerPath(cTimer *timer, const cEvent *event, std::string p } void cRecManager::DeleteTimer(int timerID) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_TIMERS_READ; + const cTimer *t = Timers->Get(timerID); +#else cTimer *t = Timers.Get(timerID); +#endif if (!t) return; DeleteTimer(t); @@ -165,21 +200,43 @@ void cRecManager::DeleteTimer(const cEvent *event) { } void cRecManager::DeleteLocalTimer(const cEvent *event) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_TIMERS_READ; + const cTimer *t = Timers->GetMatch(event); +#else cTimer *t = Timers.GetMatch(event); +#endif if (!t) return; DeleteTimer(t); } +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) +void cRecManager::DeleteTimer(const cTimer *timer) { + LOCK_TIMERS_WRITE; + cTimers* timers = Timers; + cTimer* t = timers->GetTimer((cTimer*)timer); // #TODO dirty cast + + if (t->Recording()) { + t->Skip(); + cRecordControls::Process(timers, time(NULL)); + } +#else void cRecManager::DeleteTimer(cTimer *timer) { if (timer->Recording()) { timer->Skip(); cRecordControls::Process(time(NULL)); } +#endif isyslog("timer %s deleted", *timer->ToDescr()); +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + timers->Del(t, true); + timers->SetModified(); +#else Timers.Del(timer, true); Timers.SetModified(); +#endif } void cRecManager::DeleteRemoteTimer(const cEvent *event) { @@ -196,7 +253,11 @@ void cRecManager::DeleteRemoteTimer(const cEvent *event) { } } +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) +void cRecManager::SaveTimer(const cTimer *timer, cTimer newTimerSettings) { +#else void cRecManager::SaveTimer(cTimer *timer, cTimer newTimerSettings) { +#endif if (!timer) return; @@ -208,33 +269,63 @@ void cRecManager::SaveTimer(cTimer *timer, cTimer newTimerSettings) { int stop = newTimerSettings.Stop(); std::string fileName = newTimerSettings.File(); +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + ((cTimer*)timer)->SetDay(day); + ((cTimer*)timer)->SetStart(start); + ((cTimer*)timer)->SetStop(stop); + ((cTimer*)timer)->SetPriority(prio); + ((cTimer*)timer)->SetLifetime(lifetime); + ((cTimer*)timer)->SetFile(fileName.c_str()); +#else timer->SetDay(day); timer->SetStart(start); timer->SetStop(stop); timer->SetPriority(prio); timer->SetLifetime(lifetime); timer->SetFile(fileName.c_str()); - +#endif + if (timer->HasFlags(tfActive) && !active) +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + ((cTimer*)timer)->ClrFlags(tfActive); + else if (!timer->HasFlags(tfActive) && active) + ((cTimer*)timer)->SetFlags(tfActive); + +#else timer->ClrFlags(tfActive); else if (!timer->HasFlags(tfActive) && active) timer->SetFlags(tfActive); - + timer->SetEventFromSchedule(); +#endif if (tvguideConfig.useRemoteTimers && pRemoteTimers) { RemoteTimers_Timer_v1_0 rt; +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + rt.timer = (cTimer*)timer; +#else rt.timer = timer; +#endif if (!pRemoteTimers->Service("RemoteTimers::ModTimer-v1.0", &rt)) rt.timer = NULL; RefreshRemoteTimers(); } else { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_TIMERS_WRITE; + Timers->SetModified(); +#else Timers.SetModified(); +#endif } } bool cRecManager::IsRecorded(const cEvent *event) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_TIMERS_WRITE; + cTimer *timer = Timers->GetMatch(event); +#else cTimer *timer = Timers.GetMatch(event); +#endif if (!timer) return false; return timer->Recording(); @@ -260,7 +351,10 @@ cTVGuideTimerConflicts *cRecManager::CheckTimerConflict(void) { } void cRecManager::CreateSeriesTimer(cTimer *seriesTimer) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) +#else seriesTimer->SetEventFromSchedule(); +#endif if (tvguideConfig.useRemoteTimers && pRemoteTimers) { RemoteTimers_Timer_v1_0 rt; rt.timer = seriesTimer; @@ -268,8 +362,15 @@ void cRecManager::CreateSeriesTimer(cTimer *seriesTimer) { isyslog("%s", *rt.errorMsg); RefreshRemoteTimers(); } else { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_TIMERS_WRITE; + cTimers* timers = Timers; + timers->Add(seriesTimer); + timers->SetModified(); +#else Timers.Add(seriesTimer); Timers.SetModified(); +#endif } } @@ -316,9 +417,14 @@ const cEvent **cRecManager::PerformSearchTimerSearch(std::string epgSearchString numResults = results.size(); if (numResults > 0) { searchResults = new const cEvent *[numResults]; +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_SCHEDULES_READ; + const cSchedules* schedules = Schedules; +#else cSchedulesLock schedulesLock; const cSchedules *schedules; schedules = cSchedules::Schedules(schedulesLock); +#endif const cEvent *event = NULL; int index=0; for (std::list<std::string>::iterator it=results.begin(); it != results.end(); ++it) { @@ -328,7 +434,12 @@ const cEvent **cRecManager::PerformSearchTimerSearch(std::string epgSearchString int eventID = atoi(flds[1].c_str()); std::string channelID = flds[7]; tChannelID chanID = tChannelID::FromString(channelID.c_str()); +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_CHANNELS_READ; + const cChannel *channel = Channels->GetByChannelID(chanID); +#else cChannel *channel = Channels.GetByChannelID(chanID); +#endif if (channel) { const cSchedule *Schedule = NULL; Schedule = schedules->GetSchedule(channel); @@ -435,24 +546,45 @@ void cRecManager::DeleteSearchTimer(cTVGuideSearchTimer *searchTimer, bool delTi return; int searchTimerID = searchTimer->GetID(); if (delTimers) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_TIMERS_WRITE; + cTimer *timer = Timers->First(); +#else cTimer *timer = Timers.First(); +#endif while(timer) { if (!timer->Recording()) { char* searchID = GetAuxValue(timer, "s-id"); if (searchID) { if (searchTimerID == atoi(searchID)) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + cTimer* timerNext = Timers->Next(timer); +#else cTimer* timerNext = Timers.Next(timer); +#endif DeleteTimer(timer); timer = timerNext; } else { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + timer = Timers->Next(timer); +#else timer = Timers.Next(timer); +#endif } free(searchID); } else { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + timer = Timers->Next(timer); +#else timer = Timers.Next(timer); +#endif } } else { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + timer = Timers->Next(timer); +#else timer = Timers.Next(timer); +#endif } } } @@ -505,13 +637,24 @@ void cRecManager::DeleteSwitchTimer(const cEvent *event) { } } +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) +const cRecording **cRecManager::SearchForRecordings(std::string searchString, int &numResults) { + + const cRecording **matchingRecordings = NULL; +#else cRecording **cRecManager::SearchForRecordings(std::string searchString, int &numResults) { cRecording **matchingRecordings = NULL; +#endif int num = 0; numResults = 0; +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_RECORDINGS_READ; + for (const cRecording *recording = Recordings->First(); recording; recording = Recordings->Next(recording)) { +#else for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording)) { +#endif std::string s1 = recording->Name(); std::string s2 = searchString; if (s1.empty() || s2.empty()) continue; @@ -542,7 +685,11 @@ cRecording **cRecManager::SearchForRecordings(std::string searchString, int &num } if (match) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + matchingRecordings = (const cRecording **)realloc(matchingRecordings, (num + 1) * sizeof(cRecording *)); +#else matchingRecordings = (cRecording **)realloc(matchingRecordings, (num + 1) * sizeof(cRecording *)); +#endif matchingRecordings[num++] = recording; } } @@ -619,10 +766,26 @@ void cRecManager::GetFavorites(std::vector<cTVGuideSearchTimer> *favorites) { const cEvent **cRecManager::WhatsOnNow(bool nowOrNext, int &numResults) { std::vector<const cEvent*> tmpResults; +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_SCHEDULES_READ; + LOCK_CHANNELS_READ; + const cChannels* channels = Channels; + const cSchedules* schedules = Schedules; +#else cSchedulesLock schedulesLock; const cSchedules *schedules = cSchedules::Schedules(schedulesLock); +#endif const cChannel *startChannel = NULL, *stopChannel = NULL; if (tvguideConfig.favLimitChannels) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + startChannel = Channels->GetByNumber(tvguideConfig.favStartChannel); + stopChannel = Channels->GetByNumber(tvguideConfig.favStopChannel); + } + if (!startChannel) + startChannel = Channels->First(); + + for (const cChannel *channel = startChannel; channel; channel = Channels->Next(channel)) { +#else startChannel = Channels.GetByNumber(tvguideConfig.favStartChannel); stopChannel = Channels.GetByNumber(tvguideConfig.favStopChannel); } @@ -630,6 +793,7 @@ const cEvent **cRecManager::WhatsOnNow(bool nowOrNext, int &numResults) { startChannel = Channels.First(); for (const cChannel *channel = startChannel; channel; channel = Channels.Next(channel)) { +#endif if (channel->GroupSep()) continue; const cSchedule *Schedule = schedules->GetSchedule(channel); if (!Schedule) continue; @@ -679,10 +843,26 @@ const cEvent **cRecManager::UserDefinedTime(int userTime, int &numResults) { if (searchTime < now) searchTime += 24*60*60; +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + LOCK_CHANNELS_READ; + LOCK_SCHEDULES_READ; + const cChannels* channels = Channels; + const cSchedules* schedules = Schedules; +#else cSchedulesLock schedulesLock; const cSchedules *schedules = cSchedules::Schedules(schedulesLock); +#endif const cChannel *startChannel = NULL, *stopChannel = NULL; if (tvguideConfig.favLimitChannels) { +#if defined (APIVERSNUM) && (APIVERSNUM >= 20301) + startChannel = Channels->GetByNumber(tvguideConfig.favStartChannel); + stopChannel = Channels->GetByNumber(tvguideConfig.favStopChannel); + } + if (!startChannel) + startChannel = Channels->First(); + + for (const cChannel *channel = startChannel; channel; channel = Channels->Next(channel)) { +#else startChannel = Channels.GetByNumber(tvguideConfig.favStartChannel); stopChannel = Channels.GetByNumber(tvguideConfig.favStopChannel); } @@ -690,6 +870,7 @@ const cEvent **cRecManager::UserDefinedTime(int userTime, int &numResults) { startChannel = Channels.First(); for (const cChannel *channel = startChannel; channel; channel = Channels.Next(channel)) { +#endif if (channel->GroupSep()) continue; const cSchedule *Schedule = schedules->GetSchedule(channel); if (!Schedule) continue; |