Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

epg: back to keeping pointers to CPVRChannel in CEpg and CEpgInfoTag.…

… this introduced a couple of possible deadlock situations
  • Loading branch information...
commit 5c627d1b15c75b2b554f57c27ee2833ba44da298 1 parent 765ee84
Lars Op den Kamp authored
123 xbmc/epg/Epg.cpp
View
@@ -47,8 +47,7 @@ CEpg::CEpg(int iEpgID, const CStdString &strName /* = "" */, const CStdString &s
m_iEpgID(iEpgID),
m_strName(strName),
m_strScraperName(strScraperName),
- m_iPVRChannelId(-1),
- m_iPVRChannelNumber(-1)
+ m_pvrChannel(NULL)
{
}
@@ -60,8 +59,7 @@ CEpg::CEpg(CPVRChannel *channel, bool bLoadedFromDb /* = false */) :
m_iEpgID(channel->EpgID()),
m_strName(channel->ChannelName()),
m_strScraperName(channel->EPGScraper()),
- m_iPVRChannelId(channel->ChannelID()),
- m_iPVRChannelNumber(channel->ChannelNumber())
+ m_pvrChannel(channel)
{
}
@@ -73,8 +71,7 @@ CEpg::CEpg(void) :
m_iEpgID(0),
m_strName(StringUtils::EmptyString),
m_strScraperName(StringUtils::EmptyString),
- m_iPVRChannelId(-1),
- m_iPVRChannelNumber(-1)
+ m_pvrChannel(NULL)
{
}
@@ -94,8 +91,7 @@ CEpg &CEpg::operator =(const CEpg &right)
m_strScraperName = right.m_strScraperName;
m_nowActiveStart = right.m_nowActiveStart;
m_lastScanTime = right.m_lastScanTime;
- m_iPVRChannelId = right.m_iPVRChannelId;
- m_iPVRChannelNumber = right.m_iPVRChannelNumber;
+ m_pvrChannel = right.m_pvrChannel;
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)));
@@ -325,57 +321,53 @@ const CEpgInfoTag *CEpg::GetTagAround(const CDateTime &time) const
void CEpg::AddEntry(const CEpgInfoTag &tag)
{
CEpgInfoTag *newTag(NULL);
+ CSingleLock lock(m_critSection);
+ map<CDateTime, CEpgInfoTag*>::iterator itr = m_tags.find(tag.StartAsUTC());
+ if (itr != m_tags.end())
+ newTag = itr->second;
+ else
{
- CSingleLock lock(m_critSection);
- map<CDateTime, CEpgInfoTag*>::iterator itr = m_tags.find(tag.StartAsUTC());
- if (itr != m_tags.end())
- newTag = itr->second;
- else
- {
- CPVRChannel *channel = Channel();
- newTag = new CEpgInfoTag(this, m_iPVRChannelNumber, m_iPVRChannelId, m_strName, channel ? channel->IconPath() : StringUtils::EmptyString);
- m_tags.insert(make_pair(tag.StartAsUTC(), newTag));
- }
+ newTag = new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : StringUtils::EmptyString);
+ m_tags.insert(make_pair(tag.StartAsUTC(), newTag));
}
if (newTag)
{
newTag->Update(tag);
- newTag->m_epg = this;
- newTag->m_iPVRChannelNumber = m_iPVRChannelNumber;
- newTag->m_iPVRChannelID = m_iPVRChannelId;
- newTag->m_strTableName = m_strName;
- newTag->m_bChanged = false;
+ newTag->SetPVRChannel(m_pvrChannel);
+ newTag->m_epg = this;
+ newTag->m_strTableName = m_strName;
+ newTag->m_bChanged = false;
}
}
bool CEpg::UpdateEntry(const CEpgInfoTag &tag, bool bUpdateDatabase /* = false */, bool bSort /* = true */)
{
- bool bReturn(false);
- CSingleLock lock(m_critSection);
-
CEpgInfoTag *infoTag(NULL);
- map<CDateTime, CEpgInfoTag *>::iterator it = m_tags.find(tag.StartAsUTC());
- bool bNewTag(false);
- if (it != m_tags.end())
- {
- infoTag = it->second;
- }
- else
+ bool bReturn(false);
{
- /* create a new tag if no tag with this ID exists */
- CPVRChannel *channel = Channel();
- infoTag = new CEpgInfoTag(this, m_iPVRChannelNumber, m_iPVRChannelId, m_strName, channel ? channel->IconPath() : StringUtils::EmptyString);
- infoTag->SetUniqueBroadcastID(tag.UniqueBroadcastID());
- m_tags.insert(make_pair(tag.StartAsUTC(), infoTag));
- bNewTag = true;
- }
+ CSingleLock lock(m_critSection);
- infoTag->Update(tag, bNewTag);
- infoTag->m_epg = this;
- infoTag->m_iPVRChannelNumber = m_iPVRChannelNumber;
- infoTag->m_iPVRChannelID = m_iPVRChannelId;
- infoTag->m_strTableName = m_strName;
+ map<CDateTime, CEpgInfoTag *>::iterator it = m_tags.find(tag.StartAsUTC());
+ bool bNewTag(false);
+ if (it != m_tags.end())
+ {
+ infoTag = it->second;
+ }
+ else
+ {
+ /* create a new tag if no tag with this ID exists */
+ infoTag = new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : StringUtils::EmptyString);
+ infoTag->SetUniqueBroadcastID(tag.UniqueBroadcastID());
+ m_tags.insert(make_pair(tag.StartAsUTC(), infoTag));
+ bNewTag = true;
+ }
+
+ infoTag->Update(tag, bNewTag);
+ infoTag->m_epg = this;
+ infoTag->m_pvrChannel = m_pvrChannel;
+ infoTag->m_strTableName = m_strName;
+ }
if (bUpdateDatabase)
bReturn = infoTag->Persist();
@@ -667,18 +659,8 @@ bool CEpg::UpdateMetadata(const CEpg &epg, bool bUpdateDb /* = false */)
m_strName = epg.m_strName;
m_strScraperName = epg.m_strScraperName;
- if (m_iPVRChannelId == -1 || epg.m_iPVRChannelId != -1)
- {
- m_iPVRChannelId = epg.m_iPVRChannelId;
- m_iPVRChannelNumber = epg.m_iPVRChannelNumber;
-
- /* Copy the new channel information to all child tags */
- for (map<CDateTime, CEpgInfoTag *>::const_iterator it = m_tags.begin(); it != m_tags.end(); it++)
- {
- it->second->SetPVRChannelID(m_iPVRChannelId);
- it->second->SetPVRChannelNumber(m_iPVRChannelNumber);
- }
- }
+ if (epg.m_pvrChannel)
+ SetChannel(epg.m_pvrChannel);
if (bUpdateDb)
bReturn = Persist();
@@ -952,46 +934,37 @@ const CEpgInfoTag *CEpg::GetPreviousEvent(const CEpgInfoTag& tag) const
CPVRChannel *CEpg::Channel(void) const
{
- int iChannelId(-1);
- {
- CSingleLock lock(m_critSection);
- iChannelId = m_iPVRChannelId;
- }
-
- if (iChannelId != -1 && g_PVRManager.IsStarted())
- return g_PVRChannelGroups->GetByChannelIDFromAll(iChannelId);
-
- return NULL;
+ CSingleLock lock(m_critSection);
+ return m_pvrChannel;
}
int CEpg::ChannelID(void) const
{
CSingleLock lock(m_critSection);
- return m_iPVRChannelId;
+ return m_pvrChannel ? m_pvrChannel->ChannelID() : -1;
}
int CEpg::ChannelNumber(void) const
{
CSingleLock lock(m_critSection);
- return m_iPVRChannelNumber;
+ return m_pvrChannel ? m_pvrChannel->ChannelNumber() : -1;
}
void CEpg::SetChannel(PVR::CPVRChannel *channel)
{
CSingleLock lock(m_critSection);
- m_iPVRChannelId = channel->ChannelID();
- m_iPVRChannelNumber = channel->ChannelNumber();
- for (map<CDateTime, CEpgInfoTag *>::iterator it = m_tags.begin(); it != m_tags.end(); it++)
+ if (m_pvrChannel != channel)
{
- it->second->m_iPVRChannelID = m_iPVRChannelId;
- it->second->m_iPVRChannelNumber = m_iPVRChannelNumber;
+ m_pvrChannel = channel;
+ for (map<CDateTime, CEpgInfoTag *>::iterator it = m_tags.begin(); it != m_tags.end(); it++)
+ it->second->SetPVRChannel(m_pvrChannel);
}
}
bool CEpg::HasPVRChannel(void) const
{
CSingleLock lock(m_critSection);
- return m_iPVRChannelId != -1;
+ return m_pvrChannel != NULL;
}
bool CEpg::UpdatePending(void) const
3  xbmc/epg/Epg.h
View
@@ -359,8 +359,7 @@ namespace EPG
CDateTime m_lastScanTime; /*!< the last time the EPG has been updated */
- int m_iPVRChannelId; /*!< the channel this EPG belongs to */
- int m_iPVRChannelNumber; /*!< the channel number in the "all channels" group. set on create and not updated */
+ PVR::CPVRChannel * m_pvrChannel; /*!< the channel this EPG belongs to */
CCriticalSection m_critSection; /*!< critical section for changes in this table */
};
51 xbmc/epg/EpgInfoTag.cpp
View
@@ -35,7 +35,7 @@ using namespace std;
using namespace EPG;
using namespace PVR;
-CEpgInfoTag::CEpgInfoTag(CEpg *epg /* = NULL */, int iPVRChannelNumber /* = -1 */, int iPVRChannelID /* = -1 */, const CStdString &strTableName /* = StringUtils::EmptyString */, const CStdString &strIconPath /* = StringUtils::EmptyString */) :
+CEpgInfoTag::CEpgInfoTag(CEpg *epg /* = NULL */, PVR::CPVRChannel *pvrChannel /* = NULL */, const CStdString &strTableName /* = StringUtils::EmptyString */, const CStdString &strIconPath /* = StringUtils::EmptyString */) :
m_bNotify(false),
m_bChanged(false),
m_iBroadcastId(-1),
@@ -56,8 +56,7 @@ CEpgInfoTag::CEpgInfoTag(CEpg *epg /* = NULL */, int iPVRChannelNumber /* = -1 *
m_strFileNameAndPath(""),
m_iTimerId(-1),
m_epg(epg),
- m_iPVRChannelNumber(iPVRChannelNumber),
- m_iPVRChannelID(iPVRChannelID),
+ m_pvrChannel(pvrChannel),
m_strTableName(strTableName)
{
}
@@ -83,8 +82,7 @@ CEpgInfoTag::CEpgInfoTag(const EPG_TAG &data) :
m_strFileNameAndPath(""),
m_iTimerId(-1),
m_epg(NULL),
- m_iPVRChannelNumber(-1),
- m_iPVRChannelID(-1)
+ m_pvrChannel(NULL)
{
Update(data);
}
@@ -113,8 +111,7 @@ CEpgInfoTag::CEpgInfoTag(const CEpgInfoTag &tag) :
m_firstAired(tag.m_firstAired),
m_iTimerId(tag.m_iTimerId),
m_epg(tag.m_epg),
- m_iPVRChannelNumber(tag.m_iPVRChannelNumber),
- m_iPVRChannelID(tag.m_iPVRChannelID),
+ m_pvrChannel(tag.m_pvrChannel),
m_strTableName(tag.m_strTableName)
{
}
@@ -152,8 +149,7 @@ bool CEpgInfoTag::operator ==(const CEpgInfoTag& right) const
m_strFileNameAndPath == right.m_strFileNameAndPath &&
m_startTime == right.m_startTime &&
m_endTime == right.m_endTime &&
- m_iPVRChannelNumber == right.m_iPVRChannelNumber &&
- m_iPVRChannelID == right.m_iPVRChannelID &&
+ m_pvrChannel == right.m_pvrChannel &&
m_strTableName == right.m_strTableName);
}
@@ -192,8 +188,7 @@ CEpgInfoTag &CEpgInfoTag::operator =(const CEpgInfoTag &other)
m_iTimerId = other.m_iTimerId;
m_timerStart = other.m_timerStart;
m_epg = other.m_epg;
- m_iPVRChannelNumber = other.m_iPVRChannelNumber;
- m_iPVRChannelID = other.m_iPVRChannelID;
+ m_pvrChannel = other.m_pvrChannel;
m_strTableName = other.m_strTableName;
return *this;
@@ -782,49 +777,37 @@ CPVRTimerInfoTag *CEpgInfoTag::Timer(void) const
return tag;
}
-void CEpgInfoTag::SetPVRChannelID(int iPVRChannelID)
+void CEpgInfoTag::SetPVRChannel(PVR::CPVRChannel *channel)
{
CSingleLock lock(m_critSection);
- m_iPVRChannelID = iPVRChannelID;
-}
-
-void CEpgInfoTag::SetPVRChannelNumber(int iPVRChannelNumber)
-{
- CSingleLock lock(m_critSection);
- m_iPVRChannelNumber = iPVRChannelNumber;
+ m_pvrChannel = channel;
}
bool CEpgInfoTag::HasPVRChannel(void) const
{
CSingleLock lock(m_critSection);
- return m_iPVRChannelID != -1;
+ return m_pvrChannel != NULL;
}
int CEpgInfoTag::PVRChannelNumber(void) const
{
CSingleLock lock(m_critSection);
- return m_iPVRChannelNumber;
+ return m_pvrChannel ? m_pvrChannel->ChannelNumber() : -1;
}
CStdString CEpgInfoTag::PVRChannelName(void) const
{
CStdString strReturn;
CSingleLock lock(m_critSection);
- strReturn = m_strTableName;
+ if (m_pvrChannel)
+ strReturn = m_pvrChannel->ChannelName();
return strReturn;
}
const PVR::CPVRChannel *CEpgInfoTag::ChannelTag(void) const
{
- int iChannelId(-1);
- {
- CSingleLock lock(m_critSection);
- iChannelId = m_iPVRChannelID;
- }
-
- return (iChannelId != -1) ?
- g_PVRChannelGroups->GetByChannelIDFromAll(iChannelId) :
- NULL;
+ CSingleLock lock(m_critSection);
+ return m_pvrChannel;
}
void CEpgInfoTag::Update(const EPG_TAG &tag)
@@ -870,8 +853,7 @@ bool CEpgInfoTag::Update(const CEpgInfoTag &tag, bool bUpdateBroadcastId /* = tr
m_strEpisodeName != tag.m_strEpisodeName ||
m_iUniqueBroadcastID != tag.m_iUniqueBroadcastID ||
EpgID() != tag.EpgID() ||
- m_iPVRChannelID != tag.m_iPVRChannelID ||
- m_iPVRChannelNumber != tag.m_iPVRChannelNumber ||
+ m_pvrChannel != tag.m_pvrChannel ||
m_strTableName != tag.m_strTableName ||
( tag.m_strGenre.length() > 0 && m_strGenre != tag.m_strGenre )
);
@@ -891,8 +873,7 @@ bool CEpgInfoTag::Update(const CEpgInfoTag &tag, bool bUpdateBroadcastId /* = tr
m_iGenreType = tag.m_iGenreType;
m_iGenreSubType = tag.m_iGenreSubType;
m_epg = tag.m_epg;
- m_iPVRChannelID = tag.m_iPVRChannelID;
- m_iPVRChannelNumber = tag.m_iPVRChannelNumber;
+ m_pvrChannel = tag.m_pvrChannel;
m_strTableName = tag.m_strTableName;
if (m_iGenreType == EPG_GENRE_USE_STRING && tag.m_strGenre.length() > 0)
{
17 xbmc/epg/EpgInfoTag.h
View
@@ -46,7 +46,7 @@ namespace EPG
/*!
* @brief Create a new empty event without a unique ID.
*/
- CEpgInfoTag(CEpg *epg = NULL, int iPVRChannelNumber = -1, int iPVRChannelID = -1, const CStdString &strTableName = StringUtils::EmptyString, const CStdString &strIconPath = StringUtils::EmptyString);
+ CEpgInfoTag(CEpg *epg = NULL, PVR::CPVRChannel *pvrChannel = NULL, const CStdString &strTableName = StringUtils::EmptyString, const CStdString &strIconPath = StringUtils::EmptyString);
/*!
* @brief Create a new EPG infotag with 'data' as content.
@@ -376,16 +376,10 @@ namespace EPG
virtual PVR::CPVRTimerInfoTag *Timer(void) const;
/*!
- * @brief Set the PVR channel ID of the tag
- * @param The new value
+ * @brief Change the channel tag of this epg tag
+ * @param channel The new channel
*/
- virtual void SetPVRChannelID(int iPVRChannelID);
-
- /*!
- * @brief Set the PVR channel number of the tag
- * @param The new value
- */
- virtual void SetPVRChannelNumber(int iPVRChannelNumber);
+ virtual void SetPVRChannel(PVR::CPVRChannel *channel);
/*!
* @return True if this tag has a PVR channel set.
@@ -461,8 +455,7 @@ namespace EPG
int m_iTimerId; /*!< the id of the timer (if any) */
CEpg * m_epg; /*!< the schedule that this event belongs to */
- int m_iPVRChannelNumber; /*!< the channel number in the "all channels" group */
- int m_iPVRChannelID; /*!< the ID of the PVR channel */
+ PVR::CPVRChannel * m_pvrChannel;
CStdString m_strTableName; /*!< the name of the EPG table (or PVR channel, if it's a PVR epg table */
CCriticalSection m_critSection;
};
1  xbmc/pvr/channels/PVRChannel.cpp
View
@@ -163,6 +163,7 @@ bool CPVRChannel::Delete(void)
CEpg *epg = GetEPG();
if (epg)
{
+ epg->SetChannel(NULL);
g_EpgContainer.DeleteEpg(*epg, true);
CSingleLock lock(m_critSection);
m_bEPGCreated = false;
Please sign in to comment.
Something went wrong with that request. Please try again.