Generalized return values. 0 indicates success, -1 failure.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 10 Aug 2009 14:40:06 +0000 (16:40 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 10 Aug 2009 14:40:06 +0000 (16:40 +0200)
src/config.cpp

index b5f60a5..205cac0 100644 (file)
@@ -229,7 +229,7 @@ int Config::deserialize_services()
  * 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[])
 {
@@ -241,12 +241,12 @@ 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
@@ -264,13 +264,13 @@ int Config::parse_cmd_line(int argc, char *argv[])
             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") )
@@ -281,7 +281,7 @@ int Config::parse_cmd_line(int argc, char *argv[])
             {
                 // Config path doesn't exist or is not a directory
                 Log->print_error_config_path(ConfigPath);
-                return 1;
+                return -1;
             }
         }
 
@@ -296,7 +296,7 @@ int Config::parse_cmd_line(int argc, char *argv[])
     {
         Log->print_unknown_cmd_option(e.what());
         Log->print_usage(OptDescCmd);
-        return 1;
+        return -1;
     }
     return 0;
 }
@@ -334,7 +334,7 @@ Service::Ptr Config::create_service(const string &protocol,const string &hostnam
 /**
  * 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)
 {
@@ -374,7 +374,7 @@ 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();
     }
@@ -382,7 +382,7 @@ int Config::load_service_config_file(const string& full_filename)
     {
         // error opening service config file for reading
         Log->print_error_opening_r(full_filename);
-        return 1;
+        return -1;
     }
     return 0;
 }
@@ -391,7 +391,7 @@ int Config::load_service_config_file(const string& full_filename)
 /**
  * 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)
 {
@@ -418,7 +418,7 @@ 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();
     }
@@ -426,7 +426,7 @@ int Config::load_main_config_file(const string& full_filename)
     {
         // error opening main config file for reading
         Log->print_error_opening_r(full_filename);
-        return 1;
+        return -1;
     }
     return 0;
 }
@@ -435,7 +435,7 @@ int Config::load_main_config_file(const string& full_filename)
 /**
  * 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()
 {
@@ -454,14 +454,14 @@ 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;
             }
         }
     }