Beispiel #1
0
CEpgPtr CEpgContainer::CreateChannelEpg(CPVRChannelPtr channel)
{
  if (!channel)
    return NULL;

  WaitForUpdateFinish(true);
  LoadFromDB();

  CEpgPtr epg;
  if (channel->EpgID() > 0)
    epg = GetById(channel->EpgID());

  if (!epg)
  {
    channel->SetEpgID(NextEpgId());
    epg.reset(new CEpg(channel, false));

    CSingleLock lock(m_critSection);
    m_epgs.insert(std::make_pair((unsigned int)epg->EpgID(), epg));
    SetChanged();
    epg->RegisterObserver(this);
  }

  epg->SetChannel(channel);

  {
    CSingleLock lock(m_critSection);
    m_bPreventUpdates = false;
    CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate);
  }

  NotifyObservers(ObservableMessageEpgContainer);

  return epg;
}
void CPVRChannelGroupInternal::CreateChannelEpg(const CPVRChannelPtr &channel, bool bForce /* = false */)
{
  if (!channel)
    return;

  CSingleLock lock(channel->m_critSection);
  if (!channel->m_bEPGCreated || bForce)
  {
    CEpgPtr epg = g_EpgContainer.CreateChannelEpg(channel);
    if (epg)
    {
      channel->m_bEPGCreated = true;
      if (epg->EpgID() != channel->m_iEpgId)
      {
        channel->m_iEpgId = epg->EpgID();
        channel->m_bChanged = true;
      }
    }
  }
}
Beispiel #3
0
void CEpgContainer::CleanupEpgEvents(const CEpgPtr& epg)
{
  CSingleLock lock(m_critSection);
  if (epg)
  {
    m_epgScans.erase(epg->EpgID());
    auto events = epg->GetAllEventsWithBroadcastId();
    for (const auto &infoTag : events)
      m_epgEvents.erase(infoTag->UniqueBroadcastID());
  }
}
Beispiel #4
0
bool CEpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
{
    bool bInterrupted(false);
    unsigned int iUpdatedTables(0);
    bool bShowProgress(false);
    int pendingUpdates(0);

    /* set start and end time */
    time_t start;
    time_t end;
    CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(start);
    end = start + m_iDisplayTime;
    start -= g_advancedSettings.m_iEpgLingerTime * 60;
    bShowProgress = g_advancedSettings.m_bEpgDisplayUpdatePopup && (m_bIsInitialising || g_advancedSettings.m_bEpgDisplayIncrementalUpdatePopup);

    {
        CSingleLock lock(m_critSection);
        if (m_bIsUpdating || InterruptUpdate())
            return false;
        m_bIsUpdating = true;
        pendingUpdates = m_pendingUpdates;
    }

    if (bShowProgress && !bOnlyPending)
        ShowProgressDialog();

    if (!m_bIgnoreDbForClient && !m_database.IsOpen())
    {
        CLog::Log(LOGERROR, "EpgContainer - %s - could not open the database", __FUNCTION__);

        {
            CSingleLock lock(m_critSection);
            m_bIsUpdating = false;
            m_updateEvent.Set();
        }

        if (bShowProgress && !bOnlyPending)
            CloseProgressDialog();

        return false;
    }

    std::vector<CEpgPtr> invalidTables;

    /* load or update all EPG tables */
    unsigned int iCounter(0);
    for (const auto &epgEntry : m_epgs)
    {
        if (InterruptUpdate())
        {
            bInterrupted = true;
            break;
        }

        CEpgPtr epg = epgEntry.second;
        if (!epg)
            continue;

        if (bShowProgress && !bOnlyPending)
            UpdateProgressDialog(++iCounter, m_epgs.size(), epg->Name());

        // we currently only support update via pvr add-ons. skip update when the pvr manager isn't started
        if (!g_PVRManager.IsStarted())
            continue;

        // check the pvr manager when the channel pointer isn't set
        if (!epg->Channel())
        {
            CPVRChannelPtr channel = g_PVRChannelGroups->GetChannelByEpgId(epg->EpgID());
            if (channel)
                epg->SetChannel(channel);
        }

        if ((!bOnlyPending || epg->UpdatePending()) && epg->Update(start, end, m_iUpdateTime, bOnlyPending))
            iUpdatedTables++;
        else if (!epg->IsValid())
            invalidTables.push_back(epg);
    }

    for (auto it = invalidTables.begin(); it != invalidTables.end(); ++it)
        DeleteEpg(**it, true);

    if (bInterrupted)
    {
        /* the update has been interrupted. try again later */
        time_t iNow;
        CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(iNow);
        m_iNextEpgUpdate = iNow + g_advancedSettings.m_iEpgRetryInterruptedUpdateInterval;
    }
    else
    {
        if (g_PVRManager.IsStarted())
            g_PVRManager.Recordings()->UpdateEpgTags();

        CSingleLock lock(m_critSection);
        CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate);
        m_iNextEpgUpdate += g_advancedSettings.m_iEpgUpdateCheckInterval;
        if (m_pendingUpdates == pendingUpdates)
            m_pendingUpdates = 0;
    }

    if (bShowProgress && !bOnlyPending)
        CloseProgressDialog();

    /* notify observers */
    if (iUpdatedTables > 0)
    {
        SetChanged();
        CSingleExit ex(m_critSection);
        NotifyObservers(ObservableMessageEpgContainer);
    }

    CSingleLock lock(m_critSection);
    m_bIsUpdating = false;
    m_updateEvent.Set();

    return !bInterrupted;
}