Introduced Logger.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Thu, 30 Jul 2009 13:48:28 +0000 (15:48 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Thu, 30 Jul 2009 13:48:28 +0000 (15:48 +0200)
12 files changed:
src/config.cpp
src/config.h
src/dhs.cpp
src/dhs.h
src/logger.cpp [new file with mode: 0644]
src/logger.h [new file with mode: 0644]
src/main.cpp
src/ods.cpp
src/ods.h
src/service.cpp
src/updater.cpp
src/updater.h

index cd33509..1253ab5 100644 (file)
@@ -7,21 +7,27 @@
  * @license GPLv2
 */
 
+
 #include "config.h"
 
+
 /**
  * Default Constructor. Available command line and config file options with their default values are defined here.
  */
-Config::Config()
+Config::Config(LoggerPtr _log)
     : Daemon_mode(false)
     , Loglevel(0)
     , Syslog(false)
 {
+    // initialize Logger
+    Log = _log;
+
     // Define valid command line parameters
     Opt_desc_cmd = new po::options_description("Command line options");
     Opt_desc_cmd->add_options()
         ("help,?","Show help.")
         ("version,v","Show version.")
+        ("config,c",po::value<string>()->default_value("/etc/bpdyndnsd"),"Set the config path.")
         ("protocol,q",po::value<string>(),"Set the service protocol type.")
         ("host,h",po::value<string>(),"Set the hostname to update.")
         ("login,l",po::value<string>(),"Set the login.")
@@ -45,6 +51,8 @@ Config::Config()
         ("service.login",po::value<string>(),"Login name.")
         ("service.password",po::value<string>(),"Corresponding password.")
     ;
+
+    Log->print_constructor_call("Config");
 }
 
 
@@ -57,7 +65,7 @@ Config::~Config()
     delete Opt_desc_conf_main;
     delete Opt_desc_conf_service;
 
-    cout << "Config destructor!!!" << endl;
+    Log->print_destructor_call("Config");
 }
 
 
@@ -65,9 +73,9 @@ Config::~Config()
  * 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,
+ * @return 0 if all is fine, 1 if not.
  */
