From: Bjoern Sikora Date: Mon, 10 Aug 2009 10:25:41 +0000 (+0200) Subject: Corrected include's in header files. X-Git-Tag: v1.1~237 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=88a594e85e8a199cd27393f2271a86fdfebb683e;p=bpdyndnsd Corrected include's in header files. Corrected typedef's in header files. --- diff --git a/src/config.cpp b/src/config.cpp index 62a0369..8281910 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -9,6 +9,23 @@ #include "config.h" +#include "serviceholder.h" +#include "dhs.h" +#include "ods.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + // Following boost macros are needed for serialization of derived classes through a base class pointer (Service *). BOOST_CLASS_EXPORT_GUID(ODS, "ODS") BOOST_CLASS_EXPORT_GUID(DHS, "DHS") @@ -21,7 +38,7 @@ using namespace std; /** * Default Constructor. Available command line and config file options with their default values are defined here. */ -Config::Config(LoggerPtr _log) +Config::Config(Logger::Ptr _log) : Log(new Logger) , Daemon_mode(false) , Loglevel(0) @@ -96,16 +113,16 @@ int Config::serialize_services() // First of all we have to put all Service objects in a Serviceholder object. - ServiceholderPtr service_holder(new Serviceholder()); + Serviceholder::Ptr service_holder(new Serviceholder()); - BOOST_FOREACH(ServicePtr service, Services) + BOOST_FOREACH(Service::Ptr service, Services) { service_holder->add_service(service); } int current_time = time(NULL); - BOOST_FOREACH(ServicePtr service, Old_services) + BOOST_FOREACH(Service::Ptr service, Old_services) { if ( ( service->get_lastupdated() + service->get_timeout() ) >= current_time ) // Update Timeout of service isn't expired. service_holder->add_service(service); @@ -122,7 +139,7 @@ int Config::serialize_services() boost::archive::text_oarchive oa(ofs); oa << _service_holder; } - catch( boost::archive_exception e ) + catch( boost::archive::archive_exception e ) { Log->print_exception_serialize(e.what()); ofs.close(); @@ -149,21 +166,21 @@ int Config::deserialize_services() Serviceholder* _service_holder; boost::archive::text_iarchive ia(ifs); ia >> _service_holder; // ends up in default constructor call for Serviceholder - ServiceholderPtr service_holder(_service_holder); + Serviceholder::Ptr service_holder(_service_holder); ifs.close(); - list _old_services = service_holder->get_hold_services(); + list _old_services = service_holder->get_hold_services(); - BOOST_FOREACH(ServicePtr old_service, _old_services) + BOOST_FOREACH(Service::Ptr old_service, _old_services) { // Put the deserialized service into the Old_service member list. Old_services.push_back(old_service); 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, Services) + BOOST_FOREACH(Service::Ptr service, Services) { - BOOST_FOREACH(ServicePtr old_service, Old_services) + BOOST_FOREACH(Service::Ptr old_service, Old_services) { if ( *service == *old_service ) { @@ -223,7 +240,7 @@ int Config::parse_cmd_line(int argc, char *argv[]) //TODO: convert protocol option to lowercase - ServicePtr service = create_service(protocol,host,login,password); + Service::Ptr service = create_service(protocol,host,login,password); if ( service ) Services.push_back(service); else @@ -273,22 +290,22 @@ int Config::parse_cmd_line(int argc, char *argv[]) * @param password * @return A pointer to the created Service object. */ -ServicePtr Config::create_service(const string &protocol,const string &hostname, const string &login, const string &password) +Service::Ptr Config::create_service(const string &protocol,const string &hostname, const string &login, const string &password) { if(protocol == "dhs") { - ServicePtr service_dhs(new DHS(protocol,hostname,login,password,Log,0,60,1)); + Service::Ptr service_dhs(new DHS(protocol,hostname,login,password,Log,0,60,1)); return service_dhs; } else if(protocol == "ods") { - ServicePtr service_ods(new ODS(protocol,hostname,login,password,Log,0,60,1)); + Service::Ptr service_ods(new ODS(protocol,hostname,login,password,Log,0,60,1)); return service_ods; } else { Log->print_unknown_protocol(protocol); - ServicePtr service; + Service::Ptr service; return service; } } @@ -324,7 +341,7 @@ int Config::load_service_config_file(const string& full_filename) // TODO: convert protocol to lowercase //protocol = tolower(protocol.c_str()); - ServicePtr service = create_service(protocol,host,login,password); + Service::Ptr service = create_service(protocol,host,login,password); if ( service ) { Services.push_back(service); @@ -438,7 +455,7 @@ int Config::load_config_from_files() * Getter method for Service list member. * @return Pointer to a list of Service's. */ -list Config::get_services() +list Config::get_services() { return this->Services; } @@ -448,7 +465,7 @@ list Config::get_services() * Getter method for member Opt_desc_cmd. * @return options_description*. */ -Options_descriptionPtr Config::get_opt_desc_cmd() +Config::Options_descriptionPtr Config::get_opt_desc_cmd() { return Opt_desc_cmd; } @@ -458,7 +475,7 @@ Options_descriptionPtr Config::get_opt_desc_cmd() * Getter method for member Opt_desc_conf_main. * @return options_description*. */ -Options_descriptionPtr Config::get_opt_desc_conf_main() +Config::Options_descriptionPtr Config::get_opt_desc_conf_main() { return Opt_desc_conf_main; } @@ -468,7 +485,7 @@ Options_descriptionPtr Config::get_opt_desc_conf_main() * Getter method for member Opt_desc_conf_service. * @return options_description*. */ -Options_descriptionPtr Config::get_opt_desc_conf_service() +Config::Options_descriptionPtr Config::get_opt_desc_conf_service() { return Opt_desc_conf_service; } @@ -499,7 +516,7 @@ bool Config::get_daemon_mode() */ void Config::delete_services() { - BOOST_FOREACH( ServicePtr service, Services ) + BOOST_FOREACH( Service::Ptr service, Services ) { service.reset(); } diff --git a/src/config.h b/src/config.h index a987930..076c3d0 100644 --- a/src/config.h +++ b/src/config.h @@ -10,63 +10,46 @@ #ifndef CONFIG_H #define CONFIG_H -// TODO: Only include needed header files in "config.h". -// Include the rest in config.cpp -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include -#include -#include - -#include #include "service.h" #include "logger.h" -#include "serviceholder.h" -#include "dhs.h" -#include "ods.h" +#include +#include -// TODO: What about putting this in the Logger/Service namespace instead of the global one? -typedef boost::shared_ptr ServicePtr; -typedef boost::shared_ptr LoggerPtr; -typedef boost::shared_ptr ServiceholderPtr; -typedef boost::shared_ptr Options_descriptionPtr; class Config { - private: + + typedef boost::shared_ptr Options_descriptionPtr; + Options_descriptionPtr Opt_desc_cmd; Options_descriptionPtr Opt_desc_conf_main; Options_descriptionPtr Opt_desc_conf_service; + boost::program_options::variables_map Variables_map; - std::list Services; // Represents all active Services. - std::list Old_services; // Represents all old Services where the timeout isn't expired (in case the same Service is redefined). + std::list Services; // Represents all active Services. + std::list Old_services; // Represents all old Services where the timeout isn't expired (in case the same Service is redefined). - LoggerPtr Log; + Logger::Ptr Log; bool Daemon_mode; int Loglevel; bool Syslog; std::string Config_path; - ServicePtr create_service(const std::string&,const std::string&,const std::string&,const std::string&); + Service::Ptr create_service(const std::string&,const std::string&,const std::string&,const std::string&); int load_main_config_file(const std::string&); int load_service_config_file(const std::string&); public: - Config(LoggerPtr); + typedef boost::shared_ptr Ptr; + + Config(Logger::Ptr); ~Config(); @@ -78,7 +61,7 @@ public: int load_config_from_files(); - std::list get_services(); + std::list get_services(); Options_descriptionPtr get_opt_desc_cmd(); diff --git a/src/dhs.cpp b/src/dhs.cpp index 2105c23..1b3e785 100644 --- a/src/dhs.cpp +++ b/src/dhs.cpp @@ -9,6 +9,8 @@ #include "dhs.h" +#include + using namespace std; @@ -29,7 +31,7 @@ DHS::DHS() * @param _login The login name. * @param _password The corresponding password. */ -DHS::DHS(const string& _protocol, const string& _hostname, const string& _login, const string& _password, const LoggerPtr& _logger, const int _lastupdated, const int _timeout, const int _max_updates_per_timeout) +DHS::DHS(const string& _protocol, const string& _hostname, const string& _login, const string& _password, const Logger::Ptr& _logger, const int _lastupdated, const int _timeout, const int _max_updates_per_timeout) : Timeout(_timeout) , Max_updates_per_timeout(_max_updates_per_timeout) , Updates_within_timeout(1) diff --git a/src/dhs.h b/src/dhs.h index 2c5ad8c..5b30e0a 100644 --- a/src/dhs.h +++ b/src/dhs.h @@ -11,18 +11,19 @@ #define DHS_H #include -#include #include "service.h" #include "logger.h" #include +#include -typedef boost::shared_ptr LoggerPtr; class DHS : public Service { + private: + int Timeout; // TODO: Fix variable naming int Max_updates_per_timeout; @@ -34,9 +35,11 @@ private: public: + typedef boost::shared_ptr Ptr; + DHS(); - DHS(const std::string&, const std::string&, const std::string&, const std::string&, const LoggerPtr&, const int, const int, const int); + DHS(const std::string&, const std::string&, const std::string&, const std::string&, const Logger::Ptr&, const int, const int, const int); ~DHS(); diff --git a/src/logger.cpp b/src/logger.cpp index 0523442..e3499b2 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -10,6 +10,9 @@ #include "logger.h" +#include +#include + namespace po = boost::program_options; using namespace std; @@ -599,7 +602,7 @@ void Logger::print_service_object(const string& message, const string& protocol, * Caught exception while serialize. * @param exception Exception message. */ -void print_exception_serialize(const string& exception) +void Logger::print_exception_serialize(const string& exception) { cout << "Error while trying to serialize Serviceholder object: " << exception << endl; } diff --git a/src/logger.h b/src/logger.h index 471fa4e..caf7083 100644 --- a/src/logger.h +++ b/src/logger.h @@ -10,20 +10,25 @@ #ifndef LOGGER_H #define LOGGER_H -#include -#include - -typedef boost::shared_ptr Options_descriptionPtr; +#include +#include +#include class Logger { + private: + + typedef boost::shared_ptr Options_descriptionPtr; + int Loglevel; bool Syslog; public: + typedef boost::shared_ptr Ptr; + Logger(); ~Logger(); diff --git a/src/main.cpp b/src/main.cpp index ddf1950..8b75bdd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,29 +19,27 @@ #define OBJECT_FILE "/home/bjoern/intranator/bpdyndnsd/objects.ser" #include +#include #include #include - #include +#include +#include + +#include "updater.h" -#include "updater.cpp" #include "config.cpp" +#include "dhs.cpp" #include "logger.cpp" - +#include "ods.cpp" #include "service.cpp" #include "serviceholder.cpp" +#include "updater.cpp" -#include "dhs.cpp" -#include "ods.cpp" - -#include -#include using namespace std; -typedef boost::shared_ptr UpdaterPtr; - -UpdaterPtr updater; +Updater::Ptr updater; bool online_mode = 1; /** @@ -159,7 +157,7 @@ int init_signals() int main(int argc, char *argv[]) { // initialize Updater - UpdaterPtr _updater(new Updater); + Updater::Ptr _updater(new Updater); updater = _updater; _updater.reset(); diff --git a/src/ods.cpp b/src/ods.cpp index fc0b908..5c43c94 100644 --- a/src/ods.cpp +++ b/src/ods.cpp @@ -9,6 +9,8 @@ #include "ods.h" +#include + using namespace std; @@ -29,7 +31,7 @@ ODS::ODS() * @param _login The login name. * @param _password The corresponding password. */ -ODS::ODS(const string& _protocol, const string& _hostname, const string& _login, const string& _password, const LoggerPtr& _logger, const int _lastupdated, const int _timeout, const int _max_updates_per_timeout) +ODS::ODS(const string& _protocol, const string& _hostname, const string& _login, const string& _password, const Logger::Ptr& _logger, const int _lastupdated, const int _timeout, const int _max_updates_per_timeout) : Updates_within_timeout(1) { Timeout = _timeout; diff --git a/src/ods.h b/src/ods.h index c319552..f2a7f75 100644 --- a/src/ods.h +++ b/src/ods.h @@ -11,18 +11,19 @@ #define ODS_H #include -#include #include "service.h" #include "logger.h" #include +#include -typedef boost::shared_ptr LoggerPtr; class ODS : public Service { + private: + int Timeout; // TODO: Fix variable naming int Max_updates_per_timeout; @@ -34,9 +35,11 @@ private: public: + typedef boost::shared_ptr Ptr; + ODS(); - ODS(const std::string&, const std::string&, const std::string&, const std::string&, const LoggerPtr&, const int, const int, const int); + ODS(const std::string&, const std::string&, const std::string&, const std::string&, const Logger::Ptr&, const int, const int, const int); ~ODS(); diff --git a/src/service.cpp b/src/service.cpp index 5bfda4a..d015a26 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -134,7 +134,7 @@ string Service::get_password() * Setter for member Log. * @param _log Shared pointer to Logger object. */ -void Service::set_logger(const LoggerPtr& _log) +void Service::set_logger(const Logger::Ptr& _log) { Log = _log; } @@ -144,7 +144,7 @@ void Service::set_logger(const LoggerPtr& _log) * Getter for member Log. * @return Shared pointer to Logger object. */ -LoggerPtr Service::get_logger() +Logger::Ptr Service::get_logger() { return Log; } diff --git a/src/service.h b/src/service.h index ebdd22f..1b7e8f9 100644 --- a/src/service.h +++ b/src/service.h @@ -10,17 +10,18 @@ #ifndef SERVICE_H #define SERVICE_H +#include "logger.h" + #include #include +#include -#include "logger.h" - -typedef boost::shared_ptr LoggerPtr; class Service { private: + std::string Protocol; std::string Hostname; @@ -35,9 +36,12 @@ private: template void serialize(Archive &, const unsigned int); - LoggerPtr Log; + Logger::Ptr Log; public: + + typedef boost::shared_ptr Ptr; + Service(); virtual ~Service(); @@ -65,8 +69,8 @@ public: void set_actual_ip(const std::string&); std::string get_actual_ip(); - void set_logger(const LoggerPtr&); - LoggerPtr get_logger(); + void set_logger(const Logger::Ptr&); + Logger::Ptr get_logger(); bool operator== (const Service&) const; bool operator!= (const Service&) const; diff --git a/src/serviceholder.cpp b/src/serviceholder.cpp index f2eaa57..4f21ffb 100644 --- a/src/serviceholder.cpp +++ b/src/serviceholder.cpp @@ -9,6 +9,8 @@ #include "serviceholder.h" +#include + using namespace std; @@ -45,7 +47,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(ServicePtr service) +void Serviceholder::add_service(Service::Ptr service) { Hold_services.push_back(service); } @@ -55,7 +57,7 @@ void Serviceholder::add_service(ServicePtr 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 eddb647..bce8006 100644 --- a/src/serviceholder.h +++ b/src/serviceholder.h @@ -13,34 +13,36 @@ #include #include "service.h" +#include "logger.h" #include -#include #include -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); public: + typedef boost::shared_ptr Ptr; + Serviceholder(); - Serviceholder(LoggerPtr); + Serviceholder(Logger::Ptr); ~Serviceholder(); - void add_service(ServicePtr); + void add_service(Service::Ptr); - std::list get_hold_services(); + std::list get_hold_services(); }; #endif diff --git a/src/updater.cpp b/src/updater.cpp index 46f2437..94c6e00 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -9,6 +9,8 @@ #include "updater.h" +#include + using namespace std; /** @@ -17,11 +19,11 @@ using namespace std; Updater::Updater() { // Initialize program wide Logger, at this point we don't know where to log and with which loglevel. - LoggerPtr _log(new Logger); + Logger::Ptr _log(new Logger); Log = _log; // initialize Config - ConfigPtr _config(new Config(Log)); + Config::Ptr _config(new Config(Log)); Conf = _config; } @@ -82,7 +84,7 @@ int Updater::init_config_from_files() * Getter for member Config. * @return Member Config. */ -ConfigPtr Updater::get_config() +Config::Ptr Updater::get_config() { return Conf; } @@ -92,7 +94,7 @@ ConfigPtr Updater::get_config() * Getter for member Logger. * @return Member Logger. */ -LoggerPtr Updater::get_logger() +Logger::Ptr Updater::get_logger() { return Log; } @@ -133,11 +135,11 @@ void Updater::init_log_facility() */ void Updater::update_services() { - list services = this->Conf->get_services(); + list services = this->Conf->get_services(); string ip = "192.168.1.1"; - BOOST_FOREACH(ServicePtr &service, services ) + BOOST_FOREACH(Service::Ptr &service, services ) { service->update(ip); } diff --git a/src/updater.h b/src/updater.h index 63ebce9..cb5371d 100644 --- a/src/updater.h +++ b/src/updater.h @@ -10,22 +10,24 @@ #ifndef UPDATER_H #define UPDATER_H -#include - #include "config.h" #include "logger.h" -// TODO: Global namespace? LoggerPtr will also clash with config.h -typedef boost::shared_ptr ConfigPtr; -typedef boost::shared_ptr LoggerPtr; +#include + class Updater { + private: - ConfigPtr Conf; - LoggerPtr Log; + + Config::Ptr Conf; + Logger::Ptr Log; public: + + typedef boost::shared_ptr Ptr; + Updater(); ~Updater(); @@ -36,9 +38,9 @@ public: int init_config_from_files(); - ConfigPtr get_config(); + Config::Ptr get_config(); - LoggerPtr get_logger(); + Logger::Ptr get_logger(); void reload_config();