void CPVRTimers::UpdateEpgEvent(CPVRTimerInfoTagPtr timer)
{
  CSingleLock lock(timer->m_critSection);

  /* already got an epg event set */
  if (timer->m_epgTag)
    return;

  /* try to get the channel */
  CPVRChannelPtr channel = g_PVRChannelGroups->GetByUniqueID(timer->m_iClientChannelUid, timer->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 */
  CEpgInfoTagPtr epgTag = epg->GetTagBetween(timer->StartAsUTC() - CDateTimeSpan(0, 0, 2, 0), timer->EndAsUTC() + CDateTimeSpan(0, 0, 2, 0));
  if (!epgTag)
    epgTag = epg->GetTagAround(timer->StartAsUTC());

  if (epgTag)
  {
    timer->m_epgTag = epgTag;
    timer->m_genre = epgTag->Genre();
    timer->m_iGenreType = epgTag->GenreType();
    timer->m_iGenreSubType = epgTag->GenreSubType();
    epgTag->SetTimer(timer);
  }
}
Ejemplo n.º 2
0
Archivo: Epg.cpp Proyecto: Elzevir/xbmc
bool CEpg::UpdateEntry(const CEpgInfoTagPtr &tag, bool bUpdateDatabase /* = false */)
{
  CEpgInfoTagPtr infoTag;

  {
    CSingleLock lock(m_critSection);
    std::map<CDateTime, CEpgInfoTagPtr>::iterator it = m_tags.find(tag->StartAsUTC());
    bool bNewTag(false);
    if (it != m_tags.end())
    {
      infoTag = it->second;
    }
    else
    {
      infoTag.reset(new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : ""));
      infoTag->SetUniqueBroadcastID(tag->UniqueBroadcastID());
      m_tags.insert(std::make_pair(tag->StartAsUTC(), infoTag));
      bNewTag = true;
    }

    infoTag->Update(*tag, bNewTag);
    infoTag->SetEpg(this);
    infoTag->SetPVRChannel(m_pvrChannel);

    if (bUpdateDatabase)
      m_changedTags.insert(std::make_pair(infoTag->UniqueBroadcastID(), infoTag));
  }

  infoTag->SetTimer(g_PVRTimers->GetTimerForEpgTag(infoTag));
  infoTag->SetRecording(g_PVRRecordings->GetRecordingForEpgTag(infoTag));

  return true;
}
Ejemplo n.º 3
0
Archivo: Epg.cpp Proyecto: Elzevir/xbmc
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));
  }
}
Ejemplo n.º 4
0
bool CEpg::UpdateEntry(const CEpgInfoTagPtr &tag, EPG_EVENT_STATE newState, std::map<CDateTime, CEpgInfoTagPtr>::iterator &eit, bool bUpdateDatabase /* = false */)
{
  CEpgInfoTagPtr infoTag;
  bool bNewTag(false);

  CSingleLock lock(m_critSection);

  if (newState == EPG_EVENT_CREATED || newState == EPG_EVENT_UPDATED)
  {
    // Reuse passed iterator in favor of doing expensive find self
    auto it = (eit == m_tags.end()) ? m_tags.find(tag->StartAsUTC()) : eit;
    if (it != m_tags.end())
    {
      if (newState == EPG_EVENT_CREATED)
        CLog::Log(LOGERROR, "EPG - %s - Error: EPG_EVENT_CREATED: uid %d found! Updating existing event.", __FUNCTION__, tag->UniqueBroadcastID());

      infoTag = it->second;
    }
    else
    {
      if (newState == EPG_EVENT_UPDATED)
        CLog::Log(LOGERROR, "EPG - %s - Error: EPG_EVENT_UPDATED: uid %d not found. Inserting new event.", __FUNCTION__, tag->UniqueBroadcastID());

      infoTag.reset(new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : ""));
      infoTag->SetUniqueBroadcastID(tag->UniqueBroadcastID());
      m_tags.insert(std::make_pair(tag->StartAsUTC(), infoTag));
      bNewTag = true;
    }
  }
  else if (newState == EPG_EVENT_DELETED)
  {
    // Reuse passed iterator in favor of doing expensive find self
    auto it = (eit == m_tags.end()) ? m_tags.find(tag->StartAsUTC()) : eit;
    if (it == m_tags.end())
    {
      // not guranteed that deleted tag contains valid start time. search sequential.
      for (it = m_tags.begin(); it != m_tags.end(); ++it)
      {
        if (it->second->UniqueBroadcastID() == tag->UniqueBroadcastID())
          break;
      }
    }

    if (it != m_tags.end())
    {
      it->second->ClearTimer();
      m_tags.erase(it);

      if (bUpdateDatabase)
        m_deletedTags.insert(std::make_pair(infoTag->UniqueBroadcastID(), infoTag));
    }
    else
    {
      CLog::Log(LOGERROR, "EPG - %s - Error: EPG_EVENT_DELETED: uid %d not found.", __FUNCTION__, tag->UniqueBroadcastID());
      return false;
    }

    return true;
  }
  else
  {
    CLog::Log(LOGERROR, "EPG - %s - unknownn epg event state '%d'.", __FUNCTION__, newState);
    return false;
  }

  infoTag->Update(*tag, bNewTag);
  infoTag->SetEpg(this);
  infoTag->SetPVRChannel(m_pvrChannel);
  infoTag->SetTimer(g_PVRTimers->GetTimerForEpgTag(infoTag));

  if (bUpdateDatabase)
    m_changedTags.insert(std::make_pair(infoTag->UniqueBroadcastID(), infoTag));

  return true;
}