-const int Config::parse_cmd_line(int argc, char *argv[])
+int Config::parse_cmd_line(int argc, char *argv[])
 {
     try
     {
@@ -75,13 +83,19 @@ const int Config::parse_cmd_line(int argc, char *argv[])
         po::store(po::parse_command_line(argc, argv, *this->Opt_desc_cmd), vm);
         po::notify(vm);
 
-        if(vm.count("help"))
+        if ( vm.count("help") )
+        {
+            Log->print_usage(Opt_desc_cmd);
             return 1;
-        else if(vm.count("version"))
-            return 2;
+        }
+        else if ( vm.count("version") )
+        {
+            Log->print_version();
+            return 1;
+        }
 
-        // Are all needed options set to create a Service Object
-        if(vm.count("protocol") && vm.count("host") && vm.count("login") && vm.count("password"))
+        // Create a service object if all needed options are set on the command line
+        if ( vm.count("protocol") && vm.count("host") && vm.count("login") && vm.count("password") )
         {
             // Get the cmd parameter values for protocol host login and password
             string protocol = vm["protocol"].as<string>();
@@ -93,19 +107,33 @@ const int Config::parse_cmd_line(int argc, char *argv[])
 
             ServicePtr service = create_service(protocol,host,login,password);
             if ( service != NULL )
-            {
                 Services.push_back(service);
-            }
+            else
+                return 1;
         }
-        else
+        else if ( vm.count("protocol") || vm.count("host") || vm.count("login") || vm.count("password") )
         {
-            cout << "Not all needed options set!\n" << endl;
+            Log->print_missing_cmd_service_option();
+            Log->print_usage(Opt_desc_cmd);
             return 1;
         }
+
+        if ( vm.count("config") )
+        {
+            fs::path full_config_path = fs::system_complete(fs::path(vm["config"].as<string>()));
+            Config_path = full_config_path.string();
+            if ( !fs::exists(full_config_path) ||  !fs::is_directory(full_config_path) )
+            {
+                // Config path doesn't exist or is not a directory
+                Log->print_error_config_path(Config_path);
+                return 1;
+            }
+        }
     }
     catch(po::unknown_option e)
     {
-        cout << "Unknown option set." << endl;
+        Log->print_unknown_cmd_option(e.what());
+        Log->print_usage(Opt_desc_cmd);
         return 1;
     }
     return 0;
@@ -124,17 +152,17 @@ ServicePtr Config::create_service(const string &protocol,const string &host, con
 {
     if(protocol == "dhs")
     {
-        ServicePtr service_dhs(new DHS(host,login,password));
+        ServicePtr service_dhs(new DHS(Log,host,login,password));
         return service_dhs;
     }
     else if(protocol == "ods")
     {
-        ServicePtr service_ods(new ODS(host,login,password));
+        ServicePtr service_ods(new ODS(Log,host,login,password));
         return service_ods;
     }
     else
     {
-        cout << "Could not find specified protocol: " << protocol << endl;
+        Log->print_unknown_protocol(protocol);
         ServicePtr service;
         return service;
     }
@@ -146,9 +174,10 @@ ServicePtr Config::create_service(const string &protocol,const string &host, con
  * @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.
  */
-const int Config::load_service_config_file(const string& full_filename)
+int Config::load_service_config_file(const string& full_filename)
 {
-    cout << "Loading service config file: " << full_filename << endl;
+    Log->print_load_service_conf(full_filename);
+
     ifstream service_config_file(full_filename.c_str(),ifstream::in);
     if(service_config_file.is_open())
     {
@@ -181,28 +210,30 @@ const int Config::load_service_config_file(const string& full_filename)
         {
             // unknown option in config file detected
             service_config_file.close();
-            cout << "Unknown option in service config file detected!" << endl;
-            return 3;
+            Log->print_unknown_service_conf_option(e.what());
+            return 1;
         }
         service_config_file.close();
     }
     else
     {
-        cout << "Can't open service config file for reading: " << service_config_file << endl;
-        return 4;
+        // error opening service config file for reading
+        Log->print_error_opening(full_filename);
+        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
  */
-const int Config::load_main_config_file(const string& full_filename)
+int Config::load_main_config_file(const string& full_filename)
 {
-    // load main config file
-    cout << "Loading main config file: " << full_filename << endl;
+    Log->print_load_main_conf(full_filename);
+
     ifstream main_config_file(full_filename.c_str(),ifstream::in);
     if(main_config_file.is_open())
     {
@@ -223,70 +254,58 @@ const int Config::load_main_config_file(const string& full_filename)
         }
         catch ( po::unknown_option e )
         {
-            // unknown option in config file detected
+            // unknown option in main config file detected
             main_config_file.close();
-            cout << "Unknown option in main config file detected!" << endl;
-            return 3;
+            Log->print_unknown_main_conf_option(e.what());
+            return 1;
         }
         main_config_file.close();
     }
     else
     {
-        cout << "Can't open main config file for reading: " << main_config_file << endl;
-        return 4;
+        // error opening main config file for reading
+        Log->print_error_opening(full_filename);
+        return 1;
     }
     return 0;
 }
 
-// TODO: Seperate into smaller methods
+
 /**
  * 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.
  */
-const int Config::load_config_from_files(const string& config_path)
+int Config::load_config_from_files()
 {
-    fs::path full_config_path = fs::system_complete(fs::path(config_path));
+    fs::path full_config_path = fs::path(Config_path);
 
-    if ( fs::exists(full_config_path) && fs::is_directory(full_config_path) )
+    fs::directory_iterator end_iter;
+    for ( fs::directory_iterator dir_itr(full_config_path) ; dir_itr != end_iter ; ++dir_itr )
     {
-        fs::directory_iterator end_iter;
-        for ( fs::directory_iterator dir_itr(full_config_path) ; dir_itr != end_iter ; ++dir_itr )
+        if( fs::is_regular_file( dir_itr->status() ) )
         {
-            if( fs::is_regular_file( dir_itr->status() ) )
+            string actual_file = dir_itr->path().filename();
+            boost::regex expr(".*\.conf?");
+             // If it is the main config file do the following
+            if ( actual_file == "bpdyndnsd.conf" )
             {
-                string actual_file = dir_itr->path().filename();
-                boost::regex expr(".*\.conf?");
-
-                // If it is the main config file do the following
-                if ( actual_file == "bpdyndnsd.conf" )
-                {
-                    // Load the main config file
-                    string full_filename = dir_itr->path().string();
-                    int ret_val = load_main_config_file(full_filename);
-                    if ( ret_val != 0 )
-                    {
-                        return ret_val;
-                    }
-                }
-                // 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();
-                    int ret_val = load_service_config_file(full_filename);
-                    if ( ret_val != 0 )
-                    {
-                        return ret_val;
-                    }
-                }
+                // Load the main config file
+                string full_filename = dir_itr->path().string();
+                if ( load_main_config_file(full_filename) != 0 )
+                    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;
             }
         }
     }
-    else
-    {
-        cout << "Config path doesn't exist or is not a directory" << endl;
-        return 4;
-    }
+    // Config file successfully loaded
+    Log->print_conf_loaded(Config_path);
     return 0;
 }
 
@@ -302,43 +321,30 @@ list<ServicePtr> Config::get_services()
 
 
 /**
- * Prints out the usage to the command line.
+ * Getter method for member Opt_desc_cmd.
+ * @return options_description*.
  */
-void Config::print_usage()
+po::options_description* Config::get_opt_desc_cmd()
 {
-    cout << "Usage: bpdyndnsd [Command line options]" << "\n" << endl;
-    cout << *Opt_desc_cmd << endl;
+    return Opt_desc_cmd;
 }
 
 
 /**
- * Prints out the programm name and the given version string on stdout.
- * @param version Version string.
+ * Getter method for member Opt_desc_conf_main.
+ * @return options_description*.
  */
-void Config::print_version(const string& version)
+po::options_description* Config::get_opt_desc_conf_main()
 {
-    cout << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << version << endl;
+    return Opt_desc_conf_main;
 }
 
+
 /**
- * Prints out the successful parsing of the command line options.
+ * Getter method for member Opt_desc_conf_service.
+ * @return options_description*.
  */
-void Config::print_cmd_parsed()
-{
-    cout << "Command line arguments successful parsed." << endl;
-}
-
-void Config::print_conf_loaded()
+po::options_description* Config::get_opt_desc_conf_service()
 {
-    cout << "Config files successful loaded." << endl;
+    return Opt_desc_conf_service;
 }
-
-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 bc12eb7..a208a54 100644 (file)
@@ -21,6 +21,7 @@
 #include <fstream>
 
 #include "service.h"
+#include "logger.h"
 
 #include "dhs.h"
 #include "ods.h"
@@ -31,46 +32,48 @@ namespace fs = boost::filesystem;
 using namespace std;
 
 typedef boost::shared_ptr<Service> ServicePtr;
+typedef boost::shared_ptr<Logger> LoggerPtr;
 
 class Config
 {
+
 private:
+
     po::options_description *Opt_desc_cmd;
     po::options_description *Opt_desc_conf_main;
     po::options_description *Opt_desc_conf_service;
 
     list<ServicePtr> Services;
+    LoggerPtr Log;
 
     bool Daemon_mode;
     string Logfile;
     int Loglevel;
     bool Syslog;
+    string Config_path;
 
     ServicePtr create_service(const string&,const string&,const string&,const string&);
-    const int load_main_config_file(const string&);
-    const int load_service_config_file(const string&);
-public:
-    Config();
+    int load_main_config_file(const string&);
+    int load_service_config_file(const string&);
 
-    ~Config();
+public:
 
-    const int parse_cmd_line(int, char **);
+    Config(LoggerPtr);
 
-    const int load_config_from_files(const string&);
+    ~Config();
 
-    void print_usage();
+    int parse_cmd_line(int, char **);
 
-    void print_version(const string&);
+    int load_config_from_files();
 
-    void print_cmd_parsed();
+    list<ServicePtr> get_services();
 
-    void print_conf_loaded();
+    po::options_description* get_opt_desc_cmd();
 
-    void print_error_opening();
+    po::options_description* get_opt_desc_conf_main();
 
-    void print_unknown_conf_option();
+    po::options_description* get_opt_desc_conf_service();
 
-    list<ServicePtr> get_services();
 };
 
 #endif
index 10672ba..b530739 100644 (file)
 
 
 /**
- * Default constructor.
- */
-DHS::DHS()
-{
-}
-
-
-/**
  * Constructor.
  * @param _hostname The hostname to update
  * @param _login The login name.
  * @param _password The corresponding password.
  */
-DHS::DHS(const string& _hostname, const string& _login, const string& _password)
+DHS::DHS(const LoggerPtr& _log ,const string& _hostname, const string& _login, const string& _password)
 {
+    Log = _log;
+
     Hostname = _hostname;
     Login = _login;
     Password = _password;
+
+    Log->print_constructor_call("DHS");
 }
 
 
@@ -37,7 +33,7 @@ DHS::DHS(const string& _hostname, const string& _login, const string& _password)
  */
 DHS::~DHS()
 {
-    cout << "DHS destructor!!!" << endl;
+    Log->print_destructor_call("DHS");
 }
 
 
@@ -47,7 +43,8 @@ DHS::~DHS()
  */
 void DHS::update(const string& ip)
 {
-    cout << "Running Update for Service DHS" << endl;
+    Log->print_update_service("DHS");
+
     cout << "Hostname: " << Hostname << endl;
     cout << "Login: " << Login << endl;
     cout << "Password: " << Password << endl;
index ae684f5..157316a 100644 (file)
--- a/src/dhs.h
+++ b/src/dhs.h
 
 #include <string>
 #include "service.h"
+#include "logger.h"
 
 using namespace std;
 
+typedef boost::shared_ptr<Logger> LoggerPtr;
+
 class DHS : public Service
 {
+
 private:
+
     string Hostname;
     string Login;
     string Password;
 
+    LoggerPtr Log;
+
 public:
-    DHS();
 
-    DHS(const string&, const string&, const string&);
+    DHS(const LoggerPtr&, const string&, const string&, const string&);
 
     ~DHS();
 
     void update(const string&);
+
 };
 
 #endif
diff --git a/src/logger.cpp b/src/logger.cpp
new file mode 100644 (file)
index 0000000..9515aba
--- /dev/null
@@ -0,0 +1,175 @@
+/** @file
+ * @brief Logger class implementation. This class implements the Logging facility.
+ *
+ *
+ *
+ * @copyright Intra2net AG
+ * @license GPLv2
+*/
+
+
+#include "logger.h"
+
+
+/**
+ * Default Constructor
+ */
+Logger::Logger()
+{
+    print_constructor_call("Logger");
+}
+
+
+/**
+ * Default Destructor
+ */
+Logger::~Logger()
+{
+    print_destructor_call("Logger");
+}
+
+
+/**
+ * Prints out the usage to the command line.
+ */
+void Logger::print_usage(const po::options_description* opt_desc)
+{
+    cout << "Usage: bpdyndnsd [Command line options]" << "\n" << endl;
+    cout << *opt_desc << endl;
+}
+
+
+/**
+ * Prints out the programm name and the given version string on stdout.
+ * @param version Version string.
+ */
+void Logger::print_version()
+{
+    ostringstream version_string;
+    version_string << VERSION << "." << REVISION << "." << RELEASE;
+    cout << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << version_string.str() << endl;
+}
+
+
+/**
+ * Prints out the successful parsing of the command line options.
+ */
+void Logger::print_cmd_parsed()
+{
+    cout << "Command line options successfully parsed." << endl;
+}
+
+
+/**
+ * Prints out the successful parsing of the config files.
+ */
+void Logger::print_conf_loaded(const string& config_path)
+{
+    cout << "Config files successfully loaded in: " << config_path << endl;
+}
+
+
+/**
+ * Prints out the successful parsing of the config files.
+ */
+void Logger::print_conf_not_loaded(const string& config_path)
+{
+    cout << "Config files couldn't be loaded in: " << config_path << endl;
+}
+
+
+/**
+ * Prints out the detection of unknown option on config file.
+ */
+void Logger::print_unknown_conf_option()
+{
+    cout << "Unknown option in config file detected" << endl;
+    cout << "See manpage for config file structure." << endl;
+}
+
+
+/**
+ * Prints out error on opening file
+ */
+void Logger::print_error_opening(const string& filename)
+{
+    cout << "Error opening file for reading: " << filename << endl;
+}
+
+
+/**
+ * Desctructor of specified class was called.
+ * @param _class Name of the class.
+ */
+void Logger::print_destructor_call(const string& _class)
+{
+    cout << "Destructor call: " << _class << endl;
+}
+
+
+/**
+ * Constructor of specified class was called.
+ * @param _class Name of the class.
+ */
+void Logger::print_constructor_call(const string& _class)
+{
+    cout << "Constructor call: " << _class << endl;
+}
+
+
+/**
+ * Update method for specified service was called.
+ * @param service The service which for which is running the update.
+ */
+void Logger::print_update_service(const string& service)
+{
+    cout << "Running update for service: " << service << endl;
+}
+
+
+void Logger::print_unknown_cmd_option(const string& unknown_option)
+{
+    cout << "Unknown option on command line detected: " << unknown_option << endl;
+}
+
+
+void Logger::print_unknown_protocol(const string& protocol)
+{
+    cout << "Unknown protocol defined: " << protocol << endl;
+}
+
+
+void Logger::print_load_service_conf(const string& filename)
+{
+    cout << "Loading service config file: " << filename << endl;
+}
+
+
+void Logger::print_load_main_conf(const string& filename)
+{
+    cout << "Loading main config file: " << filename << endl;
+}
+
+
+void Logger::print_unknown_service_conf_option(const string& unknown_option)
+{
+    cout << "Unknown option in service config file detected: " << unknown_option << endl;
+}
+
+
+void Logger::print_unknown_main_conf_option(const string& unknown_option)
+{
+    cout << "Unknown option in mian config file detected: " << unknown_option << endl;
+}
+
+
+void Logger::print_error_config_path(const string& config_path)
+{
+    cout << "Config path doesn't exists or is not a diretory: " << config_path << endl;
+}
+
+
+void Logger::print_missing_cmd_service_option()
+{
+    cout << "Missing option to initialize service. Protocol, host, login and password must be specified." << endl;
+}
diff --git a/src/logger.h b/src/logger.h
new file mode 100644 (file)
index 0000000..d17a6b2
--- /dev/null
@@ -0,0 +1,63 @@
+/** @file
+ * @brief Logger class header. This class represents the Logging facility.
+ *
+ *
+ *
+ * @copyright Intra2net AG
+ * @license GPLv2
+*/
+
+#ifndef LOGGER_H
+#define LOGGER_H
+
+namespace po = boost::program_options;
+
+using namespace std;
+
+class Logger
+{
+
+public:
+
+    Logger();
+
+    ~Logger();
+
+    void print_usage(const po::options_description*);
+
+    void print_version();
+
+    void print_cmd_parsed();
+
+    void print_unknown_conf_option();
+
+    void print_destructor_call(const string&);
+
+    void print_constructor_call(const string&);
+
+    void print_update_service(const string&);
+
+    void print_unknown_cmd_option(const string&);
+
+    void print_unknown_protocol(const string&);
+
+    void print_load_service_conf(const string&);
+
+    void print_load_main_conf(const string&);
+
+    void print_unknown_service_conf_option(const string&);
+
+    void print_unknown_main_conf_option(const string&);
+
+    void print_error_opening(const string&);
+
+    void print_error_config_path(const string&);
+
+    void print_conf_loaded(const string&);
+
+    void print_conf_not_loaded(const string&);
+
+    void print_missing_cmd_service_option();
+};
+
+#endif
index fbab021..a6a9492 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "updater.cpp"
 #include "config.cpp"
+#include "logger.cpp"
 
 #include "service.cpp"
 
@@ -31,7 +32,6 @@
 
 using namespace std;
 
-typedef boost::shared_ptr<Config> ConfigPtr;
 typedef boost::shared_ptr<Updater> UpdaterPtr;
 
 /**
@@ -42,18 +42,22 @@ typedef boost::shared_ptr<Updater> UpdaterPtr;
  */
 int main(int argc, char *argv[])
 {
-    // initialize Config
-    ConfigPtr config(new Config);
-
     // initialize Updater
-    UpdaterPtr updater(new Updater(config));
+    UpdaterPtr updater(new Updater);
 
+    // load the cmd options
     if ( updater->init_config_from_cmd(argc,argv) != 0 )
         return 0;
 
+    // load the config and service files
     if ( updater->init_config_from_files() != 0 )
         return 0;
 
+    // set the configured loggin facility, default stdout
+
+    // initialize daemon mode if configured
+
+    // update all configured services
     updater->update_services();
 
     return 0;
index a0ffa29..24a7484 100644 (file)
@@ -9,13 +9,6 @@
 
 #include "ods.h"
 
-/**
- * Default constructor.
- */
-ODS::ODS()
-{
-}
-
 
 /**
  * Constructor.
@@ -23,11 +16,15 @@ ODS::ODS()
  * @param _login The login name.
  * @param _password The corresponding password.
  */
-ODS::ODS(const string& _hostname, const string& _login, const string& _password)
+ODS::ODS(const LoggerPtr& _log, const string& _hostname, const string& _login, const string& _password)
 {
+    Log = _log;
+
     Hostname = _hostname;
     Login = _login;
     Password = _password;
+
+    Log->print_constructor_call("ODS");
 }
 
 
@@ -36,7 +33,7 @@ ODS::ODS(const string& _hostname, const string& _login, const string& _password)
  */
 ODS::~ODS()
 {
-    cout << "ODS destructor!!!" << endl;
+    Log->print_destructor_call("ODS");
 }
 
 
@@ -46,7 +43,8 @@ ODS::~ODS()
  */
 void ODS::update(const string& ip)
 {
-    cout << "Running Update for Service ODS" << endl;
+    Log->print_update_service("ODS");
+
     cout << "Hostname: " << Hostname << endl;
     cout << "Login: " << Login << endl;
     cout << "Password: " << Password << endl;
index 25c925e..c9f0129 100644 (file)
--- a/src/ods.h
+++ b/src/ods.h
 
 #include <string>
 #include "service.h"
+#include "logger.h"
 
 using namespace std;
 
+typedef boost::shared_ptr<Logger> LoggerPtr;
+
 class ODS : public Service
 {
+
 private:
+
     string Hostname;
     string Login;
     string Password;
 
+    LoggerPtr Log;
+
 public:
-    ODS();
 
-    ODS(const string&, const string&, const string&);
+    ODS(const LoggerPtr&, const string&, const string&, const string&);
 
     ~ODS();
 
     void update(const string&);
+
 };
 
 #endif
index d2ca5ba..bce79be 100644 (file)
@@ -14,6 +14,7 @@
  */
 Service::Service()
 {
+
 }
 
 /**
@@ -21,6 +22,7 @@ Service::Service()
  */
 Service::~Service()
 {
+
 }
 
 
index 37557e0..4d75c1e 100644 (file)
  */
 Updater::Updater()
 {
-}
+    // initialize Logger
+    LoggerPtr _log(new Logger);
+    Log = _log;
 
+    // initialize Config
+    ConfigPtr _config(new Config(Log));
+    Conf = _config;
 
-/**
- * Constructor.
- * @param _conf A pointer to a Config object.
- */
-Updater::Updater(ConfigPtr _conf)
-{
-    Conf = _conf;
+    Log->print_constructor_call("Updater");
 }
 
 
@@ -35,79 +34,40 @@ Updater::Updater(ConfigPtr _conf)
  */
 Updater::~Updater()
 {
-    cout << "Updater destructor!!!" << endl;
+    Log->print_destructor_call("Updater");
 }
 
 
 /**
- * 
- * @param argc 
- * @param argv[] 
- * @return 
+ * Parse the command line arguments and initialize corresponding options.
+ * @param argc Number command line arguments.
+ * @param argv[] Array with arguments.
+ * @return 0 if cmd options successfully parsed, 1 if usage or version.
  */
-const int Updater::init_config_from_cmd(int argc, char *argv[])
+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;
-}
+    if( Conf->parse_cmd_line( argc, argv ) != 0)
+        return 1;
 
-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();
+    // successful parsed
+    Log->print_cmd_parsed();
     return 0;
 }
 
 
 /**
- * Setter for member Conf.
- * @param _conf
+ * Load the main config and the service definition files in config path.
+ * @return 0 if all is fine, 
  */
-void Updater::set_config(ConfigPtr _conf)
+int Updater::init_config_from_files()
 {
-    Conf = _conf;
-}
+    // Load the main and service config files in config path
+    if( Conf->load_config_from_files() != 0)
+        return 1;
 
-
-/**
- * Getter for member Conf.
- * @return Conf.
- */
-ConfigPtr Updater::get_config()
-{
-    return Conf;
+    // successful loaded
+    return 0;
 }
 
 
index dfc7528..51c9a6b 100644 (file)
 #define UPDATER_H
 
 #include "config.h"
+#include "logger.h"
 
 typedef boost::shared_ptr<Config> ConfigPtr;
+typedef boost::shared_ptr<Logger> LoggerPtr;
 
 class Updater
 {
 private:
     ConfigPtr Conf;
+    LoggerPtr Log;
 
 public:
     Updater();
 
-    Updater(ConfigPtr);
-
     ~Updater();
 
-    void set_config(ConfigPtr);
-
-    ConfigPtr get_config();
-
     void update_services();
 
-    const int init_config_from_cmd(int, char **);
+    int init_config_from_cmd(int, char **);
 
-    const int init_config_from_files();
+    int init_config_from_files();
 };
 
 #endif