Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
pvr/epg: fixed add-on initialisation, epg table creation/loading and …
Browse files Browse the repository at this point in the history
…optimisations
  • Loading branch information
opdenkamp committed Feb 23, 2012
1 parent deb2a03 commit 37e7247
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 215 deletions.
10 changes: 7 additions & 3 deletions xbmc/addons/AddonManager.cpp
Expand Up @@ -395,9 +395,13 @@ bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* =
cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
for(int i=0; i <num; i++)
{
AddonPtr addon(Factory(exts[i]));
if (addon && ((bGetDisabledPVRAddons && addon->Type() == ADDON_PVRDLL) || m_database.IsAddonDisabled(addon->ID()) != enabled))
addons.push_back(addon);
const cp_extension_t *props = exts[i];
if (((bGetDisabledPVRAddons && TranslateType(props->ext_point_id) == ADDON_PVRDLL) || m_database.IsAddonDisabled(props->plugin->identifier) != enabled))
{
AddonPtr addon(Factory(props));
if (addon)
addons.push_back(addon);
}
}
m_cpluff->release_info(m_cp_context, exts);
return addons.size() > 0;
Expand Down
121 changes: 68 additions & 53 deletions xbmc/epg/Epg.cpp
Expand Up @@ -30,7 +30,7 @@
#include "EpgContainer.h"
#include "pvr/PVRManager.h"
#include "pvr/addons/PVRClients.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "utils/StringUtils.h"

