Exemple #1
0
bool CEpg::Update(time_t start, time_t end, int iUpdateTime, bool bStoreInDb /* = true */)
{
  bool bGrabSuccess = true;
  bool bUpdate = false;
  CEpgDatabase *database = g_EpgContainer.GetDatabase();
  if (bStoreInDb && (!database || !database->Open()))
  {
    CLog::Log(LOGERROR, "Epg - %s - cannot open the database", __FUNCTION__);
    return false;
  }

  CSingleLock lock(m_critSection);

  /* get the last update time from the database */
  if (!m_lastScanTime.IsValid() && bStoreInDb)
    database->GetLastEpgScanTime(m_iEpgID, &m_lastScanTime);

  /* check if we have to update */
  time_t iNow = 0;
  time_t iLastUpdate = 0;
  CDateTime::GetCurrentDateTime().GetAsTime(iNow);
  m_lastScanTime.GetAsTime(iLastUpdate);
  bUpdate = (iNow > iLastUpdate + iUpdateTime);

  if (bUpdate)
  {
    m_bInhibitSorting = true;
    bGrabSuccess = UpdateFromScraper(start, end);
    m_bInhibitSorting = false;

    /* store the loaded EPG entries in the database */
    if (bGrabSuccess && size() > 0)
    {
      Sort();
      FixOverlappingEvents(false);

      if (bStoreInDb)
      {
        database->PersistLastEpgScanTime(m_iEpgID, true);
        database->Persist(*this, true);
        PersistTags(true);
        database->CommitInsertQueries();
      }

      m_lastScanTime = CDateTime::GetCurrentDateTime();
    }
    else
    {
      m_lastScanTime = CDateTime::GetCurrentDateTime() - CDateTimeSpan(0, 0, 0, iUpdateTime + 300); /* try again in 5 minutes */
    }
  }

  if (bStoreInDb)
    database->Close();

  return bGrabSuccess;
}
Exemple #2
0
bool CEpg::Persist(void)
{
  if (CSettings::GetInstance().GetBool(CSettings::SETTING_EPG_IGNOREDBFORCLIENT) || !NeedsSave())
    return true;

#if EPG_DEBUGGING
  CLog::Log(LOGDEBUG, "persist table '%s' (#%d) changed=%d deleted=%d", Name().c_str(), m_iEpgID, m_changedTags.size(), m_deletedTags.size());
#endif

  CEpgDatabase *database = g_EpgContainer.GetDatabase();
  if (!database || !database->IsOpen())
  {
    CLog::Log(LOGERROR, "EPG - %s - could not open the database", __FUNCTION__);
    return false;
  }

  {
    CSingleLock lock(m_critSection);
    if (m_iEpgID <= 0 || m_bChanged)
    {
      int iId = database->Persist(*this, m_iEpgID > 0);
      if (iId > 0)
        m_iEpgID = iId;
    }

    for (std::map<int, CEpgInfoTagPtr>::iterator it = m_deletedTags.begin(); it != m_deletedTags.end(); ++it)
      database->Delete(*it->second);

    for (std::map<int, CEpgInfoTagPtr>::iterator it = m_changedTags.begin(); it != m_changedTags.end(); ++it)
      it->second->Persist(false);

    if (m_bUpdateLastScanTime)
      database->PersistLastEpgScanTime(m_iEpgID, true);

    m_deletedTags.clear();
    m_changedTags.clear();
    m_bChanged            = false;
    m_bTagsChanged        = false;
    m_bUpdateLastScanTime = false;
  }

  return database->CommitInsertQueries();
}
Exemple #3
0
bool CEpg::PersistTags(bool bQueueWrite /* = false */) const
{
  bool bReturn = false;
  CEpgDatabase *database = g_EpgContainer.GetDatabase();

  if (!database || !database->Open())
  {
    CLog::Log(LOGERROR, "EPG - %s - could not load the database", __FUNCTION__);
    return bReturn;
  }

  for (unsigned int iTagPtr = 0; iTagPtr < size(); iTagPtr++)
  {
    at(iTagPtr)->Persist(false);
  }

  if (!bQueueWrite)
    bReturn = database->CommitInsertQueries();
  else
    bReturn = true;

  return bReturn;
}