From 2e956a366f0605f09bd4147647e299b3805a70c7 Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Fri, 7 Aug 2009 16:20:44 +0200 Subject: [PATCH] Now serializing list of shared pointers instead of list of Service*. --- src/config.cpp | 20 ++++++++------------ src/config.h | 2 +- src/dhs.cpp | 5 ++--- src/logger.cpp | 5 ++--- src/ods.cpp | 5 ++--- src/service.cpp | 3 ++- src/serviceholder.cpp | 4 ++-- src/serviceholder.h | 11 ++++------- src/updater.cpp | 5 +---- 9 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index bca9dc3..ba66d71 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -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 old_services = service_holder->get_hold_services(); + list 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()); } } } diff --git a/src/config.h b/src/config.h index d2cbe55..9db00db 100644 --- a/src/config.h +++ b/src/config.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -48,7 +49,6 @@ private: LoggerPtr Log; bool Daemon_mode; - std::string Logfile; int Loglevel; bool Syslog; std::string Config_path; diff --git a/src/dhs.cpp b/src/dhs.cpp index 3159268..ac3d195 100644 --- a/src/dhs.cpp +++ b/src/dhs.cpp @@ -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"); } diff --git a/src/logger.cpp b/src/logger.cpp index cb40e32..5cc26d0 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -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; } diff --git a/src/ods.cpp b/src/ods.cpp index aa09996..70a6399 100644 --- a/src/ods.cpp +++ b/src/ods.cpp @@ -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"); } diff --git a/src/service.cpp b/src/service.cpp index 95eb8dd..5bfda4a 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -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()) { } diff --git a/src/serviceholder.cpp b/src/serviceholder.cpp index 1d4c073..f2eaa57 100644 --- a/src/serviceholder.cpp +++ b/src/serviceholder.cpp @@ -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 Serviceholder::get_hold_services() +std::list Serviceholder::get_hold_services() { return Hold_services; } diff --git a/src/serviceholder.h b/src/serviceholder.h index 80b44b6..eddb647 100644 --- a/src/serviceholder.h +++ b/src/serviceholder.h @@ -13,26 +13,23 @@ #include #include "service.h" -#include "logger.h" #include #include #include -typedef boost::shared_ptr LoggerPtr; +typedef boost::shared_ptr ServicePtr; class Serviceholder { private: friend class boost::serialization::access; - std::list Hold_services; + std::list Hold_services; template 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 get_hold_services(); + std::list get_hold_services(); }; #endif diff --git a/src/updater.cpp b/src/updater.cpp index fac511d..74b828c 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -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"); } -- 1.7.1