A Service is identified through Protocol and Hostname, if they are equal, it is the same service.
* @param password
* @return A pointer to the created Service object.
*/
-ServicePtr Config::create_service(const string &protocol,const string &host, const string &login, const string &password)
+ServicePtr Config::create_service(const string &protocol,const string &hostname, const string &login, const string &password)
{
if(protocol == "dhs")
{
- ServicePtr service_dhs(new DHS(Log,host,login,password));
+ ServicePtr service_dhs(new DHS(protocol,hostname,login,password,Log,0,0,1));
return service_dhs;
}
else if(protocol == "ods")
{
- ServicePtr service_ods(new ODS(Log,host,login,password));
+ ServicePtr service_ods(new ODS(protocol,hostname,login,password,Log,0,0,1));
return service_ods;
}
else
*/
DHS::DHS()
{
+ get_logger()->print_constructor_call("DHS default!!!");
}
* @param _login The login name.
* @param _password The corresponding password.
*/
-DHS::DHS(const LoggerPtr& _log ,const string& _hostname, const string& _login, const string& _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)
{
- Log = _log;
+ Timeout = _timeout;
+ Max_updates_per_timeout = _max_updates_per_timeout;
- Hostname = _hostname;
- Login = _login;
- Password = _password;
+ set_protocol(_protocol);
+ set_hostname(_hostname);
+ set_login(_login);
+ set_password(_password);
+ set_logger(_logger);
+ set_lastupdated(_lastupdated);
- // TODO: setting members from base class correctly.
- this->set_timeout(100);
- this->set_lastupdated(100);
-
- Log->print_constructor_call("DHS");
+ get_logger()->print_constructor_call("DHS");
}
*/
DHS::~DHS()
{
- Log->print_destructor_call("DHS");
+ get_logger()->print_destructor_call("DHS");
}
*/
void DHS::update(const string& ip)
{
- Log->print_update_service("DHS");
+ // if update was successful, we need to set the lastupdated base member.
+ time_t actual_time = time(NULL);
+ set_lastupdated(actual_time);
+
+ get_logger()->print_update_service("DHS");
}
void DHS::serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<Service>(*this);
- ar & Hostname;
- ar & Login;
- ar & Password;
+ ar & Timeout;
+ ar & Max_updates_per_timeout;
+}
+
+
+/**
+ * Setter for member Timeout.
+ * @param _timeout Value to set Timeout to.
+ */
+void DHS::set_timeout(const int _timeout)
+{
+ Timeout = _timeout;
+}
+
+
+/**
+ * Getter for member Timeout.
+ * @return Value of Timeout.
+ */
+int DHS::get_timeout()
+{
+ return Timeout;
+}
+
+
+/**
+ * Setter for member Max_updates_per_timeout.
+ * @param _max_updates_per_timeout Value to set Max_updates_per_timeout to.
+ */
+void DHS::set_max_updates_per_timeout(const int _max_updates_per_timeout)
+{
+ Max_updates_per_timeout = _max_updates_per_timeout;
+}
+
+
+/**
+ * Getter for member Max_updates_per_timeout.
+ * @return Value of Max_updates_per_timeout.
+ */
+int DHS::get_max_updates_per_timeout()
+{
+ return Max_updates_per_timeout;
}
#define DHS_H
#include <string>
+#include <time.h>
+
#include "service.h"
#include "logger.h"
class DHS : public Service
{
private:
- std::string Hostname;
- std::string Login;
- std::string Password;
-
- LoggerPtr Log;
+ int Timeout;
+ int Max_updates_per_timeout;
friend class boost::serialization::access;
template<class Archive>
DHS();
- DHS(const LoggerPtr&, const std::string&, const std::string&, const std::string&);
+ DHS(const std::string&, const std::string&, const std::string&, const std::string&, const LoggerPtr&, const int, const int, const int);
~DHS();
+ void set_timeout(const int);
+ int get_timeout();
+
+ void set_max_updates_per_timeout(const int);
+ int get_max_updates_per_timeout();
+
void update(const std::string&);
};
using namespace std;
typedef boost::shared_ptr<Updater> UpdaterPtr;
-typedef boost::shared_ptr<Service> ServicePtr;
UpdaterPtr updater;
bool online_mode = 1;
// child starts here
}
-
// service processing starts here
do
{
*/
ODS::ODS()
{
+ get_logger()->print_constructor_call("ODS default!!!");
}
* @param _login The login name.
* @param _password The corresponding password.
*/
-ODS::ODS(const LoggerPtr& _log, const string& _hostname, const string& _login, const string& _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)
{
- Log = _log;
+ Timeout = _timeout;
+ Max_updates_per_timeout = _max_updates_per_timeout;
- Hostname = _hostname;
- Login = _login;
- Password = _password;
+ set_protocol(_protocol);
+ set_hostname(_hostname);
+ set_login(_login);
+ set_password(_password);
+ set_logger(_logger);
+ set_lastupdated(_lastupdated);
- // TODO: setting members from base class correctly.
- this->set_timeout(100);
- this->set_lastupdated(100);
-
- Log->print_constructor_call("ODS");
+ get_logger()->print_constructor_call("ODS");
}
*/
ODS::~ODS()
{
- Log->print_destructor_call("ODS");
+ get_logger()->print_destructor_call("ODS");
}
*/
void ODS::update(const string& ip)
{
- Log->print_update_service("ODS");
+ // if update was successful, we need to set the lastupdated base member.
+ time_t actual_time = time(NULL);
+ set_lastupdated(actual_time);
+
+ get_logger()->print_update_service("ODS");
}
void ODS::serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<Service>(*this);
- ar & Hostname;
- ar & Login;
- ar & Password;
+ ar & Timeout;
+ ar & Max_updates_per_timeout;
+}
+
+
+/**
+ * Setter for member Timeout.
+ * @param _timeout Value to set Timeout to.
+ */
+void ODS::set_timeout(const int _timeout)
+{
+ Timeout = _timeout;
+}
+
+
+/**
+ * Getter for member Timeout.
+ * @return Value of Timeout.
+ */
+int ODS::get_timeout()
+{
+ return Timeout;
+}
+
+
+/**
+ * Setter for member Max_updates_per_timeout.
+ * @param _max_updates_per_timeout Value to set Max_updates_per_timeout to.
+ */
+void ODS::set_max_updates_per_timeout(const int _max_updates_per_timeout)
+{
+ Max_updates_per_timeout = _max_updates_per_timeout;
+}
+
+
+/**
+ * Getter for member Max_updates_per_timeout.
+ * @return Value of Max_updates_per_timeout.
+ */
+int ODS::get_max_updates_per_timeout()
+{
+ return Max_updates_per_timeout;
}
#define ODS_H
#include <string>
+#include <time.h>
+
#include "service.h"
#include "logger.h"
class ODS : public Service
{
-
private:
-
- std::string Hostname;
- std::string Login;
- std::string Password;
-
- LoggerPtr Log;
+ int Timeout;
+ int Max_updates_per_timeout;
friend class boost::serialization::access;
template<class Archive>
ODS();
- ODS(const LoggerPtr&, const std::string&, const std::string&, const std::string&);
+ ODS(const std::string&, const std::string&, const std::string&, const std::string&, const LoggerPtr&, const int, const int, const int);
~ODS();
- void update(const std::string&);
+ void set_timeout(const int);
+ int get_timeout();
+
+ void set_max_updates_per_timeout(const int);
+ int get_max_updates_per_timeout();
+ void update(const std::string&);
};
#endif
*/
Service::Service()
{
-
}
*/
Service::~Service()
{
-
}
template<class Archive>
void Service::serialize(Archive & ar, const unsigned int version)
{
+ // protocol and hostname are the unique identifier for each service.
+ ar & Protocol;
+ ar & Hostname;
+ // lastupdated must also be serialized, cause this is essential info of each service.
ar & Lastupdated;
- ar & Timeout;
+}
+
+
+/**
+ * Setter for member Protocol.
+ * @param _protocol Value to set Protocol to.
+ */
+void Service::set_protocol(const string& _protocol)
+{
+ Protocol = _protocol;
+}
+
+
+/**
+ * Getter for memeber Protocol.
+ * @return Value of member Protocol.
+ */
+string Service::get_protocol()
+{
+ return Protocol;
+}
+
+
+/**
+ * Setter for member Hostname.
+ * @param _hostname Value to set Hostname to.
+ */
+void Service::set_hostname(const string& _hostname)
+{
+ Hostname = _hostname;
+}
+
+
+/**
+ * Getter for member Hostname.
+ * @return Value of member Hostname.
+ */
+string Service::get_hostname()
+{
+ return Hostname;
+}
+
+
+/**
+ * Setter for member Login.
+ * @param _login Value to set Login to.
+ */
+void Service::set_login(const string& _login)
+{
+ Login = _login;
+}
+
+
+/**
+ * Getter for member Login.
+ * @return Value of member Login.
+ */
+string Service::get_login()
+{
+ return Login;
+}
+
+
+/**
+ * Setter for member Password.
+ * @param _password Value to set Password to.
+ */
+void Service::set_password(const string& _password)
+{
+ Password = _password;
+}
+
+
+/**
+ * Getter for member Password.
+ * @return Value of member Password.
+ */
+string Service::get_password()
+{
+ return Password;
+}
+
+
+/**
+ * Setter for member Log.
+ * @param _log Shared pointer to Logger object.
+ */
+void Service::set_logger(const LoggerPtr& _log)
+{
+ Log = _log;
+}
+
+
+/**
+ * Getter for member Log.
+ * @return Shared pointer to Logger object.
+ */
+LoggerPtr Service::get_logger()
+{
+ return Log;
}
/**
- * Setter for member Timeout.
- * @param _timeout Value to set Timeout to.
+ * Overloading of comparison operator.
+ * @param other Reference to other Service object.
+ * @return True if they equal, false if not.
*/
-void Service::set_timeout(const int _timeout)
+bool Service::operator== (const Service& other) const
{
- Timeout = _timeout;
+ if ( ( this->Protocol == other.Protocol ) && ( this->Hostname == other.Hostname ) )
+ return true;
+ return false;
}
/**
- * Getter for member Timeout.
- * @return Value of member Timeout.
+ * Overloading of disparate operator.
+ * @param other Reference to other Service object.
+ * @return True if they differ, false if they are equal.
*/
-int Service::get_timeout()
+bool Service::operator!= (const Service& other) const
{
- return Timeout;
+ return !(*this == other);
}
/** @file
- * @brief The abstract service interface. This class represents all services.
+ * @brief The abstract service class. This class represents all services.
*
*
*
#include <boost/serialization/array.hpp>
+#include "logger.h"
+
+typedef boost::shared_ptr<Logger> LoggerPtr;
+
class Service
{
private:
+ std::string Protocol;
+ std::string Hostname;
+ std::string Login;
+ std::string Password;
+
+ LoggerPtr Log;
+
int Lastupdated;
- int Timeout;
friend class boost::serialization::access;
template<class Archive>
virtual void update(const std::string&)=0;
+ void set_protocol(const std::string&);
+ std::string get_protocol();
+
+ void set_hostname(const std::string&);
+ std::string get_hostname();
+
+ void set_login(const std::string&);
+ std::string get_login();
+
+ void set_password(const std::string&);
+ std::string get_password();
+
+ void set_logger(const LoggerPtr&);
+ LoggerPtr get_logger();
+
void set_lastupdated(const int);
int get_lastupdated();
- void set_timeout(const int);
- int get_timeout();
+ bool operator== (const Service&) const;
+ bool operator!= (const Service&) const;
};
#endif