21 #include <mach-o/dyld.h> 30 LOGGER( slog,
"configurator" );
33 f_exe_name(
"unknown" ),
36 f_version_flag( false )
38 parser t_parser( an_argc, an_argv );
49 string t_name_logger(
"logger" );
50 string t_name_exe(
"executable" );
51 string t_name_config(
"config" );
52 string t_name_json(
"json" );
54 if( t_parser.
has( t_name_logger ) )
58 slog.SetGlobalLevel( (
logger::ELevel)t_parser[t_name_logger][
"verbosity"]().get< unsigned >() );
60 catch( std::exception& e ) {}
66 char t_exe_buf[ 2048 ];
67 uint32_t t_bufsize =
sizeof( t_exe_buf );
68 if( _NSGetExecutablePath( t_exe_buf, &t_bufsize ) != 0 )
70 const size_t t_bufsize = 2048;
71 char t_exe_buf[ t_bufsize ];
72 if( readlink(
"/proc/self/exe", t_exe_buf, t_bufsize ) < 0 )
75 LWARN( slog,
"Could not retrieve executable file name" );
77 LWARN( slog,
"Executable name buffer is too small; needs size %u\n" << t_bufsize );
83 if( t_parser.
has( t_name_config ) )
86 if( ! t_config_filename.empty() )
89 std::unique_ptr< param > t_config_from_file( t_translator.
read_file( t_config_filename.native() ));
90 if( t_config_from_file == NULL )
92 throw error() <<
"[configurator] error parsing config file";
94 if( ! t_config_from_file->is_node() )
96 throw error() <<
"[configurator] configuration file must consist of an object/node";
106 #ifdef USE_CODEC_JSON 108 if( t_parser.
has( t_name_json ) )
110 string t_config_json = t_parser.
get_value( t_name_json );
111 if( ! t_config_json.empty() )
114 std::unique_ptr< param > t_config_from_json( t_input_json.
read_string( t_config_json ) );
115 if( ! t_config_from_json->is_node() )
117 throw error() <<
"[configurator] command line json must be an object";
129 t_parser.
erase( t_name_exe );
130 t_parser.
erase( t_name_config );
131 t_parser.
erase( t_name_json );
void merge(const param_node &a_object)
configurator(int an_argc, char **an_argv, const scarab::param_node &a_default=scarab::param_node())
void erase(const std::string &a_name)
scarab::param_node f_master_config
path expand_path(const string &a_path)
Contains the logger class and macros, based on Kasper's KLogger class.
std::string get_value(const std::string &a_name) const
bool has(const std::string &a_name) const
param_ptr_t read_file(const std::string &a_filename, const param_node &a_options=param_node())
LOGGER(mtlog,"authentication")