#include "config.h"
/**
- * Default Constructor. Available command line arguments with their default values are defined here.
+ * Default Constructor. Available command line and config file options with their default values are defined here.
*/
Config::Config()
- : Daemon_mode(true)
+ : Daemon_mode(false)
, Loglevel(0)
- , Syslog(true)
+ , Syslog(false)
{
// Define valid command line parameters
Opt_desc_cmd = new po::options_description("Command line options");
delete Opt_desc_cmd;
delete Opt_desc_conf_main;
delete Opt_desc_conf_service;
+
+ cout << "Config destructor!!!" << endl;
}
* @param argv[] Pointer to command line argument array given to main.
* @return 0 if all is fine,
*/
-int Config::parse_cmd_line(int argc, char *argv[])
+const int Config::parse_cmd_line(int argc, char *argv[])
{
try
{
* @param password
* @return A pointer to the created Service object.
*/
-Service * Config::create_service(string protocol,string host, string login, string password)
+ServicePtr Config::create_service(const string &protocol,const string &host, const string &login, const string &password)
{
- Service * service;
if(protocol == "dhs")
{
- service = new DHS(host,login,password);
+ ServicePtr service_dhs(new DHS(host,login,password));
+ return service_dhs;
}
else if(protocol == "ods")
{
- service = new ODS(host,login,password);
+ ServicePtr service_ods(new ODS(host,login,password));
+ return service_ods;
+ }
+ else
+ {
+ // TODO: error handling for unknown protocol
}
- return service;
}
* @param config_path The path to the config directory.
* @return 0 if all is fine.
*/
-int Config::load_config_from_files(string config_path)
+const int Config::load_config_from_files(const string& config_path)
{
fs::path full_config_path = fs::system_complete(fs::path(config_path));
* Getter method for Service list member.
* @return Pointer to a list of Service's.
*/
-list<Service*> Config::get_services()
+list<ServicePtr> Config::get_services()
{
return this->Services;
}
* Prints out the programm name and the given version string on stdout.
* @param version Version string.
*/
-void Config::print_version(string version)
+void Config::print_version(const string& version)
{
cout << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << version << endl;
}
#include <boost/foreach.hpp>
#include <boost/filesystem.hpp>
#include <boost/regex.hpp>
+#include <boost/shared_ptr.hpp>
#include <string>
#include <iostream>
using namespace std;
+typedef boost::shared_ptr<Service> ServicePtr;
+
class Config
{
private:
po::options_description *Opt_desc_conf_main;
po::options_description *Opt_desc_conf_service;
- list<Service*> Services;
+ list<ServicePtr> Services;
bool Daemon_mode;
string Logfile;
int Loglevel;
bool Syslog;
- Service * create_service(string,string,string,string);
+ ServicePtr create_service(const string&,const string&,const string&,const string&);
public:
Config();
~Config();
- int parse_cmd_line(int, char **);
+ const int parse_cmd_line(int, char **);
- int load_config_from_files(string);
+ const int load_config_from_files(const string&);
void print_usage();
- void print_version(string);
+ void print_version(const string&);
- list<Service*> get_services();
+ list<ServicePtr> get_services();
};
#endif
* @param _login The login name.
* @param _password The corresponding password.
*/
-DHS::DHS(string _hostname, string _login, string _password)
+DHS::DHS(const string& _hostname, const string& _login, const string& _password)
{
Hostname = _hostname;
Login = _login;
*/
DHS::~DHS()
{
+ cout << "DHS destructor!!!" << endl;
}
* Service update method which should implement the corresponding service protocol.
* @param ip The new ip to set for the hostname.
*/
-void DHS::update(string ip)
+void DHS::update(const string& ip)
{
cout << "Running Update for Service DHS" << endl;
cout << "Hostname: " << Hostname << endl;
public:
DHS();
- DHS(string,string,string);
+ DHS(const string&, const string&, const string&);
~DHS();
- void update(string);
+ void update(const string&);
};
#endif
using namespace std;
+typedef boost::shared_ptr<Config> ConfigPtr;
+typedef boost::shared_ptr<Updater> UpdaterPtr;
+
/**
* @brief The main part.
* @param argc Number of arguments
int main(int argc, char *argv[])
{
// Initialize Config class and get the command line parameters
- Config * config = new Config;
+ ConfigPtr config(new Config);
int ret_val = config->parse_cmd_line(argc,argv);
if(ret_val == 1)
{
}
// initialize Updater
- Updater * updater = new Updater(config);
+ UpdaterPtr updater(new Updater(config));
updater->update_services();
return 0;
* @param _login The login name.
* @param _password The corresponding password.
*/
-ODS::ODS(string _hostname, string _login, string _password)
+ODS::ODS(const string& _hostname, const string& _login, const string& _password)
{
Hostname = _hostname;
Login = _login;
*/
ODS::~ODS()
{
+ cout << "ODS destructor!!!" << endl;
}
* Service update method which should implement the corresponding service protocol.
* @param ip The new ip to set for the hostname.
*/
-void ODS::update(string ip)
+void ODS::update(const string& ip)
{
cout << "Running Update for Service ODS" << endl;
cout << "Hostname: " << Hostname << endl;
public:
ODS();
- ODS(string,string,string);
+ ODS(const string&, const string&, const string&);
~ODS();
- void update(string);
+ void update(const string&);
};
#endif
#include "service.h"
+/**
+ * Default Constructor
+ */
Service::Service()
{
}
+/**
+ * Default Destructor
+ */
Service::~Service()
{
}
virtual ~Service();
- virtual void update(string)=0;
+ virtual void update(const string&)=0;
};
* Default constructor which initializes the member Conf.
*/
Updater::Updater()
- : Conf(NULL)
{
}
* Constructor.
* @param _conf A pointer to a Config object.
*/
-Updater::Updater(Config* _conf)
+Updater::Updater(ConfigPtr _conf)
{
Conf = _conf;
}
*/
Updater::~Updater()
{
- Conf = NULL;
+ cout << "Updater destructor!!!" << endl;
}
* Setter for member Conf.
* @param _conf
*/
-void Updater::set_config(Config* _conf)
+void Updater::set_config(ConfigPtr _conf)
{
Conf = _conf;
}
* Getter for member Conf.
* @return Conf.
*/
-Config* Updater::get_config()
+ConfigPtr Updater::get_config()
{
return Conf;
}
*/
void Updater::update_services()
{
- list<Service*> services = this->Conf->get_services();
+ list<ServicePtr> services = this->Conf->get_services();
string ip = "192.168.1.1";
- BOOST_FOREACH( Service * service, services )
+ BOOST_FOREACH( ServicePtr service, services )
{
service->update(ip);
}
#include "config.h"
+typedef boost::shared_ptr<Config> ConfigPtr;
+
class Updater
{
private:
- Config* Conf;
+ ConfigPtr Conf;
public:
Updater();
- Updater(Config*);
+ Updater(ConfigPtr);
~Updater();
- void set_config(Config*);
+ void set_config(ConfigPtr);
- Config* get_config();
+ ConfigPtr get_config();
void update_services();
};