コード例 #1
0
ファイル: SettingsManager.cpp プロジェクト: 7orlum/xbmc
bool CSettingsManager::Initialize(const TiXmlElement *root)
{
  CExclusiveLock lock(m_critical);
  CExclusiveLock settingsLock(m_settingsCritical);
  if (m_initialized || root == NULL)
    return false;

  if (!StringUtils::EqualsNoCase(root->ValueStr(), SETTING_XML_ROOT))
  {
    CLog::Log(LOGERROR, "CSettingsManager: error reading settings definition: doesn't contain <settings> tag");
    return false;
  }

  const TiXmlNode *sectionNode = root->FirstChild(SETTING_XML_ELM_SECTION);
  while (sectionNode != NULL)
  {
    std::string sectionId;
    if (CSettingSection::DeserializeIdentification(sectionNode, sectionId))
    {
      CSettingSection *section = NULL;
      SettingSectionMap::iterator itSection = m_sections.find(sectionId);
      bool update = (itSection != m_sections.end());
      if (!update)
        section = new CSettingSection(sectionId, this);
      else
        section = itSection->second;

      if (section->Deserialize(sectionNode, update))
        AddSection(section);
      else
      {
        CLog::Log(LOGWARNING, "CSettingsManager: unable to read section \"%s\"", sectionId.c_str());
        if (!update)
          delete section;
      }
    }
      
    sectionNode = sectionNode->NextSibling(SETTING_XML_ELM_SECTION);
  }

  return true;
}
コード例 #2
0
bool CSettingManager::Initialize(const XMLElement *root)
{
	XR::CSingleLock lock(m_critical);
	XR::CSingleLock lock2(m_settingsCritical);
	if (m_initialized || root == NULL)
		return false;

	if (!StringUtils::EqualsNoCase(root->Value(), "settings"))
	{
		LOGERR("CSettingsManager: error reading settings definition: doesn't contain <settings> tag");
		return false;
	}

	const XMLElement *sectionNode = root->FirstChildElement("section");
	while (sectionNode != nullptr) {
		std::string settingId;
		if (CSetting::DeserializeIdentification(sectionNode, settingId)) {
			CSettingSection* section = nullptr;
			SectionMap::iterator itSection = m_sections.find(settingId);
			bool update = (itSection != m_sections.end());
			if (!update)
				section = new CSettingSection(settingId, this);
			else
				section = itSection->second;

			if (section->Deserialize(sectionNode, update))
				AddSection(section);
			else {
				LOGWARN("CSettingsManager: unable to read section \"%s\"", settingId.c_str());
				if (!update)
					delete section;
			}
		}
		sectionNode = sectionNode->NextSiblingElement("section");
	}

	m_initialized = true;
	return true;
}
コード例 #3
0
ファイル: SettingsManager.cpp プロジェクト: Anankin/xbmc
bool CSettingsManager::Initialize(const TiXmlElement *root)
{
  CExclusiveLock lock(m_critical);
  CExclusiveLock settingsLock(m_settingsCritical);
  if (m_initialized || root == NULL)
    return false;

  if (!StringUtils::EqualsNoCase(root->ValueStr(), SETTING_XML_ROOT))
  {
    CLog::Log(LOGERROR, "CSettingsManager: error reading settings definition: doesn't contain <settings> tag");
    return false;
  }

  const TiXmlNode *sectionNode = root->FirstChild(SETTING_XML_ELM_SECTION);
  while (sectionNode != NULL)
  {
    std::string sectionId;
    if (CSettingSection::DeserializeIdentification(sectionNode, sectionId))
    {
      CSettingSection *section = NULL;
      SettingSectionMap::iterator itSection = m_sections.find(sectionId);
      bool update = (itSection != m_sections.end());
      if (!update)
        section = new CSettingSection(sectionId, this);
      else
        section = itSection->second;

      if (section->Deserialize(sectionNode, update))
      {
        section->CheckRequirements();
        if (!update)
          m_sections[section->GetId()] = section;

        // get all settings and add them to the settings map
        for (SettingCategoryList::const_iterator categoryIt = section->GetCategories().begin(); categoryIt != section->GetCategories().end(); ++categoryIt)
        {
          (*categoryIt)->CheckRequirements();
          for (SettingGroupList::const_iterator groupIt = (*categoryIt)->GetGroups().begin(); groupIt != (*categoryIt)->GetGroups().end(); ++groupIt)
          {
            (*groupIt)->CheckRequirements();
            for (SettingList::const_iterator settingIt = (*groupIt)->GetSettings().begin(); settingIt != (*groupIt)->GetSettings().end(); ++settingIt)
            {
              (*settingIt)->CheckRequirements();

              const std::string &settingId = (*settingIt)->GetId();
              SettingMap::iterator setting = m_settings.find(settingId);
              if (setting == m_settings.end())
              {
                Setting tmpSetting = { NULL };
                std::pair<SettingMap::iterator, bool> tmpIt = m_settings.insert(make_pair(settingId, tmpSetting));
                setting = tmpIt.first;
              }
                
              if (setting->second.setting == NULL)
              {
                setting->second.setting = *settingIt;
                (*settingIt)->m_callback = this;
              }
            }
          }
        }
      }
      else
      {
        CLog::Log(LOGWARNING, "CSettingsManager: unable to read section \"%s\"", sectionId.c_str());
        if (!update)
          delete section;
      }
    }
      
    sectionNode = sectionNode->NextSibling(SETTING_XML_ELM_SECTION);
  }

  for (SettingMap::iterator itSettingDep = m_settings.begin(); itSettingDep != m_settings.end(); ++itSettingDep)
  {
    if (itSettingDep->second.setting == NULL)
      continue;

    const SettingDependencies& deps = itSettingDep->second.setting->GetDependencies();
    for (SettingDependencies::const_iterator depIt = deps.begin(); depIt != deps.end(); ++depIt)
    {
      std::set<std::string> settingIds = depIt->GetSettings();
      for (std::set<std::string>::const_iterator itSettingId = settingIds.begin(); itSettingId != settingIds.end(); ++itSettingId)
      {
        SettingMap::iterator setting = m_settings.find(*itSettingId);
        if (setting == m_settings.end())
          continue;

        bool newDep = true;
        SettingDependencies &settingDeps = setting->second.dependencies[itSettingDep->first];
        for (SettingDependencies::const_iterator itDeps = settingDeps.begin(); itDeps != settingDeps.end(); ++itDeps)
        {
          if (itDeps->GetType() == depIt->GetType())
          {
            newDep = false;
            break;
          }
        }

        if (newDep)
          settingDeps.push_back(*depIt);
      }
    }
  }

  return true;
}