* Parses the command line arguments and does the needed actions.
* @param argc Command line argument number given to main.
* @param argv[] Pointer to command line argument array given to main.
- * @return 0 if all is fine, 1 if not.
+ * @return 0 if all is fine, -1 if not.
*/
int Config::parse_cmd_line(int argc, char *argv[])
{
if ( VariablesMap.count("help") )
{
Log->print_usage(OptDescCmd);
- return 1;
+ return -1;
}
else if ( VariablesMap.count("version") )
{
Log->print_version();
- return 1;
+ return -1;
}
// Create a service object if all needed options are set on the command line
if ( service )
Services.push_back(service);
else
- return 1;
+ return -1;
}
else if ( VariablesMap.count("protocol") || VariablesMap.count("host") || VariablesMap.count("login") || VariablesMap.count("password") )
{
Log->print_missing_cmd_service_option();
Log->print_usage(OptDescCmd);
- return 1;
+ return -1;
}
if ( VariablesMap.count("config") )
{
// Config path doesn't exist or is not a directory
Log->print_error_config_path(ConfigPath);
- return 1;
+ return -1;
}
}
{
Log->print_unknown_cmd_option(e.what());
Log->print_usage(OptDescCmd);
- return 1;
+ return -1;
}
return 0;
}
/**
* Loads a service config file, invoked by load_config_from_files.
* @param full_filename Filename of the service config file to load.
- * @return 0 if all is fine, 3 if an unknown option was detected, 4 if the service file could not be opened for reading.
+ * @return 0 if all is fine, -1 otherwise.
*/
int Config::load_service_config_file(const string& full_filename)
{
// unknown option in config file detected
service_config_file.close();
Log->print_unknown_service_conf_option(e.what());
- return 1;
+ return -1;
}
service_config_file.close();
}
{
// error opening service config file for reading
Log->print_error_opening_r(full_filename);
- return 1;
+ return -1;
}
return 0;
}
/**
* Loads the main config file, invoked by load_config_from_files
* @param full_filename The full filename of the main config file to load
- * @return 0 if all is fine. 3 if unknown option was detected, 4 if main config file could not be opened for reading
+ * @return 0 if all is fine, -1 otherwise
*/
int Config::load_main_config_file(const string& full_filename)
{
// unknown option in main config file detected
main_config_file.close();
Log->print_unknown_main_conf_option(e.what());
- return 1;
+ return -1;
}
main_config_file.close();
}
{
// error opening main config file for reading
Log->print_error_opening_r(full_filename);
- return 1;
+ return -1;
}
return 0;
}
/**
* Loads the main and the service config file and does the needed action.
* @param config_path The path to the config directory.
- * @return 0 if all is fine.
+ * @return 0 if all is fine, -1 otherwise
*/
int Config::load_config_from_files()
{
// Load the main config file
string full_filename = dir_itr->path().string();
if ( load_main_config_file(full_filename) != 0 )
- return 1;
+ return -1;
}
// If it is a service definition file *.conf, parse it and generate the corresponding service
else if ( boost::regex_search( actual_file,expr ) )
{
string full_filename = dir_itr->path().string();
if ( load_service_config_file(full_filename) != 0 )
- return 1;
+ return -1;
}
}
}