15 #include <boost/foreach.hpp> 16 #include <boost/property_tree/ptree.hpp> 17 #include <boost/property_tree/xml_parser.hpp> 18 #include <boost/filesystem.hpp> 23 using boost::property_tree::ptree;
32 if (groupTree.empty())
37 BOOST_FOREACH(
const ptree::value_type &
child, groupTree)
39 if (child.second.empty())
45 group.Groups.push_back(GetGroup(child.first, child.second));
59 params.
Groups.push_back(GetGroup(name, tree));
68 read_xml(configPath, pt);
70 BOOST_FOREACH(
const ptree::value_type & config, pt)
72 if (config.first !=
"config")
74 std::cerr <<
"Unknown root tag " << config.first <<
" in the config file '" << configPath <<
"'" << std::endl;
78 BOOST_FOREACH(
const ptree::value_type &
param, config.second)
80 if (param.first !=
"modules")
82 AddParameter(configuration.
Parameters, param.first, param.second);
86 BOOST_FOREACH(
const ptree::value_type & module, param.second)
88 if (module.first !=
"module")
90 std::cerr <<
"Unknown tag " << module.first <<
" inside 'modules' in the config file '" << configPath <<
"'" << std::endl;
98 if (boost::optional<const ptree &> dependsOn = module.second.get_child_optional(
"depends_on"))
100 BOOST_FOREACH(
const ptree::value_type & depend, dependsOn.get())
102 if (depend.first !=
"id")
107 moduleConfig.
Dependencies.push_back(depend.second.data());
111 if (boost::optional<const ptree &> parameters = module.second.get_child_optional(
"parameters"))
113 BOOST_FOREACH(
const ptree::value_type & parameter, parameters.get())
115 AddParameter(moduleConfig.
Parameters, parameter.first, parameter.second);
119 configuration.
Modules.push_back(moduleConfig);
123 return configuration;
128 using namespace boost::filesystem;
131 directory_iterator dirIt(p);
132 directory_iterator
end;
134 std::for_each(dirIt, end, [&configuration](
const directory_entry & entry)
136 if (entry.path().filename().extension() ==
".conf")
138 std::cout <<
"Parsing config file: " << entry.path().native() << std::endl;
145 return configuration;
151 void AddDependencies(ptree & moduleTree,
const std::vector<Common::AddonId> & ids)
158 ptree & deps = moduleTree.add(
"depends_on",
"");
160 for (
auto idIt = ids.begin(); idIt != ids.end(); ++idIt)
162 deps.add(
"id", *idIt);
168 ptree & groupTree = moduleTree.add(group.
Name,
"");
172 groupTree.add(paramIt->Name, paramIt->Value);
175 for (
auto groupIt = group.
Groups.begin(); groupIt != group.
Groups.end(); ++groupIt)
177 AddGroup(groupTree, *groupIt);
188 ptree & paramsTree = moduleTree.add(groupName,
"");
192 paramsTree.add(paramIt->Name, paramIt->Value);
195 for (
auto groupIt = params.
Groups.begin(); groupIt != params.
Groups.end(); ++groupIt)
197 AddGroup(paramsTree, *groupIt);
205 ptree & modulesPt = pt.put(
"config.modules",
"");
207 for (
auto configIt = modules.begin(); configIt != modules.end(); ++configIt)
209 ptree & moduleTree = modulesPt.add(
"module",
"");
211 moduleTree.add(
"id", config.
Id);
212 moduleTree.add(
"path", config.
Path);
214 AddParameters(moduleTree, config.
Parameters,
"parameters");
217 write_xml(configPath, pt);
Configuration ParseConfigurationFiles(const std::string &directory)
Configuration ParseConfiguration(const std::string &configPath)
void SaveConfiguration(const ModulesConfiguration &configuration, const std::string &configPath)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
std::vector< AddonId > Dependencies
Common::AddonInformation GetAddonInfomation(const ModuleConfiguration &config)
std::vector< Parameter > Parameters
std::vector< ParametersGroup > Groups
Common::AddonParameters Parameters
AddonFactory::UniquePtr CreateDynamicAddonFactory(const char *modulePath)
std::vector< ParametersGroup > Groups
AddonParameters Parameters
std::vector< Common::ModuleConfiguration > ModulesConfiguration
std::vector< ModuleConfiguration > Modules
std::vector< Parameter > Parameters