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 { /* create a new tag if no tag with this ID exists */ infoTag = new CEpgInfoTag(m_iEpgID, m_iPVRChannelNumber, m_iPVRChannelId, m_strName); infoTag->SetUniqueBroadcastID(tag.UniqueBroadcastID()); m_tags.insert(make_pair(tag.StartAsUTC(), infoTag)); bNewTag = true; } infoTag->Update(tag, bNewTag); infoTag->m_iEpgId = m_iEpgID; infoTag->m_iPVRChannelNumber = m_iPVRChannelNumber; infoTag->m_iPVRChannelID = m_iPVRChannelId; infoTag->m_strTableName = m_strName; if (bUpdateDatabase) bReturn = infoTag->Persist(); else bReturn = true; return bReturn; }
bool CEpg::UpdateEntry(const CEpgInfoTag &tag, bool bUpdateDatabase /* = false */, bool bSort /* = true */) { CEpgInfoTagPtr infoTag; bool bReturn(false); { CSingleLock lock(m_critSection); map<CDateTime, CEpgInfoTagPtr>::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 = CEpgInfoTagPtr(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; } if (bUpdateDatabase) bReturn = infoTag->Persist(); else bReturn = true; return bReturn; }
bool CEpg::UpdateEntry(const CEpgInfoTag &tag, bool bUpdateDatabase /* = false */, bool bSort /* = true */) { CEpgInfoTagPtr infoTag; CSingleLock lock(m_critSection); map<CDateTime, CEpgInfoTagPtr>::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.reset(new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : "")); infoTag->SetUniqueBroadcastID(tag.UniqueBroadcastID()); m_tags.insert(make_pair(tag.StartAsUTC(), infoTag)); bNewTag = true; } infoTag->Update(tag, bNewTag); infoTag->SetEpg(this); infoTag->SetPVRChannel(m_pvrChannel); if (bUpdateDatabase) m_changedTags.insert(make_pair(infoTag->UniqueBroadcastID(), infoTag)); return true; }
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 { newTag = new CEpgInfoTag(m_iEpgID, m_iPVRChannelNumber, m_iPVRChannelId, m_strName); m_tags.insert(make_pair(tag.StartAsUTC(), newTag)); } } if (newTag) { newTag->Update(tag); newTag->m_iEpgId = m_iEpgID; newTag->m_iPVRChannelNumber = m_iPVRChannelNumber; newTag->m_iPVRChannelID = m_iPVRChannelId; newTag->m_strTableName = m_strName; newTag->m_bChanged = false; } }
void CEpg::AddEntry(const CEpgInfoTag &tag) { CEpgInfoTagPtr newTag; CPVRChannelPtr channel; { CSingleLock lock(m_critSection); std::map<CDateTime, CEpgInfoTagPtr>::iterator itr = m_tags.find(tag.StartAsUTC()); if (itr != m_tags.end()) newTag = itr->second; else { newTag.reset(new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : "")); m_tags.insert(make_pair(tag.StartAsUTC(), newTag)); } channel = m_pvrChannel; } if (newTag) { newTag->Update(tag); newTag->SetPVRChannel(channel); newTag->SetEpg(this); newTag->SetTimer(g_PVRTimers->GetTimerForEpgTag(newTag)); newTag->SetRecording(g_PVRRecordings->GetRecordingForEpgTag(newTag)); } }
bool CEpg::UpdateEntry(const CEpgInfoTag &tag, bool bUpdateDatabase /* = false */, bool bSort /* = true */) { bool bReturn(false); CSingleLock lock(m_critSection); CEpgInfoTag *infoTag = GetTag(tag.UniqueBroadcastID(), tag.StartAsUTC()); /* create a new tag if no tag with this ID exists */ bool bNewTag(false); if (!infoTag) { infoTag = new CEpgInfoTag(); infoTag->SetUniqueBroadcastID(tag.UniqueBroadcastID()); push_back(infoTag); bNewTag = true; } infoTag->m_Epg = this; infoTag->Update(tag, bNewTag); if (bSort) Sort(); if (bUpdateDatabase) bReturn = infoTag->Persist(); else bReturn = true; return bReturn; }
CEpgInfoTag *CEpg::GetTag(int uniqueID, const CDateTime &StartTime) const { CEpgInfoTag *returnTag = NULL; CSingleLock lock(m_critSection); /* try to find the tag by UID */ if (uniqueID > 0) { for (unsigned int iEpgPtr = 0; iEpgPtr < size(); iEpgPtr++) { CEpgInfoTag *tag = at(iEpgPtr); if (tag->UniqueBroadcastID() == uniqueID) { returnTag = tag; break; } } } /* if we haven't found it, search by start time */ if (!returnTag) { for (unsigned int iEpgPtr = 0; iEpgPtr < size(); iEpgPtr++) { CEpgInfoTag *tag = at(iEpgPtr); if (tag->StartAsUTC() == StartTime) { returnTag = tag; break; } } } return returnTag; }
bool CEpg::InfoTagNext(CEpgInfoTag &tag) { CEpgInfoTag nowTag; if (InfoTagNow(nowTag)) { CSingleLock lock(m_critSection); map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.find(nowTag.StartAsUTC()); if (it != m_tags.end() && ++it != m_tags.end()) { tag = *it->second; return true; } } else if (Size() > 0) { /* return the first event that is in the future */ for (map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.begin(); it != m_tags.end(); it++) { if (it->second->InTheFuture()) { tag = *it->second; return true; } } } return false; }
CEpgInfoTagPtr CEpg::GetNextEvent(const CEpgInfoTag& tag) const { CSingleLock lock(m_critSection); std::map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.find(tag.StartAsUTC()); if (it != m_tags.end() && ++it != m_tags.end()) return it->second; CEpgInfoTagPtr retVal; return retVal; }
void CEpg::AddEntry(const CEpgInfoTag &tag) { CEpgInfoTagPtr newTag; CSingleLock lock(m_critSection); map<CDateTime, CEpgInfoTagPtr>::iterator itr = m_tags.find(tag.StartAsUTC()); if (itr != m_tags.end()) newTag = itr->second; else { newTag = CEpgInfoTagPtr(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->SetPVRChannel(m_pvrChannel); newTag->m_epg = this; newTag->m_bChanged = false; } }
CEpgInfoTagPtr CEpg::GetPreviousEvent(const CEpgInfoTag& tag) const { CSingleLock lock(m_critSection); map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.find(tag.StartAsUTC()); if (it != m_tags.end() && it != m_tags.begin()) { --it; return it->second; } CEpgInfoTagPtr retVal; return retVal; }
const CEpgInfoTag *CEpg::GetTagBetween(const CDateTime &beginTime, const CDateTime &endTime) const { CEpgInfoTag *returnTag = NULL; CSingleLock lock(m_critSection); for (unsigned int iTagPtr = 0; iTagPtr < size(); iTagPtr++) { CEpgInfoTag *tag = at(iTagPtr); if (tag->StartAsUTC() >= beginTime && tag->EndAsUTC() <= endTime) { returnTag = tag; break; } } return returnTag; }
const CEpgInfoTag *CEpg::GetTagAround(const CDateTime &time) const { CEpgInfoTag *returnTag = NULL; CSingleLock lock(m_critSection); for (unsigned int iTagPtr = 0; iTagPtr < size(); iTagPtr++) { CEpgInfoTag *tag = at(iTagPtr); if ((tag->StartAsUTC() <= time) && (tag->EndAsUTC() >= time)) { returnTag = tag; break; } } return returnTag; }
void CPVRTimerInfoTag::UpdateEpgEvent(bool bClear /* = false */) { CSingleLock lock(m_critSection); if (bClear) { CEpgInfoTag *epgTag = GetEpgInfoTag(); if (epgTag) epgTag->OnTimerDeleted(); } else { /* already got an epg event set */ if (m_iEpgId != -1) return; /* try to get the channel */ CPVRChannel *channel = (CPVRChannel *) g_PVRChannelGroups->GetByUniqueID(m_iClientChannelUid, m_iClientId); if (!channel) return; /* try to get the EPG table */ CEpg *epg = channel->GetEPG(); if (!epg) return; /* try to set the timer on the epg tag that matches with a 2 minute margin */ CEpgInfoTag *epgTag = (CEpgInfoTag *) epg->GetTagBetween(StartAsUTC() - CDateTimeSpan(0, 0, 2, 0), EndAsUTC() + CDateTimeSpan(0, 0, 2, 0)); if (!epgTag) epgTag = (CEpgInfoTag *) epg->GetTagAround(StartAsUTC()); if (epgTag) { m_iEpgId = epgTag->m_iEpgId; m_epgStart = epgTag->StartAsUTC(); m_genre = epgTag->Genre(); m_iGenreType = epgTag->GenreType(); m_iGenreSubType = epgTag->GenreSubType(); epgTag->SetTimer(this); } } }
bool CEpg::InfoTagNow(CEpgInfoTag &tag) const { CSingleLock lock(m_critSection); if (!m_nowActive || !m_nowActive->IsActive()) { CDateTime now = CDateTime::GetCurrentDateTime().GetAsUTCDateTime(); /* one of the first items will always match if the list is sorted */ for (unsigned int iTagPtr = 0; iTagPtr < size(); iTagPtr++) { CEpgInfoTag *tag = at(iTagPtr); if (tag->StartAsUTC() <= now && tag->EndAsUTC() > now) { m_nowActive = tag; break; } } } if (m_nowActive) tag = *m_nowActive; return m_nowActive != NULL; }
int CEpgDatabase::Persist(const CEpgInfoTag &tag, bool bSingleUpdate /* = true */, bool bLastUpdate /* = false */) { int iReturn = -1; const CEpg *epg = tag.GetTable(); if (!epg || epg->EpgID() <= 0) { CLog::Log(LOGERROR, "%s - tag '%s' does not have a valid table", __FUNCTION__, tag.Title().c_str()); return iReturn; } time_t iStartTime, iEndTime, iFirstAired; tag.StartAsUTC().GetAsTime(iStartTime); tag.EndAsUTC().GetAsTime(iEndTime); tag.FirstAiredAsUTC().GetAsTime(iFirstAired); int iEpgId = epg->EpgID(); int iBroadcastId = tag.BroadcastId(); if (iBroadcastId <= 0) { CStdString strWhereClause; if (tag.UniqueBroadcastID() > 0) { strWhereClause = FormatSQL("(iBroadcastUid = '%u' OR iStartTime = %u) AND idEpg = %u", tag.UniqueBroadcastID(), iStartTime, iEpgId); } else { strWhereClause = FormatSQL("iStartTime = %u AND idEpg = '%u'", iStartTime, iEpgId); } CStdString strValue = GetSingleValue("epgtags", "idBroadcast", strWhereClause); if (!strValue.IsEmpty()) iBroadcastId = atoi(strValue); } CStdString strQuery; if (iBroadcastId < 0) { strQuery = FormatSQL("INSERT INTO epgtags (idEpg, iStartTime, " "iEndTime, sTitle, sPlotOutline, sPlot, iGenreType, iGenreSubType, " "iFirstAired, iParentalRating, iStarRating, bNotify, iSeriesId, " "iEpisodeId, iEpisodePart, sEpisodeName, iBroadcastUid) " "VALUES (%u, %u, %u, '%s', '%s', '%s', %i, %i, %u, %i, %i, %i, %i, %i, %i, '%s', %i);", iEpgId, iStartTime, iEndTime, tag.Title().c_str(), tag.PlotOutline().c_str(), tag.Plot().c_str(), tag.GenreType(), tag.GenreSubType(), iFirstAired, tag.ParentalRating(), tag.StarRating(), tag.Notify(), tag.SeriesNum(), tag.EpisodeNum(), tag.EpisodePart(), tag.EpisodeName().c_str(), tag.UniqueBroadcastID()); } else { strQuery = FormatSQL("REPLACE INTO epgtags (idEpg, iStartTime, " "iEndTime, sTitle, sPlotOutline, sPlot, iGenreType, iGenreSubType, " "iFirstAired, iParentalRating, iStarRating, bNotify, iSeriesId, " "iEpisodeId, iEpisodePart, sEpisodeName, iBroadcastUid, idBroadcast) " "VALUES (%u, %u, %u, '%s', '%s', '%s', %i, %i, %u, %i, %i, %i, %i, %i, %i, '%s', %i, %i);", iEpgId, iStartTime, iEndTime, tag.Title().c_str(), tag.PlotOutline().c_str(), tag.Plot().c_str(), tag.GenreType(), tag.GenreSubType(), tag.FirstAiredAsUTC().GetAsDBDateTime().c_str(), tag.ParentalRating(), tag.StarRating(), tag.Notify(), tag.SeriesNum(), tag.EpisodeNum(), tag.EpisodePart(), tag.EpisodeName().c_str(), tag.UniqueBroadcastID(), iBroadcastId); } if (bSingleUpdate) { if (ExecuteQuery(strQuery)) iReturn = (int) m_pDS->lastinsertid(); } else { QueueInsertQuery(strQuery); if (bLastUpdate) CommitInsertQueries(); iReturn = 0; } return iReturn; }
int CEpgDatabase::Persist(const CEpgInfoTag &tag, bool bSingleUpdate /* = true */) { int iReturn(-1); if (tag.EpgID() <= 0) { CLog::Log(LOGERROR, "%s - tag '%s' does not have a valid table", __FUNCTION__, tag.Title(true).c_str()); return iReturn; } time_t iStartTime, iEndTime, iFirstAired; tag.StartAsUTC().GetAsTime(iStartTime); tag.EndAsUTC().GetAsTime(iEndTime); tag.FirstAiredAsUTC().GetAsTime(iFirstAired); int iBroadcastId = tag.BroadcastId(); std::string strQuery; /* Only store the genre string when needed */ std::string strGenre = (tag.GenreType() == EPG_GENRE_USE_STRING) ? StringUtils::Join(tag.Genre(), g_advancedSettings.m_videoItemSeparator) : ""; if (iBroadcastId < 0) { strQuery = PrepareSQL("REPLACE INTO epgtags (idEpg, iStartTime, " "iEndTime, sTitle, sPlotOutline, sPlot, sIconPath, iGenreType, iGenreSubType, sGenre, " "iFirstAired, iParentalRating, iStarRating, bNotify, iSeriesId, " "iEpisodeId, iEpisodePart, sEpisodeName, iBroadcastUid, sRecordingId) " "VALUES (%u, %u, %u, '%s', '%s', '%s', '%s', %i, %i, '%s', %u, %i, %i, %i, %i, %i, %i, '%s', %i, '%s');", tag.EpgID(), iStartTime, iEndTime, tag.Title(true).c_str(), tag.PlotOutline(true).c_str(), tag.Plot(true).c_str(), tag.Icon().c_str(), tag.GenreType(), tag.GenreSubType(), strGenre.c_str(), iFirstAired, tag.ParentalRating(), tag.StarRating(), tag.Notify(), tag.SeriesNum(), tag.EpisodeNum(), tag.EpisodePart(), tag.EpisodeName().c_str(), tag.UniqueBroadcastID(), tag.RecordingId().c_str()); } else { strQuery = PrepareSQL("REPLACE INTO epgtags (idEpg, iStartTime, " "iEndTime, sTitle, sPlotOutline, sPlot, sIconPath, iGenreType, iGenreSubType, sGenre, " "iFirstAired, iParentalRating, iStarRating, bNotify, iSeriesId, " "iEpisodeId, iEpisodePart, sEpisodeName, iBroadcastUid, idBroadcast, sRecordingId) " "VALUES (%u, %u, %u, '%s', '%s', '%s', '%s', %i, %i, '%s', %u, %i, %i, %i, %i, %i, %i, '%s', %i, %i, '%s');", tag.EpgID(), iStartTime, iEndTime, tag.Title(true).c_str(), tag.PlotOutline(true).c_str(), tag.Plot(true).c_str(), tag.Icon().c_str(), tag.GenreType(), tag.GenreSubType(), strGenre.c_str(), iFirstAired, tag.ParentalRating(), tag.StarRating(), tag.Notify(), tag.SeriesNum(), tag.EpisodeNum(), tag.EpisodePart(), tag.EpisodeName().c_str(), tag.UniqueBroadcastID(), iBroadcastId, tag.RecordingId().c_str()); } if (bSingleUpdate) { if (ExecuteQuery(strQuery)) iReturn = (int) m_pDS->lastinsertid(); } else { QueueInsertQuery(strQuery); iReturn = 0; } return iReturn; }
int CEpgDatabase::Persist(const CEpgInfoTag &tag, bool bSingleUpdate /* = true */) { int iReturn(-1); const CEpg *epg = tag.GetTable(); if (!epg || epg->EpgID() <= 0) { CLog::Log(LOGERROR, "%s - tag '%s' does not have a valid table", __FUNCTION__, tag.Title().c_str()); return iReturn; } time_t iStartTime, iEndTime, iFirstAired; tag.StartAsUTC().GetAsTime(iStartTime); tag.EndAsUTC().GetAsTime(iEndTime); tag.FirstAiredAsUTC().GetAsTime(iFirstAired); int iEpgId = epg->EpgID(); if (bSingleUpdate) { Delete(*tag.GetTable(), iStartTime, iEndTime); } int iBroadcastId = tag.BroadcastId(); CSingleLock lock(m_critSection); CStdString strQuery; /* Only store the genre string when needed */ CStdString strGenre = (tag.GenreType() == EPG_GENRE_USE_STRING) ? tag.Genre() : ""; if (iBroadcastId < 0) { strQuery = FormatSQL("INSERT INTO epgtags (idEpg, iStartTime, " "iEndTime, sTitle, sPlotOutline, sPlot, iGenreType, iGenreSubType, sGenre, " "iFirstAired, iParentalRating, iStarRating, bNotify, iSeriesId, " "iEpisodeId, iEpisodePart, sEpisodeName, iBroadcastUid) " "VALUES (%u, %u, %u, '%s', '%s', '%s', %i, %i, '%s', %u, %i, %i, %i, %i, %i, %i, '%s', %i);", iEpgId, iStartTime, iEndTime, tag.Title().c_str(), tag.PlotOutline().c_str(), tag.Plot().c_str(), tag.GenreType(), tag.GenreSubType(), strGenre.c_str(), iFirstAired, tag.ParentalRating(), tag.StarRating(), tag.Notify(), tag.SeriesNum(), tag.EpisodeNum(), tag.EpisodePart(), tag.EpisodeName().c_str(), tag.UniqueBroadcastID()); } else { strQuery = FormatSQL("REPLACE INTO epgtags (idEpg, iStartTime, " "iEndTime, sTitle, sPlotOutline, sPlot, iGenreType, iGenreSubType, sGenre, " "iFirstAired, iParentalRating, iStarRating, bNotify, iSeriesId, " "iEpisodeId, iEpisodePart, sEpisodeName, iBroadcastUid, idBroadcast) " "VALUES (%u, %u, %u, '%s', '%s', '%s', %i, %i, '%s', %u, %i, %i, %i, %i, %i, %i, '%s', %i, %i);", iEpgId, iStartTime, iEndTime, tag.Title().c_str(), tag.PlotOutline().c_str(), tag.Plot().c_str(), tag.GenreType(), tag.GenreSubType(), strGenre.c_str(), iFirstAired, tag.ParentalRating(), tag.StarRating(), tag.Notify(), tag.SeriesNum(), tag.EpisodeNum(), tag.EpisodePart(), tag.EpisodeName().c_str(), tag.UniqueBroadcastID(), iBroadcastId); } if (bSingleUpdate) { if (ExecuteQuery(strQuery)) iReturn = (int) m_pDS->lastinsertid(); } else { QueueInsertQuery(strQuery); iReturn = 0; } return iReturn; }