12 #include "param_json.hh" 17 #include <mach-o/dyld.h> 26 LOGGER( slog,
"configurator" );
29 f_exe_name(
"unknown" ),
32 f_version_flag( false ),
33 f_param_buffer( NULL ),
36 parser t_parser( an_argc, an_argv );
41 if ( a_default != NULL )
50 string t_name_logger(
"logger" );
51 string t_name_exe(
"executable" );
52 string t_name_config(
"config" );
53 string t_name_json(
"json" );
55 if( t_parser.
has( t_name_logger ) )
58 if( t_log_node !=
nullptr )
60 if( t_log_node->
has(
"verbosity" ) )
63 slog.SetGlobalLevel( t_level );
71 char t_exe_buf[ 2048 ];
72 uint32_t t_bufsize =
sizeof( t_exe_buf );
73 if( _NSGetExecutablePath( t_exe_buf, &t_bufsize ) != 0 )
75 const size_t t_bufsize = 2048;
76 char t_exe_buf[ t_bufsize ];
77 if( readlink(
"/proc/self/exe", t_exe_buf, t_bufsize ) < 0 )
80 LWARN( slog,
"Could not retrieve executable file name" );
82 LWARN( slog,
"Executable name buffer is too small; needs size %u\n" << t_bufsize );
88 if( t_parser.
has( t_name_config ) )
91 if( ! t_config_filename.empty() )
94 param* t_config_from_file = t_translator.
read_file( t_config_filename.native() );
95 if( t_config_from_file == NULL )
97 throw error() <<
"[configurator] error parsing config file";
99 if( ! t_config_from_file->
is_node() )
101 throw error() <<
"[configurator] configuration file must consist of an object/node";
104 delete t_config_from_file;
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() )
118 param_input_json t_input_json;
119 param* t_config_from_json = t_input_json.read_string( t_config_json );
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;
134 t_parser.
erase( t_name_exe );
135 t_parser.
erase( t_name_config );
136 t_parser.
erase( t_name_json );
path SCARAB_API expand_path(const string &a_path)
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
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)