Exemplo n.º 1
0
void
configuration_t::load(const std::string& path) {
	boost::mutex::scoped_lock lock(m_mutex);

	m_path = path;
	std::ifstream file(m_path.c_str(), std::ifstream::in);
	
	if (!file.is_open()) {
		throw internal_error("config file: " + m_path + " failed to open.");
	}

	std::string config_data;
	std::string line;
	while (std::getline(file, line)) {
		// strip comments
		boost::trim(line);
		if (line.substr(0, 2) == "//") {
			continue;
		}

		// append to config otherwise
		config_data += line;
	}
	
	file.close();

	Json::Value root;
	Json::Reader reader;
	bool parsing_successful = reader.parse(config_data, root);
		
	if (!parsing_successful) {
		throw internal_error("config file: " + m_path + " could not be parsed.");
	}
	
	try {
		parse_basic_settings(root);
		parse_logger_settings(root);
		parse_services_settings(root);
		parse_persistant_storage_settings(root);

		//parse_statistics_settings(config_value);
	}
	catch (const std::exception& ex) {
		std::string error_msg = "config file: " + m_path + " could not be parsed. details: ";
		error_msg += ex.what();
		throw internal_error(error_msg);
	}
}
Exemplo n.º 2
0
void
configuration::load(const std::string& path) {
	boost::mutex::scoped_lock lock(mutex_);

	path_ = path;

	std::ifstream file(path.c_str(), std::ifstream::in);
	
	if (!file.is_open()) {
		throw internal_error("config file: " + path + " failed to open at: " + std::string(BOOST_CURRENT_FUNCTION));
	}

	std::string config_data;
	std::string line;
	while (std::getline(file, line)) {
		config_data += line;// + "\n";
	}
	
	file.close();

	Json::Value root;
	Json::Reader reader;
	bool parsing_successful = reader.parse(config_data, root);
		
	if (!parsing_successful) {
		throw internal_error("config file: " + path + " could not be parsed at: " + std::string(BOOST_CURRENT_FUNCTION));
	}
	
	// parse config data
	const Json::Value config_value = root["dealer_config"];
	
	try {
		parse_basic_settings(config_value);
		parse_logger_settings(config_value);
		parse_messages_cache_settings(config_value);
		parse_persistant_storage_settings(config_value);
		parse_autodiscovery_settings(config_value);
		parse_statistics_settings(config_value);
		parse_services_settings(config_value);
	}
	catch (const std::exception& ex) {
		std::string error_msg = "config file: " + path + " could not be parsed. details: ";
		error_msg += ex.what();
		error_msg += " at: " + std::string(BOOST_CURRENT_FUNCTION);
		throw internal_error(error_msg);
	}
}