static void loadModulesConfig (boost::property_tree::ptree &config, const boost::filesystem::path &configFilePath, std::string modulesConfigPath) { std::list <std::string> locations; if (modulesConfigPath.empty() ) { boost::filesystem::path modulesConfigDir = configFilePath.parent_path() / "modules"; modulesConfigPath = modulesConfigDir.string(); } locations = split (modulesConfigPath, ':'); for (std::string location : locations) { boost::filesystem::path dir (location); dir.normalize(); loadModulesConfigFromDir (config, dir, dir); } }
static void loadModulesConfigFromDir (boost::property_tree::ptree &config, const boost::filesystem::path &dir, const boost::filesystem::path &parentDir) { GST_INFO ("Looking for config files in %s", dir.string().c_str() ); if (!boost::filesystem::is_directory (dir) ) { GST_WARNING ("Unable to load config files from: %s, it is not a directory", dir.string().c_str() ); return; } boost::filesystem::directory_iterator end_itr; for ( boost::filesystem::directory_iterator itr ( dir ); itr != end_itr; ++itr ) { if (boost::filesystem::is_regular (*itr) ) { try { boost::property_tree::ptree moduleConfig; std::string fileName = loadFile (moduleConfig, itr->path() ); std::string key = diffPathToKey (itr->path().parent_path(), parentDir); boost::property_tree::ptree loadedConfig; key = key.empty() ? "modules" : "modules." + key; key += "." + fileName; loadedConfig.put_child (key, moduleConfig); mergePropertyTrees (config, loadedConfig); GST_INFO ("Loaded module config from: %s", itr->path().string().c_str() ); } catch (ParseException &e) { GST_ERROR ("Error reading configuration: %s", e.what()); std::cerr << "Error reading configuration: " << e.what() << std::endl; } } else if (boost::filesystem::is_directory (*itr) ) { loadModulesConfigFromDir (config, itr->path(), parentDir); } } }