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 ) )
61 if( t_log_node !=
nullptr )
63 if( t_log_node->
has(
"verbosity" ) )
66 slog.SetGlobalLevel( t_level );
74 char t_exe_buf[ 2048 ];
75 uint32_t t_bufsize =
sizeof( t_exe_buf );
76 if( _NSGetExecutablePath( t_exe_buf, &t_bufsize ) != 0 )
78 const size_t t_bufsize = 2048;
79 char t_exe_buf[ t_bufsize ];
80 if( readlink(
"/proc/self/exe", t_exe_buf, t_bufsize ) < 0 )
83 LWARN( slog,
"Could not retrieve executable file name" );
85 LWARN( slog,
"Executable name buffer is too small; needs size %u\n" << t_bufsize );
91 if( t_parser.
has( t_name_config ) )
94 if( ! t_config_filename.empty() )
97 param* t_config_from_file = t_translator.
read_file( t_config_filename.native() );
98 if( t_config_from_file == NULL )
100 throw error() <<
"[configurator] error parsing config file";
102 if( ! t_config_from_file->
is_node() )
104 throw error() <<
"[configurator] configuration file must consist of an object/node";
107 delete t_config_from_file;
115 #ifdef USE_CODEC_JSON 117 if( t_parser.
has( t_name_json ) )
119 string t_config_json = t_parser.
get_value( t_name_json );
120 if( ! t_config_json.empty() )
124 if( ! t_config_from_json->
is_node() )
126 throw error() <<
"[configurator] command line json must be an object";
129 delete t_config_from_json;
139 t_parser.
erase( t_name_exe );
140 t_parser.
erase( t_name_config );
141 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)
const param_node * node_at(const std::string &a_name) const
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)