コード例 #1
0
ファイル: PVRClients.cpp プロジェクト: Zweikeks/xbmc
int CPVRClients::RegisterClient(AddonPtr client)
{
  int iClientId(-1);
  CAddonDatabase database;
  PVR_CLIENT addon;

  if (CAddonMgr::GetInstance().IsAddonDisabled(client->ID()) || !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;
}
コード例 #2
0
ファイル: PVRDatabase.cpp プロジェクト: FoodDelivery/xbmc
void CPVRDatabase::UpdateTables(int iVersion)
{
  if (iVersion < 13)
    m_pDS->exec("ALTER TABLE channels ADD idEpg integer;");

  if (iVersion < 20)
    m_pDS->exec("ALTER TABLE channels ADD bIsUserSetIcon bool");

  if (iVersion < 21)
    m_pDS->exec("ALTER TABLE channelgroups ADD iGroupType integer");

  if (iVersion < 22)
    m_pDS->exec("ALTER TABLE channels ADD bIsLocked bool");

  if (iVersion < 23)
    m_pDS->exec("ALTER TABLE channelgroups ADD iLastWatched integer");

  if (iVersion < 24)
    m_pDS->exec("ALTER TABLE channels ADD bIsUserSetName bool");

  if (iVersion < 25)
    m_pDS->exec("DROP TABLE IF EXISTS channelsettings");

  if (iVersion < 26)
  {
    m_pDS->exec("ALTER TABLE channels ADD iClientSubChannelNumber integer");
    m_pDS->exec("UPDATE channels SET iClientSubChannelNumber = 0");
    m_pDS->exec("ALTER TABLE map_channelgroups_channels ADD iSubChannelNumber integer");
    m_pDS->exec("UPDATE map_channelgroups_channels SET iSubChannelNumber = 0");
  }

  if (iVersion < 27)
    m_pDS->exec("ALTER TABLE channelgroups ADD bIsHidden bool");

  if (iVersion < 28)
  {
    VECADDONS addons;
    CAddonDatabase database;
    if (database.Open() && CAddonMgr::Get().GetAddons(ADDON_PVRDLL, addons, true))
    {
      /** find all old client IDs */
      std::string strQuery(PrepareSQL("SELECT idClient, sUid FROM clients"));
      m_pDS->query(strQuery);
      while (!m_pDS->eof() && !addons.empty())
      {
        /** try to find an add-on that matches the sUid */
        for (VECADDONS::iterator it = addons.begin(); it != addons.end(); ++it)
        {
          if ((*it)->ID() == m_pDS->fv(1).get_asString())
          {
            /** try to get the current ID from the database */
            int iAddonId = database.GetAddonId(*it);
            /** register a new id if it didn't exist */
            if (iAddonId <= 0)
              iAddonId = database.AddAddon(*it, 0);
            if (iAddonId > 0)
            {
              // this fails when an id becomes the id of one that's being replaced next iteration
              // but since almost everyone only has 1 add-on enabled...
              /** update the iClientId in the channels table */
              strQuery = PrepareSQL("UPDATE channels SET iClientId = %u WHERE iClientId = %u", iAddonId, m_pDS->fv(0).get_asInt());
              m_pDS->exec(strQuery);

              /** no need to check this add-on again */
              it = addons.erase(it);
              break;
            }
          }
        }
        m_pDS->next();
      }
    }
    m_pDS->exec("DROP TABLE clients");
  }

  if (iVersion < 29)
    m_pDS->exec("ALTER TABLE channelgroups ADD iPosition integer");
}