25 #include <boost/property_tree/json_parser.hpp>
28 namespace configuration {
36 using boost::property_tree::ptree;
38 namespace po = boost::program_options;
39 namespace pt = boost::property_tree;
56 tmp =
instance_.load(boost::memory_order_consume);
60 instance_.store(tmp, boost::memory_order_release);
69 : program_options(
"Allowed options")
76 LOG(
LDEBUG)<<
"Properties loaded from config file (raw):";
77 for (ptree::const_iterator it = pt_.begin(); it != pt_.end(); ++it) {
78 LOG(
LDEBUG) <<it->first <<
": " << it->second.get_value<std::string>() << std::endl;
88 if (it->first == node_name_) {
89 LOG(
LINFO)<<
"Node \"" << node_name_ <<
"\" has been found in config file";
95 LOG(
LWARNING)<<
"Node " << node_name_ <<
" not found in config file";
96 return empty_ptree<ptree>();
102 std::string tmp = std::string(argv[0]);
108 std::string existing_config_name;
118 (
"help,h",
"Display (h)elp message")
119 (
"load-config,l", po::value<std::string>(&existing_config_name)->default_value(default_config_name.c_str()),
"(L)oad configuration from given JSON file")
120 (
"create-config,c",
"(C)reate default configuration JSON file")
121 (
"set-logger-level,s", po::value<int>(&log_lvl)->default_value(3),
"(S)et logger severity level")
125 po::variables_map vm;
132 catch (
const po::error & u) {
133 std::cout << u.what() <<
"\n";
138 if (vm.count(
"help")) {
146 if (vm.count(
"create-config")) {
147 std::cout <<
"Creating JSON file " << new_config_name <<
" with default configuration \n";
149 std::ofstream cfg(new_config_name.c_str());
152 " \"app_state\": {\n"
153 " \"application_sleep_interval\": \"1000\"\n"
156 cfg << std::string(argv[0]).erase(0,2);
158 " \"learning_iterations_to_test_ratio\": \"50\",\n"
159 " \"number_of_averaged_test_measures\": \"5\"\n"
172 LOG(
LSTATUS) <<
"Configuration file \"" << existing_config_name +
"\" was loaded properly";
176 catch(boost::property_tree::json_parser_error&) {
177 LOG(
LERROR) <<
"Configuration file \"" << existing_config_name +
"\" was not found or invalid";
179 LOG(
LINFO) <<
" specify config file name with -l switch";
180 LOG(
LINFO) <<
" create default configuration using -c switch";
198 for (boost::property_tree::ptree::const_iterator cfg_it =
config_tree.begin(); cfg_it !=
config_tree.end(); ++cfg_it) {
203 reg_it->second->loadPropertiesFromConfigNode(cfg_it->second);
205 LOG(
LERROR) <<
"Object \"" << cfg_it->first <<
"\" appearing in the loaded config file was not found in the property tree registry";
210 LOG(
LINFO) <<
"Configuration completed";
211 LOG(
LSTATUS) <<
"List of application properties:";
215 reg_it->second->printPropertiesWithValues();
218 LOG(
LINFO) <<
"Property-dependent variables initialized";
222 LOG(
LSTATUS) <<
"Initializing property-dependent variables";
228 reg_it->second->initializePropertyDependentVariables();
232 LOG(
LINFO) <<
"Property-dependent variables initialized";
static ParameterServer * getInstance()
void parseApplicationParameters(int argc, char *argv[])
Severity_t
Message severity level.
Parent class for all classes possessing properties. Contains methods useful for their management...
void loadPropertiesFromConfiguration()
Contains declaration of parameter server singleton along with some auxiliary typedefs.
const Ptree & empty_ptree()
std::string application_name
Name of the executed binary file.
const boost::property_tree::ptree & returnNode(std::string node_name_)
void print(boost::property_tree::ptree const &pt)
std::string getNodeName() const
Server of application parameters - defined in the form of a singleton, with double-checked locking pa...
std::map< std::string, mic::configuration::PropertyTree * >::iterator id_pt_it_t
Type used during iterating/searching for property trees in registry.
static boost::atomic< ParameterServer * > instance_
boost::program_options::options_description program_options
boost::program_options::variables_map program_arguments
void initializePropertyDependentVariables()
boost::property_tree::ptree config_tree
boost::program_options::options_description & getProgramOptions()
void registerPropertyTree(mic::configuration::PropertyTree *pt_)
#define LOG(level)
Macro for message printing.
static boost::mutex instantiation_mutex
std::map< std::string, mic::configuration::PropertyTree * > property_trees_registry
#define LOGGER
Macro returning logger instance.
const boost::program_options::variables_map & getProgramArguments()