8 #define SCARAB_API_EXPORTS 23 #include <mach-o/dyld.h> 34 LOGGER( slog,
"configurator" );
37 f_exe_name(
"unknown" ),
40 f_version_flag( false )
42 parser t_parser( an_argc, an_argv );
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"]().as_uint() );
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 )
78 TCHAR t_exe_buf[MAX_PATH];
79 if( ! GetModuleFileName( NULL, t_exe_buf, MAX_PATH ) )
82 LWARN( slog,
"Could not retrieve executable file name" );
84 LWARN( slog,
"Executable name buffer is too small; needs size %u\n" << t_bufsize );
90 if( t_parser.
has( t_name_config ) )
93 if( ! t_config_filename.empty() )
96 std::unique_ptr< param > t_config_from_file( t_translator.
read_file( t_config_filename.string() ));
97 if( t_config_from_file == NULL )
99 throw error() <<
"[configurator] error parsing config file";
101 if( ! t_config_from_file->is_node() )
103 throw error() <<
"[configurator] configuration file must consist of an object/node";
113 #ifdef USE_CODEC_JSON 115 if( t_parser.
has( t_name_json ) )
117 string t_config_json = t_parser[ t_name_json ]().as_string();
118 if( ! t_config_json.empty() )
121 std::unique_ptr< param > t_config_from_json( t_input_json.
read_string( t_config_json ) );
122 if( ! t_config_from_json->is_node() )
124 throw error() <<
"[configurator] command line json must be an object";
136 t_parser.
erase( t_name_exe );
137 t_parser.
erase( t_name_config );
138 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)
LOGGER(mtlog, "authentication")
Contains the logger class and macros, based on Kasper's KLogger class.
param_ptr_t read_file(const std::string &a_filename, const param_node &a_options=param_node())
bool has(const std::string &a_name) const