void CSettingsManager::SetInitialized() { CExclusiveLock lock(m_settingsCritical); if (m_initialized) return; m_initialized = true; for (SettingMap::iterator setting = m_settings.begin(); setting != m_settings.end(); ) { SettingMap::iterator tmpIterator = setting++; if (tmpIterator->second.setting == NULL) m_settings.erase(tmpIterator); } // figure out all the dependencies between settings for (SettingMap::iterator itSettingDep = m_settings.begin(); itSettingDep != m_settings.end(); ++itSettingDep) { if (itSettingDep->second.setting == NULL) continue; // if the setting has a parent setting, add it to its children std::string parentSettingId = itSettingDep->second.setting->GetParent(); if (!parentSettingId.empty()) { SettingMap::iterator itParentSetting = m_settings.find(parentSettingId); if (itParentSetting != m_settings.end()) itParentSetting->second.children.insert(itSettingDep->first); } // handle all dependencies of the setting 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); } } } }
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; }