Now serializing list of shared pointers instead of list of Service*.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Fri, 7 Aug 2009 14:20:44 +0000 (16:20 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Fri, 7 Aug 2009 14:20:44 +0000 (16:20 +0200)
src/config.cpp
src/config.h
src/dhs.cpp
src/logger.cpp
src/ods.cpp
src/service.cpp
src/serviceholder.cpp
src/serviceholder.h
src/updater.cpp

index bca9dc3..ba66d71 100644 (file)
@@ -22,7 +22,8 @@ using namespace std;
  * Default Constructor. Available command line and config file options with their default values are defined here.
  */
 Config::Config(LoggerPtr _log)
-    : Daemon_mode(false)
+    : Log(new Logger)
+    , Daemon_mode(false)
     , Loglevel(0)
     , Syslog(false)
     , Config_path("/etc/bpdyndnsd")
@@ -68,8 +69,6 @@ Config::Config(LoggerPtr _log)
     // Define valid service file options
     Opt_desc_conf_service = new po::options_description("Service file options");
     Opt_desc_conf_service->add(opt_desc_service);
-
-    Log->print_constructor_call("Config");
 }
 
 
@@ -81,8 +80,6 @@ Config::~Config()
     delete Opt_desc_cmd;
     delete Opt_desc_conf_main;
     delete Opt_desc_conf_service;
-
-    Log->print_destructor_call("Config");
 }
 
 
@@ -100,7 +97,7 @@ int Config::serialize_services()
 
     BOOST_FOREACH(ServicePtr service, Services)
     {
-        service_holder->add_service(service.get());
+        service_holder->add_service(service);
     }
 
     // Then we can serialize this separate Object into one file.
@@ -135,23 +132,22 @@ int Config::deserialize_services()
         ServiceholderPtr service_holder(_service_holder);
         ifs.close();
 
-        list<Service*> old_services = service_holder->get_hold_services();
+        list<ServicePtr> old_services = service_holder->get_hold_services();
 
-        BOOST_FOREACH(Service* old_service, old_services)
+        BOOST_FOREACH(ServicePtr old_service, old_services)
         {
             Log->print_service_object("Deserialized following Service object:", old_service->get_protocol(), old_service->get_hostname(), old_service->get_login() ,old_service->get_password() ,old_service->get_actual_ip(), old_service->get_lastupdated());
         }
 