#include "../addons/include/xbmc_pvr_types.h" // TODO extract the epg specific stuff
Expand All @@ -47,7 +47,7 @@ CEpg::CEpg(int iEpgID, const CStdString &strName /* = "" */, const CStdString &s
m_strName(strName),
m_strScraperName(strScraperName),
m_nowActive(NULL),
m_Channel(NULL)
m_iPVRChannelId(-1)
{
m_lastScanTime.SetValid(false);
m_firstDate.SetValid(false);
Expand All @@ -62,7 +62,7 @@ CEpg::CEpg(CPVRChannel *channel, bool bLoadedFromDb /* = false */) :
m_strName(channel->ChannelName()),
m_strScraperName(channel->EPGScraper()),
m_nowActive(NULL),
m_Channel(channel)
m_iPVRChannelId(channel->ChannelID())
{
m_lastScanTime.SetValid(false);
m_firstDate.SetValid(false);
Expand All @@ -77,7 +77,7 @@ CEpg::CEpg(void) :
m_strName(StringUtils::EmptyString),
m_strScraperName(StringUtils::EmptyString),
m_nowActive(NULL),
m_Channel(NULL)
m_iPVRChannelId(-1)
{
m_lastScanTime.SetValid(false);
m_firstDate.SetValid(false);
Expand All @@ -101,7 +101,7 @@ CEpg &CEpg::operator =(const CEpg &right)
m_lastScanTime = right.m_lastScanTime;
m_firstDate = right.m_firstDate;
m_lastDate = right.m_lastDate;
m_Channel = right.m_Channel;
m_iPVRChannelId = right.m_iPVRChannelId;

for (map<CDateTime, CEpgInfoTag *>::const_iterator it = right.m_tags.begin(); it != right.m_tags.end(); it++)
m_tags.insert(make_pair(it->first, new CEpgInfoTag(*it->second)));
Expand Down Expand Up @@ -335,7 +335,7 @@ bool CEpg::Load(void)
bool bReturn(false);
CEpgDatabase *database = g_EpgContainer.GetDatabase();

if (!database || !database->Open())
if (!database || !database->IsOpen())
{
CLog::Log(LOGERROR, "Epg - %s - could not open the database", __FUNCTION__);
return bReturn;
Expand All @@ -357,7 +357,6 @@ bool CEpg::Load(void)
}

m_bLoaded = true;
database->Close();

return bReturn;
}
Expand Down Expand Up @@ -390,7 +389,7 @@ bool CEpg::UpdateEntries(const CEpg &epg, bool bStoreInDb /* = true */)
{
if (bStoreInDb)
{
if (!database || !database->Open())
if (!database || !database->IsOpen())
{
CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__);
return bReturn;
Expand All @@ -417,7 +416,6 @@ bool CEpg::UpdateEntries(const CEpg &epg, bool bStoreInDb /* = true */)
if (bStoreInDb)
{
bReturn = database->CommitTransaction();
database->Close();
if (bReturn)
Persist(true);
}
Expand Down Expand Up @@ -446,11 +444,8 @@ const CDateTime &CEpg::GetLastScanTime(void)
CEpgDatabase *database = g_EpgContainer.GetDatabase();
CDateTime dtReturn; dtReturn.SetValid(false);

if (database && database->Open())
{
if (database && database->IsOpen())
database->GetLastEpgScanTime(m_iEpgID, &m_lastScanTime);
database->Close();
}
}

if (!m_lastScanTime.IsValid())
Expand Down Expand Up @@ -551,7 +546,7 @@ bool CEpg::Persist(bool bUpdateLastScanTime /* = false */)

CEpgDatabase *database = g_EpgContainer.GetDatabase();

if (!database || !database->Open())
if (!database || !database->IsOpen())
{
CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__);
return false;
Expand Down Expand Up @@ -589,8 +584,6 @@ bool CEpg::Persist(bool bUpdateLastScanTime /* = false */)

database->CommitTransaction();

database->Close();

return bReturn;
}

Expand Down Expand Up @@ -618,10 +611,10 @@ bool CEpg::UpdateMetadata(const CEpg &epg, bool bUpdateDb /* = false */)
bool bReturn = true;
CSingleLock lock(m_critSection);

m_strName = epg.m_strName;
m_strName = epg.m_strName;
m_strScraperName = epg.m_strScraperName;
if (epg.HasPVRChannel())
m_Channel = epg.m_Channel;
if (m_iPVRChannelId == -1 || epg.m_iPVRChannelId != -1)
m_iPVRChannelId = epg.m_iPVRChannelId;

if (bUpdateDb)
bReturn = Persist();
Expand Down Expand Up @@ -653,7 +646,7 @@ bool CEpg::FixOverlappingEvents(bool bUpdateDb /* = false */)
{
if (bUpdateDb)
{
if (!database || !database->Open())
if (!database || !database->IsOpen())
{
CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__);
bReturn = false;
Expand Down Expand Up @@ -691,32 +684,28 @@ bool CEpg::FixOverlappingEvents(bool bUpdateDb /* = false */)
bool CEpg::UpdateFromScraper(time_t start, time_t end)
{
bool bGrabSuccess = false;

if (g_PVRManager.IsStarted() && HasPVRChannel() && m_Channel->EPGEnabled() && ScraperName() == "client")
{
if (g_PVRManager.IsStarted() && g_PVRClients->GetAddonCapabilities(m_Channel->ClientID()).bSupportsEPG)
if (ScraperName() == "client")
{
CPVRChannel *channel = Channel();
if (!channel)
CLog::Log(LOGINFO, "%s - channel not found, can't update", __FUNCTION__);
else if (!channel->EPGEnabled())
CLog::Log(LOGINFO, "%s - EPG updating disabled in the channel configuration", __FUNCTION__);
else if (!g_PVRClients->GetAddonCapabilities(channel->ClientID()).bSupportsEPG)
CLog::Log(LOGINFO, "%s - the backend for channel '%s' on client '%i' does not support EPGs", __FUNCTION__, channel->ChannelName().c_str(), channel->ClientID());
else
{
CLog::Log(LOGINFO, "%s - updating EPG for channel '%s' from client '%i'",
__FUNCTION__, m_Channel->ChannelName().c_str(), m_Channel->ClientID());
CLog::Log(LOGINFO, "%s - updating EPG for channel '%s' from client '%i'", __FUNCTION__, channel->ChannelName().c_str(), channel->ClientID());
PVR_ERROR error;
g_PVRClients->GetEPGForChannel(*m_Channel, this, start, end, &error);
g_PVRClients->GetEPGForChannel(*channel, this, start, end, &error);
bGrabSuccess = error == PVR_ERROR_NO_ERROR;
}
else
{
CLog::Log(LOGINFO, "%s - channel '%s' on client '%i' does not support EPGs",
__FUNCTION__, m_Channel->ChannelName().c_str(), m_Channel->ClientID());
}
}
else if (m_strScraperName.IsEmpty()) /* no grabber defined */
{
CLog::Log(LOGERROR, "EPG - %s - no EPG grabber defined for table '%s'",
__FUNCTION__, m_strName.c_str());
}
CLog::Log(LOGERROR, "EPG - %s - no EPG scraper defined for table '%s'", __FUNCTION__, m_strName.c_str());
else
{
CLog::Log(LOGINFO, "EPG - %s - updating EPG table '%s' with scraper '%s'",
__FUNCTION__, m_strName.c_str(), m_strScraperName.c_str());
CLog::Log(LOGINFO, "EPG - %s - updating EPG table '%s' with scraper '%s'", __FUNCTION__, m_strName.c_str(), m_strScraperName.c_str());
CLog::Log(LOGERROR, "loading the EPG via scraper has not been implemented yet");
// TODO: Add Support for Web EPG Scrapers here
}
Expand All @@ -729,7 +718,7 @@ bool CEpg::PersistTags(void) const
bool bReturn = false;
CEpgDatabase *database = g_EpgContainer.GetDatabase();

if (!database || !database->Open())
if (!database || !database->IsOpen())
{
CLog::Log(LOGERROR, "EPG - %s - could not load the database", __FUNCTION__);
return bReturn;
Expand Down Expand Up @@ -815,30 +804,22 @@ bool CEpg::UpdateEntry(const EPG_TAG *data, bool bUpdateDatabase /* = false */)

bool CEpg::IsRadio(void) const
{
CSingleLock lock(m_critSection);

return HasPVRChannel() ? m_Channel->IsRadio() : false;
CPVRChannel *channel = Channel();
return channel ? channel->IsRadio() : false;
}

bool CEpg::IsRemovableTag(const CEpgInfoTag *tag) const
{
CSingleLock lock(m_critSection);

if (HasPVRChannel())
{
return (!tag || !tag->HasTimer());
}

return true;
return (!tag || !tag->HasTimer());
}


bool CEpg::LoadFromClients(time_t start, time_t end)
{
bool bReturn(false);
if (HasPVRChannel())
CPVRChannel *channel = Channel();
if (channel)
{
CEpg tmpEpg(m_Channel);
CEpg tmpEpg(channel);
if (tmpEpg.UpdateFromScraper(start, end))
bReturn = UpdateEntries(tmpEpg, !g_guiSettings.GetBool("epg.ignoredbforclient"));
}
Expand Down Expand Up @@ -872,3 +853,37 @@ const CEpgInfoTag *CEpg::GetPreviousEvent(const CEpgInfoTag& tag) const
}
return NULL;
}

CPVRChannel *CEpg::Channel(void) const
{
int iChannelId(-1);
{
CSingleLock lock(m_critSection);
iChannelId = m_iPVRChannelId;
}

CLog::Log(LOGINFO, "%s - get channel %d (%d)", __FUNCTION__, iChannelId, g_PVRManager.IsStarted() ? 1 : 0);

if (iChannelId != -1 && g_PVRManager.IsStarted())
return g_PVRChannelGroups->GetByChannelIDFromAll(iChannelId);

return NULL;
}

int CEpg::ChannelID(void) const
{
CSingleLock lock(m_critSection);
return m_iPVRChannelId;
}

void CEpg::SetChannel(PVR::CPVRChannel *channel)
{
CSingleLock lock(m_critSection);
m_iPVRChannelId = channel->ChannelID();
}

bool CEpg::HasPVRChannel(void) const
{
CSingleLock lock(m_critSection);
return m_iPVRChannelId != -1;
}
10 changes: 6 additions & 4 deletions xbmc/epg/Epg.h
Expand Up @@ -83,13 +83,15 @@ namespace EPG
* @brief The channel this EPG belongs to.
* @return The channel this EPG belongs to
*/
virtual const PVR::CPVRChannel *Channel(void) const { return m_Channel; }
virtual PVR::CPVRChannel *Channel(void) const;

virtual int ChannelID(void) const;

/*!
* @brief Channel the channel tag linked to this EPG table.
* @param channel The new channel tag.
*/
virtual void SetChannel(PVR::CPVRChannel *channel) { m_Channel = channel; }
virtual void SetChannel(PVR::CPVRChannel *channel);

/*!
* @brief Get the name of the scraper to use for this table.
Expand Down Expand Up @@ -130,7 +132,7 @@ namespace EPG
/*!
* @return True if this EPG has a PVR channel set, false otherwise.
*/
virtual bool HasPVRChannel(void) const { return !(m_Channel == NULL); }
virtual bool HasPVRChannel(void) const;

/*!
* @brief Remove all entries from this EPG that finished before the given time
Expand Down Expand Up @@ -342,7 +344,7 @@ namespace EPG
CDateTime m_firstDate; /*!< start time of the first epg event in this table */
CDateTime m_lastDate; /*!< end time of the last epg event in this table */

PVR::CPVRChannel * m_Channel; /*!< the channel this EPG belongs to */
int m_iPVRChannelId; /*!< the channel this EPG belongs to */

mutable CCriticalSection m_critSection; /*!< critical section for changes in this table */
};
Expand Down

0 comments on commit 37e7247

Please sign in to comment.