Example #1
0
void CPVRManager::Process(void)
{
  /* load the pvr data from the db and clients if it's not already loaded */
  if (!Load())
  {
    /* close the busy dialog */
    ShowBusyDialog(false);
    CLog::Log(LOGERROR, "PVRManager - %s - failed to load PVR data", __FUNCTION__);
    return;
  }

  /* reset observers that are observing pvr related data in the pvr windows, or updates won't work after a reload */
  CGUIWindowPVR *pWindow = (CGUIWindowPVR *) g_windowManager.GetWindow(WINDOW_PVR);
  if (pWindow)
    pWindow->Reset();

  /* start the other pvr related update threads */
  m_addons->Start();
  m_guiInfo->Start();
  m_epg->RegisterObserver(this);
  m_epg->Start();

  /* continue last watched channel after first startup */
  if (!m_bStop && m_bFirstStart && g_guiSettings.GetInt("pvrplayback.startlast") != START_LAST_CHANNEL_OFF)
    ContinueLastChannel();

  /* close the busy dialog */
  ShowBusyDialog(false);

  /* signal to window that clients are loaded */
  if (pWindow)
    pWindow->UnlockWindow();

  /* check whether all channel icons are cached */
  m_channelGroups->GetGroupAllRadio()->CacheIcons();
  m_channelGroups->GetGroupAllTV()->CacheIcons();

  CLog::Log(LOGDEBUG, "PVRManager - %s - entering main loop", __FUNCTION__);

  /* main loop */
  while (!m_bStop)
  {
    /* keep trying to load remaining clients if they're not already loaded */
    if (!m_addons->AllClientsLoaded())
      m_addons->TryLoadClients(1);

    /* execute the next pending jobs if there are any */
    ExecutePendingJobs();

    /* check if the (still) are any enabled addons */
    if (DisableIfNoClients())
    {
      CLog::Log(LOGNOTICE, "PVRManager - %s - no add-ons enabled. disabling PVR functionality", __FUNCTION__);
      Stop();
      return;
    }

    WaitForSingleObject(m_triggerEvent, 1000);
  }

}