Пример #1
0
bool CPVRClients::UpdateAndInitialiseClients(bool bInitialiseAllClients /* = false */)
{
  bool bReturn(true);
  ADDON::VECADDONS map;
  {
    CSingleLock lock(m_critSection);
    map = m_addons;
  }

  for (unsigned iClientPtr = 0; iClientPtr < map.size(); iClientPtr++)
  {
    const AddonPtr clientAddon = map.at(iClientPtr);

    if (!clientAddon->Enabled() && IsKnownClient(clientAddon))
    {
      /* stop the client and remove it from the db */
      bReturn &= StopClient(clientAddon, false) && bReturn;
    }
    else if (clientAddon->Enabled() && (bInitialiseAllClients || !IsKnownClient(clientAddon)))
    {
      /* register the new client and initialise it */
      bReturn &= InitialiseClient(clientAddon) && bReturn;
    }
  }

  /* check whether all clients are (still) connected */
  {
    CSingleLock lock(m_critSection);
    m_bAllClientsConnected = (ConnectedClientAmount() == EnabledClientAmount());
  }

  return bReturn;
}
Пример #2
0
int CActiveAEDSP::RegisterAudioDSPAddon(AddonPtr addon, bool* newRegistration/*=NULL*/)
{
    int iAddonId(-1);

    if (newRegistration)
        *newRegistration = false;

    if (!addon->Enabled())
        return -1;

    CLog::Log(LOGDEBUG, "ActiveAE DSP - %s - registering add-on '%s'", __FUNCTION__, addon->Name().c_str());

    if (!m_databaseDSP.IsOpen())
    {
        CLog::Log(LOGERROR, "ActiveAE DSP - %s - failed to get the database", __FUNCTION__);
        return -1;
    }

    /* check whether we already know this dsp addon */
    iAddonId = m_databaseDSP.GetAudioDSPAddonId(addon->ID());

    /* try to register the new dsp addon in the db */
    if (iAddonId < 0)
    {
        if ((iAddonId = m_databaseDSP.Persist(addon)) < 0)
        {
            CLog::Log(LOGERROR, "ActiveAE DSP - %s - can't add dsp addon '%s' to the database", __FUNCTION__, addon->Name().c_str());
            return -1;
        }
        else if (newRegistration)
            *newRegistration = true;
    }

    AE_DSP_ADDON dspAddon;
    /* load and initialise the dsp addon libraries */
    {
        CSingleLock lock(m_critSection);
        AE_DSP_ADDONMAP_CITR existingAddon = m_addonMap.find(iAddonId);
        if (existingAddon != m_addonMap.end())
        {
            /* return existing addon */
            dspAddon = existingAddon->second;
        }
        else
        {
            /* create a new addon instance */
            dspAddon = std::dynamic_pointer_cast<CActiveAEDSPAddon> (addon);
            m_addonMap.insert(std::make_pair(iAddonId, dspAddon));
        }
    }

    if (iAddonId < 0)
        CLog::Log(LOGERROR, "ActiveAE DSP - %s - can't register dsp add-on '%s'", __FUNCTION__, addon->Name().c_str());

    return iAddonId;
}
Пример #3
0
int CPVRClients::RegisterClient(AddonPtr client, bool* newRegistration/*=NULL*/)
{
  int iClientId(-1);

  if (newRegistration)
    *newRegistration = false;

  if (!client->Enabled())
    return -1;

  CLog::Log(LOGDEBUG, "%s - registering add-on '%s'", __FUNCTION__, client->Name().c_str());

  CPVRDatabase *database = GetPVRDatabase();
  if (!database)
    return -1;

  // check whether we already know this client
  iClientId = database->GetClientId(client->ID());

  // try to register the new client in the db
  if (iClientId < 0)
  {
    if ((iClientId = database->Persist(client)) < 0)
    {
      CLog::Log(LOGERROR, "PVR - %s - can't add client '%s' to the database", __FUNCTION__, client->Name().c_str());
      return -1;
    }
    else if (newRegistration)
      *newRegistration = true;
  }

  PVR_CLIENT addon;
  // load and initialise the client libraries
  {
    CSingleLock lock(m_critSection);
    PVR_CLIENTMAP_CITR existingClient = m_clientMap.find(iClientId);
    if (existingClient != m_clientMap.end())
    {
      // return existing client
      addon = existingClient->second;
    }
    else
    {
      // create a new client instance
      addon = boost::dynamic_pointer_cast<CPVRClient>(client);
      m_clientMap.insert(std::make_pair(iClientId, addon));
    }
  }

  if (iClientId < 0)
    CLog::Log(LOGERROR, "PVR - %s - can't register add-on '%s'", __FUNCTION__, client->Name().c_str());

  return iClientId;
}
Пример #4
0
int CPVRClients::RegisterClient(AddonPtr client)
{
  int iClientId(-1);
  CAddonDatabase database;
  PVR_CLIENT addon;

  if (!client->Enabled() || !database.Open())
    return -1;

  CLog::Log(LOGDEBUG, "%s - registering add-on '%s'", __FUNCTION__, client->Name().c_str());

  // check whether we already know this client
  iClientId = database.GetAddonId(client); //database->GetClientId(client->ID());

  // try to register the new client in the db
  if (iClientId <= 0)
    iClientId = database.AddAddon(client, 0);

  if (iClientId > 0)
  // load and initialise the client libraries
  {
    CSingleLock lock(m_critSection);
    PVR_CLIENTMAP_CITR existingClient = m_clientMap.find(iClientId);
    if (existingClient != m_clientMap.end())
    {
      // return existing client
      addon = existingClient->second;
    }
    else
    {
      // create a new client instance
      addon = std::dynamic_pointer_cast<CPVRClient>(client);
      m_clientMap.insert(std::make_pair(iClientId, addon));
      m_addonNameIds.insert(make_pair(addon->ID(), iClientId));
    }
  }

  if (iClientId <= 0)
    CLog::Log(LOGERROR, "PVR - %s - can't register add-on '%s'", __FUNCTION__, client->Name().c_str());

  return iClientId;
}
Пример #5
0
bool CPVRClients::InitialiseClient(AddonPtr client)
{
  bool bReturn(false);
  if (!client->Enabled())
    return bReturn;

  CLog::Log(LOGDEBUG, "%s - initialising add-on '%s'", __FUNCTION__, client->Name().c_str());

  /* register this client in the db */
  int iClientId = AddClientToDb(client);
  if (iClientId == -1)
    return bReturn;

  /* load and initialise the client libraries */
  boost::shared_ptr<CPVRClient> addon;
  {
    CSingleLock lock(m_critSection);
    CLIENTMAPITR existingClient = m_clientMap.find(iClientId);
    if (existingClient != m_clientMap.end())
    {
      addon = existingClient->second;
    }
    else
    {
      addon = boost::dynamic_pointer_cast<CPVRClient>(client);
      m_clientMap.insert(std::make_pair(iClientId, addon));
    }
  }

  if (addon)
    bReturn = addon->Create(iClientId);

  if (!bReturn)
    CLog::Log(LOGERROR, "PVR - %s - can't initialise add-on '%s'", __FUNCTION__, client->Name().c_str());

  return bReturn;
}
Пример #6
0
bool CPVRClients::LoadClients(void)
{
  if (m_bAllClientsLoaded)
    return !m_clientMap.empty();

  CAddonMgr::Get().RegisterAddonMgrCallback(ADDON_PVRDLL, this);

  /* get all PVR addons */
  VECADDONS addons;
  if (!CAddonMgr::Get().GetAddons(ADDON_PVRDLL, addons, true))
    return false;

  /* load and initialise the clients */
  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
  if (!database || !database->Open())
  {
    CLog::Log(LOGERROR, "PVR - %s - cannot open the database", __FUNCTION__);
    return false;
  }

  m_bAllClientsLoaded = true;
  for (unsigned iClientPtr = 0; iClientPtr < addons.size(); iClientPtr++)
  {
    const AddonPtr clientAddon = addons.at(iClientPtr);
    if (!clientAddon->Enabled())
      continue;

    int iClientId = AddClientToDb(clientAddon->ID(), clientAddon->Name());
    if (iClientId == -1)
      continue; // don't set "m_bAllClientsLoaded = false;" here because this will enter a neverending loop

    /* check if this client isn't active already */
    if (ClientLoaded(clientAddon->ID()))
      continue;

    /* load and initialise the client libraries */
    boost::shared_ptr<CPVRClient> addon = boost::dynamic_pointer_cast<CPVRClient>(clientAddon);
    if (addon && addon->Create(iClientId, this))
    {
      /* get the client's properties */
      PVR_SERVERPROPS props;
      if (addon->GetProperties(&props) == PVR_ERROR_NO_ERROR)
      {
        m_clientMap.insert(std::make_pair(iClientId, addon));
        m_clientsProps.insert(std::make_pair(iClientId, props));
      }
      else
      {
        CLog::Log(LOGERROR, "PVR - %s - can't get client properties from addon '%s'",
            __FUNCTION__, clientAddon->Name().c_str());
        m_bAllClientsLoaded = false;
      }
    }
    else
    {
      CLog::Log(LOGERROR, "PVR - %s - can't initialise client '%s'",
          __FUNCTION__, clientAddon->Name().c_str());
      m_bAllClientsLoaded = false;
    }
  }

  database->Close();

  return !m_clientMap.empty();
}
Пример #7
0
bool CPVRClients::UpdateAndInitialiseClients(bool bInitialiseAllClients /* = false */)
{
  bool bReturn(true);
  ADDON::VECADDONS map;
  ADDON::VECADDONS disableAddons;
  {
    CSingleLock lock(m_critSection);
    map = m_addons;
  }

  if (map.size() == 0)
    return false;

  for (unsigned iClientPtr = 0; iClientPtr < map.size(); iClientPtr++)
  {
    const AddonPtr clientAddon = map.at(iClientPtr);
    bool bEnabled = clientAddon->Enabled() &&
        !m_addonDb.IsAddonDisabled(clientAddon->ID());

    if (!bEnabled && IsKnownClient(clientAddon))
    {
      CSingleLock lock(m_critSection);
      /* stop the client and remove it from the db */
      StopClient(clientAddon, false);
      ADDON::VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), clientAddon);
      if (addonPtr != m_addons.end())
        m_addons.erase(addonPtr);

    }
    else if (bEnabled && (bInitialiseAllClients || !IsKnownClient(clientAddon) || !IsConnectedClient(clientAddon)))
    {
      bool bDisabled(false);

      // register the add-on in the pvr db, and create the CPVRClient instance
      int iClientId = RegisterClient(clientAddon);
      if (iClientId < 0)
      {
        // failed to register or create the add-on, disable it
        CLog::Log(LOGWARNING, "%s - failed to register add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str());
        disableAddons.push_back(clientAddon);
        bDisabled = true;
      }
      else
      {
        ADDON_STATUS status(ADDON_STATUS_UNKNOWN);
        PVR_CLIENT addon;
        {
          CSingleLock lock(m_critSection);
          if (!GetClient(iClientId, addon))
          {
            CLog::Log(LOGWARNING, "%s - failed to find add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str());
            disableAddons.push_back(clientAddon);
            bDisabled = true;
          }
        }

        // throttle connection attempts, no more than 1 attempt per 5 seconds
        if (!bDisabled && addon->Enabled())
        {
          time_t now;
          CDateTime::GetCurrentDateTime().GetAsTime(now);
          std::map<int, time_t>::iterator it = m_connectionAttempts.find(iClientId);
          if (it != m_connectionAttempts.end() && now < it->second)
            continue;
          m_connectionAttempts[iClientId] = now + 5;
        }

        // re-check the enabled status. newly installed clients get disabled when they're added to the db
        if (!bDisabled && addon->Enabled() && (status = addon->Create(iClientId)) != ADDON_STATUS_OK)
        {
          CLog::Log(LOGWARNING, "%s - failed to create add-on %s, status = %d", __FUNCTION__, clientAddon->Name().c_str(), status);
          if (!addon.get() || !addon->DllLoaded() || status == ADDON_STATUS_PERMANENT_FAILURE)
          {
            // failed to load the dll of this add-on, disable it
            CLog::Log(LOGWARNING, "%s - failed to load the dll for add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str());
            disableAddons.push_back(clientAddon);
            bDisabled = true;
          }
        }
      }

      if (bDisabled && (g_PVRManager.GetState() == ManagerStateStarted || g_PVRManager.GetState() == ManagerStateStarting))
        CGUIDialogOK::ShowAndGetInput(24070, 24071, 16029, 0);
    }
  }

  // disable add-ons that failed to initialise
  if (disableAddons.size() > 0)
  {
    CSingleLock lock(m_critSection);
    for (ADDON::VECADDONS::iterator it = disableAddons.begin(); it != disableAddons.end(); it++)
    {
      // disable in the add-on db
      m_addonDb.DisableAddon((*it)->ID(), true);

      // remove from the pvr add-on list
      ADDON::VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), *it);
      if (addonPtr != m_addons.end())
        m_addons.erase(addonPtr);
    }
  }

  return bReturn;
}
Пример #8
0
bool CActiveAEDSP::UpdateAndInitialiseAudioDSPAddons(bool bInitialiseAllAudioDSPAddons /* = false */)
{
    bool bReturn(true);
    VECADDONS map;
    VECADDONS disableAddons;
    {
        CSingleLock lock(m_critUpdateSection);
        map = m_addons;
    }

    if (map.size() == 0)
        return false;

    for (unsigned iAddonPtr = 0; iAddonPtr < map.size(); ++iAddonPtr)
    {
        const AddonPtr dspAddon = map.at(iAddonPtr);
        bool bEnabled = dspAddon->Enabled() &&
                        !CAddonMgr::GetInstance().IsAddonDisabled(dspAddon->ID());

        if (!bEnabled && IsKnownAudioDSPAddon(dspAddon))
        {
            CSingleLock lock(m_critUpdateSection);
            /* stop the dsp addon and remove it from the db */
            StopAudioDSPAddon(dspAddon, false);
            VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), dspAddon);
            if (addonPtr != m_addons.end())
                m_addons.erase(addonPtr);

        }
        else if (bEnabled && (bInitialiseAllAudioDSPAddons || !IsKnownAudioDSPAddon(dspAddon) || !IsReadyAudioDSPAddon(dspAddon)))
        {
            bool bDisabled(false);

            /* register the add-on in the audio dsp db, and create the CActiveAEDSPAddon instance */
            int iAddonId = RegisterAudioDSPAddon(dspAddon);
            if (iAddonId < 0)
            {
                /* failed to register or create the add-on, disable it */
                CLog::Log(LOGWARNING, "ActiveAE DSP - %s - failed to register add-on %s, disabling it", __FUNCTION__, dspAddon->Name().c_str());
                disableAddons.push_back(dspAddon);
                bDisabled = true;
            }
            else
            {
                ADDON_STATUS status(ADDON_STATUS_UNKNOWN);
                AE_DSP_ADDON addon;
                {
                    CSingleLock lock(m_critUpdateSection);
                    if (!GetAudioDSPAddon(iAddonId, addon))
                    {
                        CLog::Log(LOGWARNING, "ActiveAE DSP - %s - failed to find add-on %s, disabling it", __FUNCTION__, dspAddon->Name().c_str());
                        disableAddons.push_back(dspAddon);
                        bDisabled = true;
                    }
                }

                /* re-check the enabled status. newly installed dsps get disabled when they're added to the db */
                if (!bDisabled && addon->Enabled() && (status = addon->Create(iAddonId)) != ADDON_STATUS_OK)
                {
                    CLog::Log(LOGWARNING, "ActiveAE DSP - %s - failed to create add-on %s, status = %d", __FUNCTION__, dspAddon->Name().c_str(), status);
                    if (!addon.get() || !addon->DllLoaded() || status == ADDON_STATUS_PERMANENT_FAILURE)
                    {
                        /* failed to load the dll of this add-on, disable it */
                        CLog::Log(LOGWARNING, "ActiveAE DSP - %s - failed to load the dll for add-on %s, disabling it", __FUNCTION__, dspAddon->Name().c_str());
                        disableAddons.push_back(dspAddon);
                        bDisabled = true;
                    }
                }
            }

            if (bDisabled && IsActivated())
                CGUIDialogOK::ShowAndGetInput(24070, 24071, 16029, 0);
        }
    }

    /* disable add-ons that failed to initialise */
    if (disableAddons.size() > 0)
    {
        CSingleLock lock(m_critUpdateSection);
        for (VECADDONS::iterator itr = disableAddons.begin(); itr != disableAddons.end(); ++itr)
        {
            /* disable in the add-on db */
            CAddonMgr::GetInstance().DisableAddon((*itr)->ID());

            /* remove from the audio dsp add-on list */
            VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), *itr);
            if (addonPtr != m_addons.end())
                m_addons.erase(addonPtr);
        }
    }

    return bReturn;
}
Пример #9
0
bool CPVRClients::UpdateAndInitialiseClients(bool bInitialiseAllClients /* = false */)
{
  bool bReturn(true);
  ADDON::VECADDONS map;
  ADDON::VECADDONS disableAddons;
  {
    CSingleLock lock(m_critSection);
    map = m_addons;
  }

  if (map.size() == 0)
    return false;

  for (unsigned iClientPtr = 0; iClientPtr < map.size(); iClientPtr++)
  {
    const AddonPtr clientAddon = map.at(iClientPtr);
    bool bEnabled = clientAddon->Enabled() &&
        !m_addonDb.IsAddonDisabled(clientAddon->ID());

    if (!bEnabled && IsKnownClient(clientAddon))
    {
      CSingleLock lock(m_critSection);
      /* stop the client and remove it from the db */
      StopClient(clientAddon, false);
      ADDON::VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), clientAddon);
      if (addonPtr != m_addons.end())
        m_addons.erase(addonPtr);

    }
    else if (bEnabled && (bInitialiseAllClients || !IsKnownClient(clientAddon) || !IsConnectedClient(clientAddon)))
    {
      bool bDisabled(false);

      // register the add-on in the pvr db, and create the CPVRClient instance
      int iClientId = RegisterClient(clientAddon);
      if (iClientId < 0)
      {
        // failed to register or create the add-on, disable it
        CLog::Log(LOGWARNING, "%s - failed to register add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str());
        disableAddons.push_back(clientAddon);
        bDisabled = true;
      }
      else
      {
        PVR_CLIENT addon;
        if (!GetClient(iClientId, addon))
        {
          CLog::Log(LOGWARNING, "%s - failed to find add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str());
          disableAddons.push_back(clientAddon);
          bDisabled = true;
        }
        // re-check the enabled status. newly installed clients get disabled when they're added to the db
        else if (addon->Enabled() && !addon->Create(iClientId))
        {
          CLog::Log(LOGWARNING, "%s - failed to create add-on %s", __FUNCTION__, clientAddon->Name().c_str());
          if (!addon.get() || !addon->DllLoaded())
          {
            // failed to load the dll of this add-on, disable it
            CLog::Log(LOGWARNING, "%s - failed to load the dll for add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str());
            disableAddons.push_back(clientAddon);
            bDisabled = true;
          }
        }
      }

      if (bDisabled && (g_PVRManager.GetState() == ManagerStateStarted || g_PVRManager.GetState() == ManagerStateStarting))
        CGUIDialogOK::ShowAndGetInput(24070, 24071, 16029, 0);
    }
  }

  // disable add-ons that failed to initialise
  if (disableAddons.size() > 0)
  {
    CSingleLock lock(m_critSection);
    for (ADDON::VECADDONS::iterator it = disableAddons.begin(); it != disableAddons.end(); it++)
    {
      // disable in the add-on db
      m_addonDb.DisableAddon((*it)->ID(), true);

      // remove from the pvr add-on list
      ADDON::VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), *it);
      if (addonPtr != m_addons.end())
        m_addons.erase(addonPtr);
    }
  }

  return bReturn;
}