-        BOOST_FOREACH(ServicePtr service_ptr, Services)
+        BOOST_FOREACH(ServicePtr service, Services)
         {
-            Service * service = service_ptr.get();
-            BOOST_FOREACH(Service* old_service, old_services)
+            BOOST_FOREACH(ServicePtr old_service, old_services)
             {
                 if ( *service == *old_service )
                 {
                     service->set_lastupdated(old_service->get_lastupdated());
                     service->set_actual_ip(old_service->get_actual_ip());
-                    Log->print_service_object("New Service object with adopted values:", service_ptr->get_protocol(), service_ptr->get_hostname(), service_ptr->get_login() ,service_ptr->get_password() ,service_ptr->get_actual_ip(), service_ptr->get_lastupdated());
+                    Log->print_service_object("New Service object with adopted values:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password() ,service->get_actual_ip(), service->get_lastupdated());
                 }
             }
         }
index d2cbe55..9db00db 100644 (file)
@@ -18,6 +18,7 @@
 #include <boost/archive/text_oarchive.hpp>
 #include <boost/archive/text_iarchive.hpp>
 #include <boost/serialization/export.hpp>
+#include <boost/serialization/shared_ptr.hpp>
 
 #include <string>
 #include <iostream>
@@ -48,7 +49,6 @@ private:
     LoggerPtr Log;
 
     bool Daemon_mode;
-    std::string Logfile;
     int Loglevel;
     bool Syslog;
     std::string Config_path;
index 3159268..ac3d195 100644 (file)
@@ -16,6 +16,8 @@ using namespace std;
  * Default Constructor, needed for object serialization.
  */
 DHS::DHS()
+    : Timeout(0)
+    , Max_updates_per_timeout(0)
 {
 }
 
@@ -37,8 +39,6 @@ DHS::DHS(const string& _protocol, const string& _hostname, const string& _login,
     set_password(_password);
     set_logger(_logger);
     set_lastupdated(_lastupdated);
-
-    get_logger()->print_constructor_call("DHS");
 }
 
 
@@ -47,7 +47,6 @@ DHS::DHS(const string& _protocol, const string& _hostname, const string& _login,
  */
 DHS::~DHS()
 {
-    get_logger()->print_destructor_call("DHS");
 }
 
 
index cb40e32..5cc26d0 100644 (file)
@@ -19,10 +19,9 @@ using namespace std;
  */
 Logger::Logger()
     : Loglevel(0)
-    , Syslog(0)
+    , Syslog(false)
 {
     set_log_facility(Loglevel,Syslog);
-    print_constructor_call("Logger");
 }
 
 
@@ -31,7 +30,6 @@ Logger::Logger()
  */
 Logger::~Logger()
 {
-    print_destructor_call("Logger");
 }
 
 
@@ -81,6 +79,7 @@ void Logger::log_error(const string& msg)
 void Logger::set_loglevel(const int _loglevel)
 {
     Loglevel = _loglevel;
+    cout << "Loglevel set" << endl;
 }
 
 
index aa09996..70a6399 100644 (file)
@@ -16,6 +16,8 @@ using namespace std;
  * Default Constructor, needed for object serialization.
  */
 ODS::ODS()
+    : Timeout(0)
+    , Max_updates_per_timeout(0)
 {
 }
 
@@ -37,8 +39,6 @@ ODS::ODS(const string& _protocol, const string& _hostname, const string& _login,
     set_password(_password);
     set_logger(_logger);
     set_lastupdated(_lastupdated);
-
-    get_logger()->print_constructor_call("ODS");
 }
 
 
@@ -47,7 +47,6 @@ ODS::ODS(const string& _protocol, const string& _hostname, const string& _login,
  */
 ODS::~ODS()
 {
-    get_logger()->print_destructor_call("ODS");
 }
 
 
index 95eb8dd..5bfda4a 100644 (file)
@@ -18,8 +18,9 @@ Service::Service()
     , Hostname("")
     , Login("NOT SERIALIZED")
     , Password("NOT SERIALIZED")
-    , Lastupdated(0)
     , Actual_IP("0.0.0.0")
+    , Lastupdated(0)
+    , Log(new Logger())
 {
 }
 
index 1d4c073..f2eaa57 100644 (file)
@@ -45,7 +45,7 @@ void Serviceholder::serialize(Archive & ar, const unsigned int version)
  * Add Service * to internal list.
  * @param service Pointer to Service object.
  */
-void Serviceholder::add_service(Service * service)
+void Serviceholder::add_service(ServicePtr service)
 {
     Hold_services.push_back(service);
 }
@@ -55,7 +55,7 @@ void Serviceholder::add_service(Service * service)
  * Needed after deserialization to get the valid list of Service* back.
  * @return The list of Service*.
  */
-std::list<Service*> Serviceholder::get_hold_services()
+std::list<ServicePtr> Serviceholder::get_hold_services()
 {
     return Hold_services;
 }
index 80b44b6..eddb647 100644 (file)
 #include <list>
 
 #include "service.h"
-#include "logger.h"
 
 #include <boost/serialization/array.hpp>
 #include <boost/serialization/list.hpp>
 #include <boost/shared_ptr.hpp>
 
-typedef boost::shared_ptr<Logger> LoggerPtr;
+typedef boost::shared_ptr<Service> ServicePtr;
 
 class Serviceholder
 {
 private:
     friend class boost::serialization::access;
 
-    std::list<Service*> Hold_services;
+    std::list<ServicePtr> Hold_services;
 
     template<class Archive>
     void serialize(Archive &, const unsigned int);
 
-    int Test;
-
 public:
 
     Serviceholder();
@@ -41,9 +38,9 @@ public:
 
     ~Serviceholder();
 
-    void add_service(Service *);
+    void add_service(ServicePtr);
 
-    std::list<Service*> get_hold_services();
+    std::list<ServicePtr> get_hold_services();
 };
 
 #endif
index fac511d..74b828c 100644 (file)
@@ -16,15 +16,13 @@ using namespace std;
  */
 Updater::Updater()
 {
-    // initialize Logger
+    // Initialize program wide Logger, at this point we don't know where to log and with which loglevel.
     LoggerPtr _log(new Logger);
     Log = _log;
 
     // initialize Config
     ConfigPtr _config(new Config(Log));
     Conf = _config;
-
-    Log->print_constructor_call("Updater");
 }
 
 
@@ -33,7 +31,6 @@ Updater::Updater()
  */
 Updater::~Updater()
 {
-    Log->print_destructor_call("Updater");
 }