void LocationsMgr::add_location( const std::string& name , const CfgPairs& cfg ) { try { if( cfg.at("type") == "szbase" ) add_szbase( name , cfg ); else if( cfg.at("type") == "proxy" ) add_proxy( name , cfg ); else throw invalid_value("Invalid 'type' in section " + name ); } catch( std::out_of_range& e ) { throw missing_option("Missing option in section " + name ); } }
void LocationsMgr::add_szbase( const std::string& name , const CfgPairs& cfg ) { auto draw_name = cfg.count("draw_name") ? cfg.at("draw_name") : name; try { auto& vars = vars_cache.get_szarp( cfg.at("base") ); loc_factory.register_location<SzbaseLocation>( name , draw_name , "szbase" , std::ref(vars) ); } catch( file_not_found_error& e ) { throw invalid_value( e.what() ); } catch( xml_parse_error& e ) { throw invalid_value( e.what() ); } }
void LocationsMgr::add_proxy( const std::string& name , const CfgPairs& cfg ) { unsigned port; try { port = boost::lexical_cast<unsigned>(cfg.at("port")); } catch( boost::bad_lexical_cast& e ) { throw invalid_value("Invalid port number in section " + name ); } catch( std::out_of_range& e ) { port = 9002; } auto draw_name = cfg.count("draw_name") ? cfg.at("draw_name") : ""; auto updater = std::make_shared <RemotesUpdater>( name , draw_name , cfg.at("address") , port , loc_factory ); updater->connect(); updaters[ name ] = updater; }
void LocationsMgr::add_szbase( const std::string& name , const CfgPairs& cfg ) { auto pa = cfg.count("prober_address") ? cfg.at("prober_address") : "127.0.0.1"; auto pp = cfg.count("prober_port") ? cfg.at("prober_port") : "8090"; auto draw_name = cfg.count("draw_name") ? cfg.at("draw_name") : name; unsigned p; try { p = boost::lexical_cast<unsigned>(pp); } catch( boost::bad_lexical_cast& e ) { throw invalid_value("Invalid port number in section " + name ); } try { auto& vars = vars_cache.get_szarp( cfg.at("base") ); loc_factory.register_location<SzbaseLocation>( name , draw_name , "szbase" , std::ref(vars) ); } catch( file_not_found_error& e ) { throw invalid_value( e.what() ); } catch( xml_parse_error& e ) { throw invalid_value( e.what() ); } }