Moved some logic out of main into updater.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Wed, 29 Jul 2009 16:10:42 +0000 (18:10 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Wed, 29 Jul 2009 16:10:42 +0000 (18:10 +0200)
src/config.cpp
src/config.h
src/main.cpp
src/updater.cpp
src/updater.h

index bcb99a9..cd33509 100644 (file)
@@ -319,3 +319,26 @@ void Config::print_version(const string& version)
 {
     cout << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << version << endl;
 }
+
+/**
+ * Prints out the successful parsing of the command line options.
+ */
+void Config::print_cmd_parsed()
+{
+    cout << "Command line arguments successful parsed." << endl;
+}
+
+void Config::print_conf_loaded()
+{
+    cout << "Config files successful loaded." << endl;
+}
+
+void Config::print_unknown_conf_option()
+{
+    cout << "See manpage for config file structure." << endl;
+}
+
+void Config::print_error_opening()
+{
+    cout << "Error opening file." << endl;
+}
\ No newline at end of file
index 456fe4d..bc12eb7 100644 (file)
@@ -62,6 +62,14 @@ public:
 
     void print_version(const string&);
 
+    void print_cmd_parsed();
+
+    void print_conf_loaded();
+
+    void print_error_opening();
+
+    void print_unknown_conf_option();
+
     list<ServicePtr> get_services();
 };
 
index b60e073..fbab021 100644 (file)
@@ -42,41 +42,18 @@ typedef boost::shared_ptr<Updater> UpdaterPtr;
  */
 int main(int argc, char *argv[])
 {
-    // Initialize Config class and get the command line parameters
+    // initialize Config
     ConfigPtr config(new Config);
-    int ret_val = config->parse_cmd_line(argc,argv);
-    if(ret_val == 1)
-    {
-        // usage
-        config->print_usage();
-        return 0;
-    }
-    else if(ret_val == 2)
-    {
-        // version
-        ostringstream version_string;
-        version_string << VERSION << "." << REVISION << "." << RELEASE;
-        config->print_version(version_string.str());
-        return 0;
-    }
 
-    // Load the main config and the service files
-    string config_path = "/home/bjoern/bpdyndnsd";  // TODO: standard config path should be /etc/bpdyndnsd if not specified other on command line
-    ret_val = config->load_config_from_files(config_path);
-    if(ret_val == 3)
-    {
-        // unknown option
-        cout << "See manpage for config file structure." << endl;
+    // initialize Updater
+    UpdaterPtr updater(new Updater(config));
+
+    if ( updater->init_config_from_cmd(argc,argv) != 0 )
         return 0;
-    }
-    else if(ret_val == 4)
-    {
-        // error opening
+
+    if ( updater->init_config_from_files() != 0 )
         return 0;
-    }
 
-    // initialize Updater
-    UpdaterPtr updater(new Updater(config));
     updater->update_services();
 
     return 0;
index 35811e6..37557e0 100644 (file)
@@ -40,6 +40,58 @@ Updater::~Updater()
 
 
 /**
+ * 
+ * @param argc 
+ * @param argv[] 
+ * @return 
+ */
+const int Updater::init_config_from_cmd(int argc, char *argv[])
+{
+    // Load the command line parameters
+    int ret_val = Conf->parse_cmd_line(argc,argv);
+    if(ret_val == 1)
+    {
+        // usage
+        Conf->print_usage();
+        return ret_val;
+    }
+    else if(ret_val == 2)
+    {
+        // version
+        ostringstream version_string;
+        version_string << VERSION << "." << REVISION << "." << RELEASE;
+        Conf->print_version(version_string.str());
+        return ret_val;
+    }
+    // successful parsed
+    Conf->print_cmd_parsed();
+    return 0;
+}
+
+const int Updater::init_config_from_files()
+{
+    // Load the main config and the service files
+    string config_path = "/home/bjoern/bpdyndnsd";  // TODO: standard config path should be /etc/bpdyndnsd if not specified other on command line
+    int ret_val = Conf->load_config_from_files(config_path);
+    if(ret_val == 3)
+    {
+        // unknown option
+        Conf->print_unknown_conf_option();
+        return ret_val;
+    }
+    else if(ret_val == 4)
+    {
+        // error opening
+        Conf->print_error_opening();
+        return ret_val;
+    }
+    // successful loaded
+    Conf->print_conf_loaded();
+    return 0;
+}
+
+
+/**
  * Setter for member Conf.
  * @param _conf
  */
index edb6548..dfc7528 100644 (file)
@@ -31,6 +31,10 @@ public:
     ConfigPtr get_config();
 
     void update_services();
+
+    const int init_config_from_cmd(int, char **);
+
+    const int init_config_from_files();
 };
 
 #endif