Beispiel #1
0
bool CPVRChannel::Delete(void)
{
  bool bReturn = false;
  CPVRDatabase *database = GetPVRDatabase();
  if (!database)
    return bReturn;

  /* delete the EPG table */
  CEpg *epg = GetEPG();
  if (epg)
  {
    CPVRChannelPtr empty;
    epg->SetChannel(empty);
    g_EpgContainer.DeleteEpg(*epg, true);
    CSingleLock lock(m_critSection);
    m_bEPGCreated = false;
  }

  bReturn = database->Delete(*this);
  return bReturn;
}
Beispiel #2
0
bool CEpgContainer::DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase /* = false */)
{
  if (epg.EpgID() < 0)
    return false;

  CSingleLock lock(m_critSection);

  const auto &epgEntry = m_epgs.find((unsigned int)epg.EpgID());
  if (epgEntry == m_epgs.end())
    return false;

  CLog::Log(LOGDEBUG, "deleting EPG table %s (%d)", epg.Name().c_str(), epg.EpgID());
  if (bDeleteFromDatabase && !m_bIgnoreDbForClient && m_database.IsOpen())
    m_database.Delete(*epgEntry->second);

  epgEntry->second->UnregisterObserver(this);
  CleanupEpgEvents(epgEntry->second);
  m_epgs.erase(epgEntry);

  return true;
}
Beispiel #3
0
int CPVRChannelGroup::GetEPGAll(CFileItemList &results)
{
  int iInitialSize = results.Size();
  CSingleLock lock(m_critSection);

  for (unsigned int iChannelPtr = 0; iChannelPtr < m_members.size(); iChannelPtr++)
  {
    if (m_members.at(iChannelPtr).channel && !m_members.at(iChannelPtr).channel->IsHidden())
    {
      CEpg* epg = m_members.at(iChannelPtr).channel->GetEPG();
      if (epg)
      {
        // XXX channel pointers aren't set in some occasions. this works around the issue, but is not very nice
        epg->SetChannel(m_members.at(iChannelPtr).channel);
        epg->Get(results);
      }
    }
  }

  return results.Size() - iInitialSize;
}
Beispiel #4
0
bool CEpgDatabase::Delete(const CEpg &table, const time_t start /* = 0 */, const time_t end /* = 0 */)
{
  /* invalid channel */
  if (table.EpgID() <= 0)
  {
    CLog::Log(LOGERROR, "EpgDB - %s - invalid channel id: %d",
        __FUNCTION__, table.EpgID());
    return false;
  }

  CStdString strWhereClause;
  strWhereClause = FormatSQL("idEpg = %u", table.EpgID());

  if (start != 0)
    strWhereClause.append(FormatSQL(" AND iStartTime >= %u", start).c_str());

  if (end != 0)
    strWhereClause.append(FormatSQL(" AND iEndTime <= %u", end).c_str());

  CSingleLock lock(m_critSection);
  return DeleteValues("epgtags", strWhereClause);
}
Beispiel #5
0
int CPVRChannelGroup::GetEPGAll(CFileItemList &results) const
{
  int iInitialSize = results.Size();
  CEpg* epg;
  CSingleLock lock(m_critSection);

  for (std::vector<PVRChannelGroupMember>::const_iterator it = m_members.begin(); it != m_members.end(); ++it)
  {
    if ((*it).channel && !(*it).channel->IsHidden())
    {
      epg = (*it).channel->GetEPG();
      if (epg)
      {
        // XXX channel pointers aren't set in some occasions. this works around the issue, but is not very nice
        epg->SetChannel((*it).channel);
        epg->Get(results);
      }
    }
  }

  return results.Size() - iInitialSize;
}
Beispiel #6
0
bool CPVRChannel::CreateEPG(bool bForce /* = false */)
{
  CSingleLock lock(m_critSection);
  if (!m_bEPGCreated || bForce)
  {
    CEpg epgTmp(this, false);
    if (g_EpgContainer.UpdateEntry(epgTmp))
    {
      CEpg *epg = g_EpgContainer.GetByChannel(*this);
      if (epg)
      {
        m_bEPGCreated = true;
        if (epg->EpgID() != m_iEpgId)
        {
          m_iEpgId = epg->EpgID();
          m_bChanged = true;
        }
      }
    }
  }

  return m_bEPGCreated;
}
Beispiel #7
0
bool CEpgContainer::UpdateEntry(const CEpg &entry, bool bUpdateDatabase /* = false */)
{
  CEpg *epg(NULL);
  bool bReturn(false);
  WaitForUpdateFinish(true);

  CSingleLock lock(m_critSection);
  epg = entry.EpgID() > 0 ? GetById(entry.EpgID()) : NULL;
  if (!epg)
  {
    /* table does not exist yet, create a new one */
    unsigned int iEpgId = !m_bIgnoreDbForClient ? entry.EpgID() : NextEpgId();
    epg = CreateEpg(iEpgId);
    if (epg)
      InsertEpg(epg);
  }

  bReturn = epg ? epg->UpdateMetadata(entry, bUpdateDatabase) : false;
  m_bPreventUpdates = false;
  CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate);
  lock.Leave();

  return bReturn;
}
Beispiel #8
0
bool CEpg::UpdateMetadata(const CEpg &epg, bool bUpdateDb /* = false */)
{
  bool bReturn = true;
  CSingleLock lock(m_critSection);

  m_strName = epg.m_strName;
  m_strScraperName = epg.m_strScraperName;
  if (epg.HasPVRChannel())
    m_Channel = epg.m_Channel;

  if (bUpdateDb)
    bReturn = Persist();

  return bReturn;
}
Beispiel #9
0
JSONRPC_STATUS CPVROperations::GetBroadcasts(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
  if (!g_PVRManager.IsStarted())
    return FailedToExecute;

  CPVRChannelGroupsContainer *channelGroupContainer = g_PVRManager.ChannelGroups();
  if (channelGroupContainer == NULL)
    return FailedToExecute;

  CPVRChannelPtr channel = channelGroupContainer->GetChannelById((int)parameterObject["channelid"].asInteger());
  if (channel == NULL)
    return InvalidParams;

  CEpg *channelEpg = channel->GetEPG();
  if (channelEpg == NULL)
    return InternalError;

  CFileItemList programFull;
  channelEpg->Get(programFull);

  HandleFileItemList("broadcastid", false, "broadcasts", programFull, parameterObject, result, programFull.Size(), true);

  return OK;
}
Beispiel #10
0
void CPVRTimers::UpdateEpgEvent(CPVRTimerInfoTagPtr timer)
{
  CSingleLock lock(timer->m_critSection);

  /* repeating timers have no epg event */
  if (timer->IsRepeating())
    return;

  /* 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);
  }
}
Beispiel #11
0
void CPVRTimerInfoTag::UpdateEpgEvent(bool bClear /* = false */)
{
  CSingleLock lock(m_critSection);
  if (bClear)
  {
    if (m_epgInfo)
    {
      m_epgInfo->SetTimer(NULL);
      m_epgInfo = NULL;
    }
  }
  else
  {
    /* already got an epg event set */
    if (m_epgInfo)
      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 */
    m_epgInfo = (CEpgInfoTag *) epg->GetTagBetween(StartAsUTC() - CDateTimeSpan(0, 0, 2, 0), EndAsUTC() + CDateTimeSpan(0, 0, 2, 0));
    if (!m_epgInfo)
      m_epgInfo = (CEpgInfoTag *) epg->GetTagAround(StartAsUTC());

    if (m_epgInfo)
      m_epgInfo->SetTimer(this);
  }
}
Beispiel #12
0
bool CEpgContainer::DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase /* = false */)
{
  bool bReturn = false;
  CSingleLock lock(m_critSection);

  for (unsigned int iEpgPtr = 0; iEpgPtr < m_epgs.size(); iEpgPtr++)
  {
    if (m_epgs[iEpgPtr]->EpgID() == epg.EpgID())
    {
      if (bDeleteFromDatabase && !m_bIgnoreDbForClient && m_database.Open())
      {
        m_database.Delete(*m_epgs[iEpgPtr]);
        m_database.Close();
      }

      delete m_epgs[iEpgPtr];
      m_epgs.erase(m_epgs.begin() + iEpgPtr);
      bReturn = true;
      break;
    }
  }

  return bReturn;
}
Beispiel #13
0
bool CPVRChannel::GetEPGNext(CEpgInfoTag &tag) const
{
    CEpg *epg = GetEPG();
    return epg ? epg->InfoTagNext(tag) : false;
}
Beispiel #14
0
bool CEpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
{
  bool bInterrupted(false);
  unsigned int iUpdatedTables(0);
  bool bShowProgress(false);

  /* 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;
  }

  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;
  }

  vector<CEpg*> invalidTables;

  /* load or update all EPG tables */
  CEpg *epg;
  unsigned int iCounter(0);
  for (map<unsigned int, CEpg *>::iterator it = m_epgs.begin(); it != m_epgs.end(); it++)
  {
    if (InterruptUpdate())
    {
      bInterrupted = true;
      break;
    }

    epg = it->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 (vector<CEpg*>::iterator 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
  {
    CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate);
    m_iNextEpgUpdate += g_advancedSettings.m_iEpgUpdateCheckInterval;
    m_bHasPendingUpdates = false;
  }

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

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

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

  return !bInterrupted;
}
Beispiel #15
0
int CEpgDatabase::Get(CEpg &epg)
{
  int iReturn(-1);

  std::string strQuery = PrepareSQL("SELECT * FROM epgtags WHERE idEpg = %u;", epg.EpgID());
  if (ResultQuery(strQuery))
  {
    iReturn = 0;
    try
    {
      while (!m_pDS->eof())
      {
        CEpgInfoTagPtr newTag(new CEpgInfoTag());

        time_t iStartTime, iEndTime, iFirstAired;
        iStartTime = (time_t) m_pDS->fv("iStartTime").get_asInt();
        CDateTime startTime(iStartTime);
        newTag->m_startTime = startTime;

        iEndTime = (time_t) m_pDS->fv("iEndTime").get_asInt();
        CDateTime endTime(iEndTime);
        newTag->m_endTime = endTime;

        iFirstAired = (time_t) m_pDS->fv("iFirstAired").get_asInt();
        CDateTime firstAired(iFirstAired);
        newTag->m_firstAired = firstAired;

        newTag->m_iUniqueBroadcastID = m_pDS->fv("iBroadcastUid").get_asInt();
        newTag->m_iBroadcastId       = m_pDS->fv("idBroadcast").get_asInt();
        newTag->m_strTitle           = m_pDS->fv("sTitle").get_asString().c_str();
        newTag->m_strPlotOutline     = m_pDS->fv("sPlotOutline").get_asString().c_str();
        newTag->m_strPlot            = m_pDS->fv("sPlot").get_asString().c_str();
        newTag->m_strOriginalTitle   = m_pDS->fv("sOriginalTitle").get_asString().c_str();
        newTag->m_strCast            = m_pDS->fv("sCast").get_asString().c_str();
        newTag->m_strDirector        = m_pDS->fv("sDirector").get_asString().c_str();
        newTag->m_strWriter          = m_pDS->fv("sWriter").get_asString().c_str();
        newTag->m_iYear              = m_pDS->fv("iYear").get_asInt();
        newTag->m_strIMDBNumber      = m_pDS->fv("sIMDBNumber").get_asString().c_str();
        newTag->m_iGenreType         = m_pDS->fv("iGenreType").get_asInt();
        newTag->m_iGenreSubType      = m_pDS->fv("iGenreSubType").get_asInt();
        newTag->m_genre              = StringUtils::Split(m_pDS->fv("sGenre").get_asString().c_str(), g_advancedSettings.m_videoItemSeparator);
        newTag->m_iParentalRating    = m_pDS->fv("iParentalRating").get_asInt();
        newTag->m_iStarRating        = m_pDS->fv("iStarRating").get_asInt();
        newTag->m_bNotify            = m_pDS->fv("bNotify").get_asBool();
        newTag->m_iEpisodeNumber     = m_pDS->fv("iEpisodeId").get_asInt();
        newTag->m_iEpisodePart       = m_pDS->fv("iEpisodePart").get_asInt();
        newTag->m_strEpisodeName     = m_pDS->fv("sEpisodeName").get_asString().c_str();
        newTag->m_iSeriesNumber      = m_pDS->fv("iSeriesId").get_asInt();
        newTag->m_strIconPath        = m_pDS->fv("sIconPath").get_asString().c_str();

        epg.AddEntry(*newTag);
        ++iReturn;

        m_pDS->next();
      }
      m_pDS->close();
    }
    catch (...)
    {
      CLog::Log(LOGERROR, "%s - couldn't load EPG data from the database", __FUNCTION__);
    }
  }
  return iReturn;
}
Beispiel #16
0
bool CEpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
{
  bool bInterrupted(false);
  unsigned int iUpdatedTables(0);
  bool bShowProgress(false);

  /* 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;
  }

  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;
  }

  /* load or update all EPG tables */
  CEpg *epg;
  unsigned int iCounter(0);
  for (map<unsigned int, CEpg *>::iterator it = m_epgs.begin(); it != m_epgs.end(); it++)
  {
    if (InterruptUpdate())
    {
      bInterrupted = true;
      break;
    }

    epg = it->second;
    if (!epg)
      continue;

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

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

  if (!bInterrupted)
  {
    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
    {
      CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate);
      m_iNextEpgUpdate += g_advancedSettings.m_iEpgUpdateCheckInterval;
      m_bHasPendingUpdates = false;
    }
  }

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

  /* notify observers */
  if (iUpdatedTables > 0)
  {
    SetChanged();
    NotifyObservers("epg", true);
  }

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

  return !bInterrupted;
}
Beispiel #17
0
bool CEpgContainer::UpdateEPG(bool bShowProgress /* = false */)
{
  bool bInterrupted(false);
  bool bDbOpened(false);
  unsigned int iUpdatedTables(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;

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

  if (bShowProgress)
    ShowProgressDialog();

  /* open the database */
  if (!m_bIgnoreDbForClient && !(bDbOpened = m_database.Open()))
  {
    CLog::Log(LOGERROR, "EpgContainer - %s - could not open the database", __FUNCTION__);
    return false;
  }

  /* load or update all EPG tables */
  CEpg *epg;
  for (unsigned int iEpgPtr = 0; iEpgPtr < m_epgs.size(); iEpgPtr++)
  {
    if (InterruptUpdate())
    {
      bInterrupted = true;
      break;
    }

    epg = m_epgs[iEpgPtr];
    if (!epg)
      continue;

    if (epg->Update(start, end, m_iUpdateTime))
      ++iUpdatedTables;

    if (bShowProgress)
      UpdateProgressDialog(iEpgPtr, m_epgs.size(), epg->Name());
  }

  if (!bInterrupted)
  {
    CSingleLock lock(m_critSection);
    m_bIsUpdating = false;

    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
    {
      CDateTime::GetCurrentDateTime().GetAsUTCDateTime().GetAsTime(m_iNextEpgUpdate);
      m_iNextEpgUpdate += g_advancedSettings.m_iEpgUpdateCheckInterval;
    }
  }

  if (bShowProgress)
    CloseProgressDialog();

  /* notify observers */
  if (iUpdatedTables > 0)
  {
    if (CheckPlayingEvents())
      SetChanged();
    NotifyObservers("epg", true);
  }

  if (bDbOpened)
    m_database.Close();
  m_updateEvent.Set();

  return !bInterrupted;
}