From 2766937dd58f9e6650df207ea137afaaa653903f Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Mon, 24 Sep 2018 17:23:54 +0200 Subject: [PVR] EpgContainer: Code cleanup. --- xbmc/pvr/channels/PVRChannel.cpp | 2 +- xbmc/pvr/epg/Epg.cpp | 11 +-- xbmc/pvr/epg/Epg.h | 2 - xbmc/pvr/epg/EpgContainer.cpp | 200 ++++++++++++++++++--------------------- xbmc/pvr/epg/EpgContainer.h | 131 +++++++++++-------------- 5 files changed, 154 insertions(+), 192 deletions(-) diff --git a/xbmc/pvr/channels/PVRChannel.cpp b/xbmc/pvr/channels/PVRChannel.cpp index b8c2bd9ecc..143736f3dd 100644 --- a/xbmc/pvr/channels/PVRChannel.cpp +++ b/xbmc/pvr/channels/PVRChannel.cpp @@ -133,7 +133,7 @@ bool CPVRChannel::Delete(void) { CPVRChannelPtr empty; epg->SetChannel(empty); - CServiceBroker::GetPVRManager().EpgContainer().DeleteEpg(*epg, true); + CServiceBroker::GetPVRManager().EpgContainer().DeleteEpg(epg, true); CSingleLock lock(m_critSection); m_bEPGCreated = false; } diff --git a/xbmc/pvr/epg/Epg.cpp b/xbmc/pvr/epg/Epg.cpp index dd47dfc50a..67b5b8dcb7 100644 --- a/xbmc/pvr/epg/Epg.cpp +++ b/xbmc/pvr/epg/Epg.cpp @@ -17,7 +17,6 @@ #include "ServiceBroker.h" #include "guilib/LocalizeStrings.h" #include "settings/AdvancedSettings.h" -#include "settings/Settings.h" #include "threads/SingleLock.h" #include "utils/log.h" @@ -293,7 +292,7 @@ CPVREpgInfoTagPtr CPVREpg::GetTagBetween(const CDateTime &beginTime, const CDate if (tag) { m_tags.insert(make_pair(tag->StartAsUTC(), tag)); - UpdateEntry(tag, !CServiceBroker::GetSettings()->GetBool(CSettings::SETTING_EPG_IGNOREDBFORCLIENT)); + UpdateEntry(tag, !CServiceBroker::GetPVRManager().EpgContainer().IgnoreDB()); } } @@ -402,7 +401,7 @@ bool CPVREpg::UpdateEntries(const CPVREpg &epg, bool bStoreInDb /* = true */) CDateTime CPVREpg::GetLastScanTime(void) { - bool bIgnore = CServiceBroker::GetSettings()->GetBool(CSettings::SETTING_EPG_IGNOREDBFORCLIENT); + bool bIgnore = CServiceBroker::GetPVRManager().EpgContainer().IgnoreDB(); CPVREpgDatabasePtr database = CServiceBroker::GetPVRManager().EpgContainer().GetEpgDatabase(); CDateTime lastScanTime; @@ -603,7 +602,7 @@ int CPVREpg::Get(CFileItemList &results, const CPVREpgSearchFilter &filter) cons bool CPVREpg::Persist(void) { - if (CServiceBroker::GetSettings()->GetBool(CSettings::SETTING_EPG_IGNOREDBFORCLIENT) || !NeedsSave()) + if (CServiceBroker::GetPVRManager().EpgContainer().IgnoreDB() || !NeedsSave()) return true; CPVREpgDatabasePtr database = CServiceBroker::GetPVRManager().EpgContainer().GetEpgDatabase(); @@ -831,13 +830,13 @@ bool CPVREpg::LoadFromClients(time_t start, time_t end, bool bForceUpdate) { CPVREpg tmpEpg(channel); if (tmpEpg.UpdateFromScraper(start, end, bForceUpdate)) - bReturn = UpdateEntries(tmpEpg, !CServiceBroker::GetSettings()->GetBool(CSettings::SETTING_EPG_IGNOREDBFORCLIENT)); + bReturn = UpdateEntries(tmpEpg, !CServiceBroker::GetPVRManager().EpgContainer().IgnoreDB()); } else { CPVREpg tmpEpg(m_iEpgID, m_strName, m_strScraperName); if (tmpEpg.UpdateFromScraper(start, end, bForceUpdate)) - bReturn = UpdateEntries(tmpEpg, !CServiceBroker::GetSettings()->GetBool(CSettings::SETTING_EPG_IGNOREDBFORCLIENT)); + bReturn = UpdateEntries(tmpEpg, !CServiceBroker::GetPVRManager().EpgContainer().IgnoreDB()); } return bReturn; diff --git a/xbmc/pvr/epg/Epg.h b/xbmc/pvr/epg/Epg.h index 9f5bb31509..34c0ada884 100644 --- a/xbmc/pvr/epg/Epg.h +++ b/xbmc/pvr/epg/Epg.h @@ -24,8 +24,6 @@ /** EPG container for CPVREpgInfoTag instances */ namespace PVR { - typedef std::map EPGMAP; - class CPVREpg : public Observable { friend class CPVREpgDatabase; diff --git a/xbmc/pvr/epg/EpgContainer.cpp b/xbmc/pvr/epg/EpgContainer.cpp index 678d2e9f82..84555b5814 100644 --- a/xbmc/pvr/epg/EpgContainer.cpp +++ b/xbmc/pvr/epg/EpgContainer.cpp @@ -97,8 +97,7 @@ void CEpgTagStateChange::Deliver() // update if (!epg->UpdateEntry(m_epgtag, m_state, false)) - CLog::LogF(LOGERROR, "Update failed for epgtag change for channel '%s'", - channel->ChannelName().c_str()); + CLog::LogF(LOGERROR, "Update failed for epgtag change for channel '%s'", channel->ChannelName().c_str()); } CPVREpgContainer::CPVREpgContainer(void) : @@ -112,23 +111,14 @@ CPVREpgContainer::CPVREpgContainer(void) : CSettings::SETTING_EPG_PREVENTUPDATESWHILEPLAYINGTV }) { - m_bStop = true; - m_bIsUpdating = false; - m_bIsInitialising = true; - m_iNextEpgId = 0; - m_bPreventUpdates = false; + m_bStop = true; // base class member m_updateEvent.Reset(); - m_bStarted = false; - m_bLoaded = false; - m_pendingUpdates = 0; - m_iLastEpgCleanup = 0; - m_iNextEpgActiveTagCheck = 0; - m_iNextEpgUpdate = 0; } CPVREpgContainer::~CPVREpgContainer(void) { - Unload(); + Stop(); + Clear(); } CPVREpgDatabasePtr CPVREpgContainer::GetEpgDatabase() const @@ -140,12 +130,6 @@ CPVREpgDatabasePtr CPVREpgContainer::GetEpgDatabase() const return m_database; } -void CPVREpgContainer::Unload(void) -{ - Stop(); - Clear(false); -} - bool CPVREpgContainer::IsStarted(void) const { CSingleLock lock(m_critSection); @@ -158,23 +142,19 @@ unsigned int CPVREpgContainer::NextEpgId(void) return ++m_iNextEpgId; } -void CPVREpgContainer::Clear(bool bClearDb /* = false */) +void CPVREpgContainer::Clear() { /* make sure the update thread is stopped */ bool bThreadRunning = !m_bStop; - if (bThreadRunning && !Stop()) - { - CLog::LogF(LOGERROR, "Could not stop the EPG update thread"); - return; - } + if (bThreadRunning) + Stop(); { CSingleLock lock(m_critSection); /* clear all epg tables and remove pointers to epg tables on channels */ for (const auto &epgEntry : m_epgs) - { epgEntry.second->UnregisterObserver(this); - } + m_epgs.clear(); m_iNextEpgUpdate = 0; m_bStarted = false; @@ -183,13 +163,8 @@ void CPVREpgContainer::Clear(bool bClearDb /* = false */) m_bUpdateNotificationPending = false; } - /* clear the database entries */ - if (bClearDb && !IgnoreDB()) - { - m_database->DeleteEpg(); - } - SetChanged(); + { CSingleExit ex(m_critSection); NotifyObservers(ObservableMessageEpgContainer); @@ -205,7 +180,7 @@ public: CPVREpgContainerStartJob() = default; ~CPVREpgContainerStartJob(void) override = default; - bool DoWork(void) override + bool DoWork() override { CServiceBroker::GetPVRManager().EpgContainer().Start(false); return true; @@ -260,7 +235,7 @@ void CPVREpgContainer::Start(bool bAsync) } } -bool CPVREpgContainer::Stop(void) +void CPVREpgContainer::Stop(void) { StopThread(); @@ -268,8 +243,6 @@ bool CPVREpgContainer::Stop(void) CSingleLock lock(m_critSection); m_bStarted = false; - - return true; } void CPVREpgContainer::Notify(const Observable &obs, const ObservableMessage msg) @@ -294,8 +267,8 @@ void CPVREpgContainer::LoadFromDB(void) if (m_bLoaded || IgnoreDB()) return; - bool bLoaded(true); - unsigned int iCounter(0); + bool bLoaded = true; + unsigned int iCounter = 0; CPVRGUIProgressHandler* progressHandler = new CPVRGUIProgressHandler(g_localizeStrings.Get(19250)); // Loading guide from database const CDateTime cleanupTime(CDateTime::GetUTCDateTime() - CDateTimeSpan(GetPastDaysToDisplay(), 0, 0, 0)); @@ -307,7 +280,7 @@ void CPVREpgContainer::LoadFromDB(void) m_database->Unlock(); for (const auto& entry : result) - InsertFromDatabase(entry); + InsertFromDB(entry); for (const auto &epgEntry : m_epgs) { @@ -328,18 +301,16 @@ void CPVREpgContainer::LoadFromDB(void) bool CPVREpgContainer::PersistAll(void) { - bool bReturn(true); + bool bReturn = true; + m_critSection.lock(); - auto copy = m_epgs; + const auto epgs = m_epgs; m_critSection.unlock(); - for (EPGMAP::const_iterator it = copy.begin(); it != copy.end(); ++it) + for (const auto& epg : epgs) { - CPVREpgPtr epg = it->second; - if (epg && epg->NeedsSave()) - { - bReturn &= epg->Persist(); - } + if (epg.second && epg.second->NeedsSave()) + bReturn &= epg.second->Persist(); } return bReturn; @@ -347,9 +318,10 @@ bool CPVREpgContainer::PersistAll(void) void CPVREpgContainer::Process(void) { - time_t iNow(0), iLastSave(0); - bool bUpdateEpg(true); - bool bHasPendingUpdates(false); + time_t iNow = 0; + time_t iLastSave = 0; + bool bUpdateEpg = true; + bool bHasPendingUpdates = false; while (!m_bStop && !g_application.m_bStop) { @@ -462,12 +434,17 @@ void CPVREpgContainer::Process(void) CPVREpgPtr CPVREpgContainer::GetById(int iEpgId) const { + CPVREpgPtr retval; + if (iEpgId < 0) - return CPVREpgPtr(); + return retval; CSingleLock lock(m_critSection); - const auto &epgEntry = m_epgs.find((unsigned int) iEpgId); - return epgEntry != m_epgs.end() ? epgEntry->second : CPVREpgPtr(); + const auto &epgEntry = m_epgs.find(static_cast(iEpgId)); + if (epgEntry != m_epgs.end()) + retval = epgEntry->second; + + return retval; } CPVREpgInfoTagPtr CPVREpgContainer::GetTagById(const CPVRChannelPtr &channel, unsigned int iBroadcastId) const @@ -479,7 +456,7 @@ CPVREpgInfoTagPtr CPVREpgContainer::GetTagById(const CPVRChannelPtr &channel, un if (channel) { - const CPVREpgPtr epg(channel->GetEPG()); + const CPVREpgPtr epg = channel->GetEPG(); if (epg) retval = epg->GetTagByBroadcastId(iBroadcastId); } @@ -498,21 +475,21 @@ CPVREpgInfoTagPtr CPVREpgContainer::GetTagById(const CPVRChannelPtr &channel, un std::vector CPVREpgContainer::GetEpgTagsForTimer(const CPVRTimerInfoTagPtr &timer) const { - CPVRChannelPtr channel(timer->Channel()); + CPVRChannelPtr channel = timer->Channel(); if (!channel) channel = timer->UpdateChannel(); if (channel) { - const CPVREpgPtr epg(channel->GetEPG()); + const CPVREpgPtr epg = channel->GetEPG(); if (epg) return epg->GetTagsBetween(timer->StartAsUTC(), timer->EndAsUTC()); } return std::vector(); } -void CPVREpgContainer::InsertFromDatabase(const CPVREpgPtr &newEpg) +void CPVREpgContainer::InsertFromDB(const CPVREpgPtr &newEpg) { // table might already have been created when pvr channels were loaded CPVREpgPtr epg = GetById(newEpg->EpgID()); @@ -537,13 +514,13 @@ void CPVREpgContainer::InsertFromDatabase(const CPVREpgPtr &newEpg) CPVREpgPtr CPVREpgContainer::CreateChannelEpg(const CPVRChannelPtr &channel) { + CPVREpgPtr epg; if (!channel) - return CPVREpgPtr(); + return epg; WaitForUpdateFinish(true); LoadFromDB(); - CPVREpgPtr epg; if (channel->EpgID() > 0) epg = GetById(channel->EpgID()); @@ -555,7 +532,7 @@ CPVREpgPtr CPVREpgContainer::CreateChannelEpg(const CPVRChannelPtr &channel) epg.reset(new CPVREpg(channel, false)); CSingleLock lock(m_critSection); - m_epgs.insert(std::make_pair((unsigned int)epg->EpgID(), epg)); + m_epgs.insert(std::make_pair(static_cast(epg->EpgID()), epg)); SetChanged(); epg->RegisterObserver(this); } @@ -592,18 +569,18 @@ bool CPVREpgContainer::RemoveOldEntries(void) return true; } -bool CPVREpgContainer::DeleteEpg(const CPVREpg &epg, bool bDeleteFromDatabase /* = false */) +bool CPVREpgContainer::DeleteEpg(const CPVREpgPtr &epg, bool bDeleteFromDatabase /* = false */) { - if (epg.EpgID() < 0) + if (!epg || epg->EpgID() < 0) return false; CSingleLock lock(m_critSection); - const auto &epgEntry = m_epgs.find((unsigned int)epg.EpgID()); + const auto &epgEntry = m_epgs.find(static_cast(epg->EpgID())); if (epgEntry == m_epgs.end()) return false; - CLog::LogFC(LOGDEBUG, LOGEPG, "Deleting EPG table %s (%d)", epg.Name().c_str(), epg.EpgID()); + CLog::LogFC(LOGDEBUG, LOGEPG, "Deleting EPG table %s (%d)", epg->Name().c_str(), epg->EpgID()); if (bDeleteFromDatabase && !IgnoreDB()) m_database->Delete(*epgEntry->second); @@ -620,7 +597,7 @@ bool CPVREpgContainer::IgnoreDB() const bool CPVREpgContainer::InterruptUpdate(void) const { - bool bReturn(false); + bool bReturn = false; CSingleLock lock(m_critSection); bReturn = g_application.m_bStop || m_bStop || m_bPreventUpdates; @@ -647,10 +624,10 @@ void CPVREpgContainer::WaitForUpdateFinish(bool bInterrupt /* = true */) bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */) { - bool bInterrupted(false); - unsigned int iUpdatedTables(0); - bool bShowProgress(false); - int pendingUpdates(0); + bool bInterrupted = false; + unsigned int iUpdatedTables = 0; + bool bShowProgress = false; + int pendingUpdates = 0; /* set start and end time */ time_t start; @@ -664,6 +641,7 @@ bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */) CSingleLock lock(m_critSection); if (m_bIsUpdating || InterruptUpdate()) return false; + m_bIsUpdating = true; pendingUpdates = m_pendingUpdates; } @@ -675,7 +653,7 @@ bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */) progressHandler = new CPVRGUIProgressHandler(g_localizeStrings.Get(19004)); // Importing guide from clients /* load or update all EPG tables */ - unsigned int iCounter(0); + unsigned int iCounter = 0; for (const auto &epgEntry : m_epgs) { if (InterruptUpdate()) @@ -684,7 +662,7 @@ bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */) break; } - CPVREpgPtr epg = epgEntry.second; + const CPVREpgPtr epg = epgEntry.second; if (!epg) continue; @@ -698,23 +676,27 @@ bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */) // check the pvr manager when the channel pointer isn't set if (!epg->Channel()) { - CPVRChannelPtr channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelByEpgId(epg->EpgID()); + const CPVRChannelPtr channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelByEpgId(epg->EpgID()); if (channel) epg->SetChannel(channel); } if ((!bOnlyPending || epg->UpdatePending()) && epg->Update(start, end, m_settings.GetIntValue(CSettings::SETTING_EPG_EPGUPDATE) * 60, bOnlyPending)) + { iUpdatedTables++; + } else if (!epg->IsValid()) + { invalidTables.push_back(epg); + } } if (bShowProgress && !bOnlyPending) progressHandler->DestroyProgress(); - for (auto it = invalidTables.begin(); it != invalidTables.end(); ++it) - DeleteEpg(**it, true); + for (const auto& epg : invalidTables) + DeleteEpg(epg, true); if (bInterrupted) { @@ -751,14 +733,15 @@ const CDateTime CPVREpgContainer::GetFirstEPGDate(void) { CDateTime returnValue; - CSingleLock lock(m_critSection); - for (const auto &epgEntry : m_epgs) + m_critSection.lock(); + const auto epgs = m_epgs; + m_critSection.unlock(); + + for (const auto &epgEntry : epgs) { - lock.Leave(); CDateTime entry = epgEntry.second->GetFirstDate(); if (entry.IsValid() && (!returnValue.IsValid() || entry < returnValue)) returnValue = entry; - lock.Enter(); } return returnValue; @@ -768,14 +751,15 @@ const CDateTime CPVREpgContainer::GetLastEPGDate(void) { CDateTime returnValue; - CSingleLock lock(m_critSection); - for (const auto &epgEntry : m_epgs) + m_critSection.lock(); + const auto epgs = m_epgs; + m_critSection.unlock(); + + for (const auto &epgEntry : epgs) { - lock.Leave(); CDateTime entry = epgEntry.second->GetLastDate(); if (entry.IsValid() && (!returnValue.IsValid() || entry > returnValue)) returnValue = entry; - lock.Enter(); } return returnValue; @@ -801,38 +785,36 @@ int CPVREpgContainer::GetEPGSearch(CFileItemList &results, const CPVREpgSearchFi bool CPVREpgContainer::CheckPlayingEvents(void) { - bool bReturn(false); - bool bFoundChanges(false); + bool bReturn = false; + bool bFoundChanges = false; + time_t iNextEpgActiveTagCheck; { - time_t iNextEpgActiveTagCheck; - { - CSingleLock lock(m_critSection); - iNextEpgActiveTagCheck = m_iNextEpgActiveTagCheck; - } + CSingleLock lock(m_critSection); + iNextEpgActiveTagCheck = m_iNextEpgActiveTagCheck; + } - time_t iNow; - CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow); - if (iNow >= iNextEpgActiveTagCheck) - { - for (const auto &epgEntry : m_epgs) - bFoundChanges = epgEntry.second->CheckPlayingEvent() || bFoundChanges; + time_t iNow; + CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow); + if (iNow >= iNextEpgActiveTagCheck) + { + for (const auto &epgEntry : m_epgs) + bFoundChanges = epgEntry.second->CheckPlayingEvent() || bFoundChanges; - CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNextEpgActiveTagCheck); - iNextEpgActiveTagCheck += g_advancedSettings.m_iEpgActiveTagCheckInterval; + CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNextEpgActiveTagCheck); + iNextEpgActiveTagCheck += g_advancedSettings.m_iEpgActiveTagCheckInterval; - /* pvr tags always start on the full minute */ - if (CServiceBroker::GetPVRManager().IsStarted()) - iNextEpgActiveTagCheck -= iNextEpgActiveTagCheck % 60; + /* pvr tags always start on the full minute */ + if (CServiceBroker::GetPVRManager().IsStarted()) + iNextEpgActiveTagCheck -= iNextEpgActiveTagCheck % 60; - bReturn = true; - } + bReturn = true; + } - if (bReturn) - { - CSingleLock lock(m_critSection); - m_iNextEpgActiveTagCheck = iNextEpgActiveTagCheck; - } + if (bReturn) + { + CSingleLock lock(m_critSection); + m_iNextEpgActiveTagCheck = iNextEpgActiveTagCheck; } if (bFoundChanges) diff --git a/xbmc/pvr/epg/EpgContainer.h b/xbmc/pvr/epg/EpgContainer.h index aff7b8405b..887e0c6ad0 100644 --- a/xbmc/pvr/epg/EpgContainer.h +++ b/xbmc/pvr/epg/EpgContainer.h @@ -54,25 +54,13 @@ namespace PVR /*! * @brief Stop the EPG update thread. - * @return */ - bool Stop(void); + void Stop(void); /*! * @brief Clear all EPG entries. - * @param bClearDb Clear the database too if true. */ - void Clear(bool bClearDb = false); - - /*! - * @brief Stop the update thread and unload all data. - */ - void Unload(void); - - /*! - * @brief Clear the EPG and all it's database entries. - */ - void Reset(void) { Clear(true); } + void Clear(); /*! * @brief Check whether the EpgContainer has fully started. @@ -84,9 +72,9 @@ namespace PVR * @brief Delete an EPG table from this container. * @param epg The table to delete. * @param bDeleteFromDatabase Delete this table from the database too if true. - * @return + * @return True on success, false otherwise. */ - bool DeleteEpg(const CPVREpg &epg, bool bDeleteFromDatabase = false); + bool DeleteEpg(const CPVREpgPtr &epg, bool bDeleteFromDatabase = false); /*! * @brief Process a notification from an observable. @@ -95,7 +83,12 @@ namespace PVR */ void Notify(const Observable &obs, const ObservableMessage msg) override; - CPVREpgPtr CreateChannelEpg(const PVR::CPVRChannelPtr &channel); + /*! + * @brief Create the EPg for a given channel. + * @param channel The channel. + * @return the created EPG + */ + CPVREpgPtr CreateChannelEpg(const CPVRChannelPtr &channel); /*! * @brief Get all EPG tables and apply a filter. @@ -112,9 +105,9 @@ namespace PVR const CDateTime GetFirstEPGDate(void); /*! - * @brief Get the end time of the last entry. - * @return The end time. - */ + * @brief Get the end time of the last entry. + * @return The end time. + */ const CDateTime GetLastEPGDate(void); /*! @@ -130,56 +123,27 @@ namespace PVR * @param iBroadcastId The event id to get * @return The requested event, or an empty tag when not found */ - CPVREpgInfoTagPtr GetTagById(const PVR::CPVRChannelPtr &channel, unsigned int iBroadcastId) const; + CPVREpgInfoTagPtr GetTagById(const CPVRChannelPtr &channel, unsigned int iBroadcastId) const; /*! * @brief Get the EPG events matching the given timer * @param timer The timer to get the matching events for. * @return The matching events, or an empty vector when no matching tag was found */ - std::vector GetEpgTagsForTimer(const PVR::CPVRTimerInfoTagPtr &timer) const; - - /*! - * @brief Notify EPG table observers when the currently active tag changed. - * @return True if the check was done, false if it was not the right time to check - */ - bool CheckPlayingEvents(void); - - /*! - * @brief The next EPG ID to be given to a table when the db isn't being used. - * @return The next ID. - */ - unsigned int NextEpgId(void); + std::vector GetEpgTagsForTimer(const CPVRTimerInfoTagPtr &timer) const; /*! - * @return True to not to store EPG entries in the database. + * @brief Check whether data should be persisted to the EPG database. + * @return True if data should not be persisted to the EPG database, false otherwise. */ bool IgnoreDB() const; - /*! - * @brief Wait for an EPG update to finish. - * @param bInterrupt True to interrupt a running update. - */ - void WaitForUpdateFinish(bool bInterrupt = true); - - /*! - * @brief Set to true to prevent updates. - * @param bSetTo The new value. - */ - void PreventUpdates(bool bSetTo = true) { m_bPreventUpdates = bSetTo; } - /*! * @brief Notify EPG container that there are pending manual EPG updates * @param bHasPendingUpdates The new value */ void SetHasPendingUpdates(bool bHasPendingUpdates = true); - /*! - * @brief Call Persist() on each table - * @return True when they all were persisted, false otherwise. - */ - bool PersistAll(void); - /*! * @brief A client triggered an epg update request for a channel * @param iClientID The id of the client which triggered the update request @@ -208,10 +172,27 @@ namespace PVR private: /*! - * @brief Load the EPG settings. - * @return True if the settings were loaded successfully, false otherwise. + * @brief Notify EPG table observers when the currently active tag changed. + * @return True if the check was done, false if it was not the right time to check */ - bool LoadSettings(void); + bool CheckPlayingEvents(void); + + /*! + * @brief The next EPG ID to be given to a table when the db isn't being used. + * @return The next ID. + */ + unsigned int NextEpgId(void); + + /*! + * @brief Wait for an EPG update to finish. + */ + void WaitForUpdateFinish(); + + /*! + * @brief Call Persist() on each table + * @return True when they all were persisted, false otherwise. + */ + bool PersistAll(void); /*! * @brief Remove old EPG entries. @@ -227,6 +208,7 @@ namespace PVR bool UpdateEPG(bool bOnlyPending = false); /*! + * @brief Check whether a running update should be interrupted. * @return True if a running update should be interrupted, false otherwise. */ bool InterruptUpdate(void) const; @@ -241,27 +223,28 @@ namespace PVR */ void LoadFromDB(void); - void InsertFromDatabase(const CPVREpgPtr &newEpg); + /*! + * @brief Insert data from database + * @param newEpg the EPG containing the updated data. + */ + void InsertFromDB(const CPVREpgPtr &newEpg); CPVREpgDatabasePtr m_database; /*!< the EPG database */ - /** @name Class state properties */ - //@{ - bool m_bIsUpdating; /*!< true while an update is running */ - bool m_bIsInitialising; /*!< true while the epg manager hasn't loaded all tables */ - bool m_bStarted; /*!< true if EpgContainer has fully started */ - bool m_bLoaded; /*!< true after epg data is initially loaded from the database */ - bool m_bPreventUpdates; /*!< true to prevent EPG updates */ - int m_pendingUpdates; /*!< count of pending manual updates */ - time_t m_iLastEpgCleanup; /*!< the time the EPG was cleaned up */ - time_t m_iNextEpgUpdate; /*!< the time the EPG will be updated */ - time_t m_iNextEpgActiveTagCheck; /*!< the time the EPG will be checked for active tag updates */ - unsigned int m_iNextEpgId; /*!< the next epg ID that will be given to a new table when the db isn't being used */ - EPGMAP m_epgs; /*!< the EPGs in this container */ - //@} - - mutable CCriticalSection m_critSection; /*!< a critical section for changes to this container */ - CEvent m_updateEvent; /*!< trigger when an update finishes */ + bool m_bIsUpdating = false; /*!< true while an update is running */ + bool m_bIsInitialising = true; /*!< true while the epg manager hasn't loaded all tables */ + bool m_bStarted = false; /*!< true if EpgContainer has fully started */ + bool m_bLoaded = false; /*!< true after epg data is initially loaded from the database */ + bool m_bPreventUpdates = false; /*!< true to prevent EPG updates */ + int m_pendingUpdates = 0; /*!< count of pending manual updates */ + time_t m_iLastEpgCleanup = 0; /*!< the time the EPG was cleaned up */ + time_t m_iNextEpgUpdate = 0; /*!< the time the EPG will be updated */ + time_t m_iNextEpgActiveTagCheck = 0; /*!< the time the EPG will be checked for active tag updates */ + unsigned int m_iNextEpgId = 0; /*!< the next epg ID that will be given to a new table when the db isn't being used */ + std::map m_epgs; /*!< the EPGs in this container */ + + mutable CCriticalSection m_critSection; /*!< a critical section for changes to this container */ + CEvent m_updateEvent; /*!< trigger when an update finishes */ std::list m_updateRequests; /*!< list of update requests triggered by addon */ CCriticalSection m_updateRequestsLock; /*!< protect update requests */ -- cgit v1.2.3