void core::executor::load_config() { std::string install_lock = m_working_directory + "/install.lock"; std::string config_file = m_working_directory + "/config.json"; std::string schema_file = m_working_directory + "/schema.sql"; std::string data_directory = m_working_directory + "/data"; std::string js_directory = m_working_directory + "/js"; assure_exists(m_working_directory,"Working path directory"); assure_exists(config_file,"Config file"); assure_exists(schema_file,"Schema template file"); assure_exists(data_directory,"Data directory"); assure_exists(js_directory,"Javascript directory"); std::ifstream config_file_stream(config_file.c_str()); int no = 0; if (!m_config.load(config_file_stream,true,&no)) { throw std::runtime_error("Error in config file `" + config_file + "' at line " + util::string::to_string(no)); } config_file_stream.close(); m_config.set<std::string>("cms.working_directory",m_working_directory); m_config.set<std::string>("cms.install_lock",install_lock); m_config.set<std::string>("cms.schema_file",schema_file); m_config.set<std::string>("cms.data_directory",data_directory); m_config.set<std::string>("cms.js_directory",js_directory); }
/* Entry point */ int main(int argc, char** argv) { /* * Initialize Logging */ google::InitGoogleLogging(""); /* * Environment Wrangling */ const char *home = std::getenv("HOME"); boost::program_options::variables_map vm; std::string name = ""; boost::filesystem::path config_file; /* * Define argument parsing description for program_options */ /* * Parse arguments from command line and configuration file */ boost::program_options::options_description rr( "World Router" ); boost::program_options::options_description glb ( "Global Options " ); boost::program_options::options_description all ( "World Router Options" ); boost::program_options::options_description named ("Named Options"); rr.add_options() ( "help,h", "Display help message" ) ( "name,n", boost::program_options::value<std::string>(),"Name of Router. \nDefault: Required") ( "config,c", boost::program_options::value<std::string>(), "Config File: \nDefault: Required") ( "primary,p", boost::program_options::value<std::string>()->implicit_value("true"), "Primary Broker. \nDefault: false") ; glb.add_options() ( "global.broker", boost::program_options::value<std::string>(), "" ) ; /* * Create groups */ all.add(rr); all.add(glb); /* * Create WorldRouter Object * */ WorldRouter router; try { /* * Checked Argument Wrangling */ boost::program_options::store( boost::program_options::parse_command_line(argc, argv, all), vm ); boost::program_options::notify(vm); /* * Special cases */ if ( vm.count("help") ) { std::cout << rr << std::endl; return 1; } /* * Name / Id must * Might attempt to register with msg broker a named * queue */ if ( vm.count("name") ) name = vm["name"].as<std::string>(); if ( vm.count("config") ) config_file = vm["config"].as<std::string>(); if ( name.empty() || name == "" ) throw std::runtime_error("router name is required, specify with --name"); if ( ! boost::filesystem::exists(config_file)) throw std::runtime_error("config file [" + config_file.string() + "] does not exist"); /* * Parse the config file */ std::ifstream config_file_stream(config_file.string()); /* * Because We want to be able to different sections based on name */ named.add_options() ( (name+".master.q,i").c_str(), boost::program_options::value<std::string>(), "In Queue. \nDefault: master.q") ( (name+".internal.wrq,i").c_str(), boost::program_options::value<std::string>(), "In Queue. \nDefault: internal.wrq") ; all.add(named); /* * And we want the named to only be available via the config file */ boost::program_options::store( boost::program_options::parse_config_file(config_file_stream, all, true), vm ); boost::program_options::notify(vm); /* * Register Configuration */ router.registerConfig(vm); /* * Create session * 1) establish connection to broker * 2) create session * 3) create queue if primary ( reciever ) * if primary, queue must not be present * if NOT primary, queue MUST be present * */ router.establishSession(); router.run(); } catch(const std::exception& error) { std::cerr << "Exception: " << error.what() << std::endl; google::FlushLogFiles(google::INFO); } LOG(INFO) << "All Done!"; google::FlushLogFiles(google::INFO); return 0; }