20 #include <mach-o/dyld.h> 29 LOGGER( slog,
"configurator" );
32 f_exe_name(
"unknown" ),
35 f_version_flag( false ),
36 f_param_buffer( NULL ),
39 parser t_parser( an_argc, an_argv );
44 if ( a_default != NULL )
53 string t_name_logger(
"logger" );
54 string t_name_exe(
"executable" );
55 string t_name_config(
"config" );
56 string t_name_json(
"json" );
58 if( t_parser.
has( t_name_logger ) )
62 slog.SetGlobalLevel( (
logger::ELevel)t_parser[t_name_logger][
"verbosity"]().get< unsigned >() );
64 catch( std::exception& e ) {}
70 char t_exe_buf[ 2048 ];
71 uint32_t t_bufsize =
sizeof( t_exe_buf );
72 if( _NSGetExecutablePath( t_exe_buf, &t_bufsize ) != 0 )
74 const size_t t_bufsize = 2048;
75 char t_exe_buf[ t_bufsize ];
76 if( readlink(
"/proc/self/exe", t_exe_buf, t_bufsize ) < 0 )
79 LWARN( slog,
"Could not retrieve executable file name" );
81 LWARN( slog,
"Executable name buffer is too small; needs size %u\n" << t_bufsize );
87 if( t_parser.
has( t_name_config ) )
90 if( ! t_config_filename.empty() )
93 param* t_config_from_file = t_translator.
read_file( t_config_filename.native() );
94 if( t_config_from_file == NULL )
96 throw error() <<
"[configurator] error parsing config file";
98 if( ! t_config_from_file->
is_node() )
100 throw error() <<
"[configurator] configuration file must consist of an object/node";
103 delete t_config_from_file;
111 #ifdef USE_CODEC_JSON 113 if( t_parser.
has( t_name_json ) )
115 string t_config_json = t_parser.
get_value( t_name_json );
116 if( ! t_config_json.empty() )
120 if( ! t_config_from_json->
is_node() )
122 throw error() <<
"[configurator] command line json must be an object";
125 delete t_config_from_json;
135 t_parser.
erase( t_name_exe );
136 t_parser.
erase( t_name_config );
137 t_parser.
erase( t_name_json );
virtual bool is_node() const
void merge(const param_node &a_object)
void erase(const std::string &a_name)
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
scarab::param_node * f_master_config
configurator(int an_argc, char **an_argv, scarab::param_node *a_default=NULL)
LOGGER(mtlog,"authentication")
param * read_file(const std::string &a_filename, const param_node *a_options=nullptr)