Corrected typedef's in header files.
#include "config.h"
+#include "serviceholder.h"
+#include "dhs.h"
+#include "ods.h"
+
+#include <time.h>
+#include <iostream>
+#include <fstream>
+
+#include <boost/foreach.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/regex.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/archive/archive_exception.hpp>
+#include <boost/serialization/export.hpp>
+#include <boost/serialization/shared_ptr.hpp>
+
// 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")
/**
* 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)
// 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);
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();
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<ServicePtr> _old_services = service_holder->get_hold_services();
+ list<Service::Ptr> _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 )
{
//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
* @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;
}
}
// 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);
* Getter method for Service list member.
* @return Pointer to a list of Service's.
*/
-list<ServicePtr> Config::get_services()
+list<Service::Ptr> Config::get_services()
{
return this->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;
}
* 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;
}
* 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;
}
*/
void Config::delete_services()
{
- BOOST_FOREACH( ServicePtr service, Services )
+ BOOST_FOREACH( Service::Ptr service, Services )
{
service.reset();
}
#ifndef CONFIG_H
#define CONFIG_H
-// TODO: Only include needed header files in "config.h".
-// Include the rest in config.cpp
-#include <boost/program_options.hpp>
-#include <boost/foreach.hpp>
-#include <boost/filesystem.hpp>
-#include <boost/regex.hpp>
-#include <boost/shared_ptr.hpp>
-#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>
-#include <fstream>
-
-#include <time.h>
#include "service.h"
#include "logger.h"
-#include "serviceholder.h"
-#include "dhs.h"
-#include "ods.h"
+#include <boost/program_options.hpp>
+#include <boost/shared_ptr.hpp>
-// TODO: What about putting this in the Logger/Service namespace instead of the global one?
-typedef boost::shared_ptr<Service> ServicePtr;
-typedef boost::shared_ptr<Logger> LoggerPtr;
-typedef boost::shared_ptr<Serviceholder> ServiceholderPtr;
-typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr;
class Config
{
-
private:
+
+ typedef boost::shared_ptr<boost::program_options::options_description> 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<ServicePtr> Services; // Represents all active Services.
- std::list<ServicePtr> Old_services; // Represents all old Services where the timeout isn't expired (in case the same Service is redefined).
+ std::list<Service::Ptr> Services; // Represents all active Services.
+ std::list<Service::Ptr> 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<Config> Ptr;
+
+ Config(Logger::Ptr);
~Config();
int load_config_from_files();
- std::list<ServicePtr> get_services();
+ std::list<Service::Ptr> get_services();
Options_descriptionPtr get_opt_desc_cmd();
#include "dhs.h"
+#include <time.h>
+
using namespace std;
* @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)
#define DHS_H
#include <string>
-#include <time.h>
#include "service.h"
#include "logger.h"
#include <boost/serialization/array.hpp>
+#include <boost/shared_ptr.hpp>
-typedef boost::shared_ptr<Logger> LoggerPtr;
class DHS : public Service
{
+
private:
+
int Timeout;
// TODO: Fix variable naming
int Max_updates_per_timeout;
public:
+ typedef boost::shared_ptr<DHS> 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();
#include "logger.h"
+#include <syslog.h>
+#include <sstream>
+
namespace po = boost::program_options;
using namespace std;
* 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;
}
#ifndef LOGGER_H
#define LOGGER_H
-#include <syslog.h>
-#include <sstream>
-
-typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr;
+#include <string>
+#include <boost/program_options.hpp>
+#include <boost/shared_ptr.hpp>
class Logger
{
+
private:
+
+ typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr;
+
int Loglevel;
bool Syslog;
public:
+ typedef boost::shared_ptr<Logger> Ptr;
+
Logger();
~Logger();
#define OBJECT_FILE "/home/bjoern/intranator/bpdyndnsd/objects.ser"
#include <iostream>
+#include <fstream>
#include <list>
#include <string>
-
#include <boost/foreach.hpp>
+#include <sys/types.h>
+#include <signal.h>
+
+#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 <sys/types.h>
-#include <signal.h>
using namespace std;
-typedef boost::shared_ptr<Updater> UpdaterPtr;
-
-UpdaterPtr updater;
+Updater::Ptr updater;
bool online_mode = 1;
/**
int main(int argc, char *argv[])
{
// initialize Updater
- UpdaterPtr _updater(new Updater);
+ Updater::Ptr _updater(new Updater);
updater = _updater;
_updater.reset();
#include "ods.h"
+#include <time.h>
+
using namespace std;
* @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;
#define ODS_H
#include <string>
-#include <time.h>
#include "service.h"
#include "logger.h"
#include <boost/serialization/array.hpp>
+#include <boost/shared_ptr.hpp>
-typedef boost::shared_ptr<Logger> LoggerPtr;
class ODS : public Service
{
+
private:
+
int Timeout;
// TODO: Fix variable naming
int Max_updates_per_timeout;
public:
+ typedef boost::shared_ptr<ODS> 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();
* 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;
}
* Getter for member Log.
* @return Shared pointer to Logger object.
*/
-LoggerPtr Service::get_logger()
+Logger::Ptr Service::get_logger()
{
return Log;
}
#ifndef SERVICE_H
#define SERVICE_H
+#include "logger.h"
+
#include <string>
#include <boost/serialization/array.hpp>
+#include <boost/shared_ptr.hpp>
-#include "logger.h"
-
-typedef boost::shared_ptr<Logger> LoggerPtr;
class Service
{
private:
+
std::string Protocol;
std::string Hostname;
template<class Archive>
void serialize(Archive &, const unsigned int);
- LoggerPtr Log;
+ Logger::Ptr Log;
public:
+
+ typedef boost::shared_ptr<Service> Ptr;
+
Service();
virtual ~Service();
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;
#include "serviceholder.h"
+#include <boost/serialization/list.hpp>
+
using namespace std;
* 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);
}
* Needed after deserialization to get the valid list of Service* back.
* @return The list of Service*.
*/
-std::list<ServicePtr> Serviceholder::get_hold_services()
+std::list<Service::Ptr> Serviceholder::get_hold_services()
{
return Hold_services;
}
#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<Service> ServicePtr;
-
class Serviceholder
{
+
private:
+
friend class boost::serialization::access;
- std::list<ServicePtr> Hold_services;
+ std::list<Service::Ptr> Hold_services;
template<class Archive>
void serialize(Archive &, const unsigned int);
public:
+ typedef boost::shared_ptr<Serviceholder> Ptr;
+
Serviceholder();
- Serviceholder(LoggerPtr);
+ Serviceholder(Logger::Ptr);
~Serviceholder();
- void add_service(ServicePtr);
+ void add_service(Service::Ptr);
- std::list<ServicePtr> get_hold_services();
+ std::list<Service::Ptr> get_hold_services();
};
#endif
#include "updater.h"
+#include <boost/foreach.hpp>
+
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;
}
* Getter for member Config.
* @return Member Config.
*/
-ConfigPtr Updater::get_config()
+Config::Ptr Updater::get_config()
{
return Conf;
}
* Getter for member Logger.
* @return Member Logger.
*/
-LoggerPtr Updater::get_logger()
+Logger::Ptr Updater::get_logger()
{
return Log;
}
*/
void Updater::update_services()
{
- list<ServicePtr> services = this->Conf->get_services();
+ list<Service::Ptr> 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);
}
#ifndef UPDATER_H
#define UPDATER_H
-#include <boost/foreach.hpp>
-
#include "config.h"
#include "logger.h"
-// TODO: Global namespace? LoggerPtr will also clash with config.h
-typedef boost::shared_ptr<Config> ConfigPtr;
-typedef boost::shared_ptr<Logger> LoggerPtr;
+#include <boost/shared_ptr.hpp>
+
class Updater
{
+
private:
- ConfigPtr Conf;
- LoggerPtr Log;
+
+ Config::Ptr Conf;
+ Logger::Ptr Log;
public:
+
+ typedef boost::shared_ptr<Updater> Ptr;
+
Updater();
~Updater();
int init_config_from_files();
- ConfigPtr get_config();
+ Config::Ptr get_config();
- LoggerPtr get_logger();
+ Logger::Ptr get_logger();
void reload_config();