#include "config.h"
+// 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")
+
namespace po = boost::program_options;
namespace fs = boost::filesystem;
/**
+ * This function serializes all Service objects in Services into a specified file.
+ * @return 0 if all is fine, -1 otherwise.
+ */
+int Config::serialize_services()
+{
+ //TODO: error handling
+
+ cout << "starting serialize objects" << endl;
+ // serialize service objects
+ ofstream ofs("/home/bjoern/intranator/bpdyndnsd/objects.ser");
+ boost::archive::text_oarchive oa(ofs);
+
+ BOOST_FOREACH(ServicePtr service, Services)
+ {
+ Service* ptr = service.get();
+ oa << BOOST_SERIALIZATION_NVP(ptr);
+ }
+ ofs.close();
+
+ return 0;
+}
+
+
+/**
* Parses the command line arguments and does the needed actions.
* @param argc Command line argument number given to main.
* @param argv[] Pointer to command line argument array given to main.
#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 <string>
#include <iostream>
~Config();
+ int serialize_services();
+
int parse_cmd_line(int, char **);
int load_config_from_files();
using namespace std;
+
+/**
+ * Default Constructor, needed for object serialization.
+ */
+DHS::DHS()
+{
+}
+
+
/**
* Constructor.
* @param _hostname The hostname to update
Login = _login;
Password = _password;
+ // TODO: setting members from base class correctly.
+ this->set_timeout(100);
+ this->set_lastupdated(100);
+
Log->print_constructor_call("DHS");
}
{
Log->print_update_service("DHS");
}
+
+
+/**
+ * Serialize function needed by boost/serialization to define which members should be stored as the object state.
+ * @param ar Archive
+ * @param version Version
+ */
+template<class Archive>
+void DHS::serialize(Archive & ar, const unsigned int version)
+{
+ ar & boost::serialization::base_object<Service>(*this);
+ ar & Hostname;
+ ar & Login;
+ ar & Password;
+}
#include "service.h"
#include "logger.h"
+#include <boost/serialization/array.hpp>
+
typedef boost::shared_ptr<Logger> LoggerPtr;
class DHS : public Service
{
-
private:
-
std::string Hostname;
std::string Login;
std::string Password;
LoggerPtr Log;
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive &, const unsigned int);
+
public:
+ DHS();
+
DHS(const LoggerPtr&, const std::string&, const std::string&, const std::string&);
~DHS();
void update(const std::string&);
-
};
#endif
#include <sys/types.h>
#include <signal.h>
-
using namespace std;
typedef boost::shared_ptr<Updater> UpdaterPtr;
+typedef boost::shared_ptr<Service> ServicePtr;
UpdaterPtr updater;
bool online_mode = 1;
void terminate(int param)
{
updater->get_logger()->print_caught_sigterm();
+
+ // unfortunately we can't call serialize_services in any destructor
+ // cause some singleton are already destroyed !?!
+ updater->get_config()->serialize_services();
updater.reset();
exit(0);
}
+
/**
* Signal SIGUSR1 caught, switching to offline mode.
* @param param Parameter from the signal interface.
}while ( updater->get_config()->get_daemon_mode() == 1 );
+
+ // serialize services
+ updater->get_config()->serialize_services();
+
return 0;
}
using namespace std;
+
+/**
+ * Default Constructor, needed for object serialization.
+ */
+ODS::ODS()
+{
+}
+
+
/**
* Constructor.
* @param _hostname The hostname to update
Login = _login;
Password = _password;
+ // TODO: setting members from base class correctly.
+ this->set_timeout(100);
+ this->set_lastupdated(100);
+
Log->print_constructor_call("ODS");
}
{
Log->print_update_service("ODS");
}
+
+
+/**
+ * Serialize function needed by boost/serialization to define which members should be stored as the object state.
+ * @param ar Archive
+ * @param version Version
+ */
+template<class Archive>
+void ODS::serialize(Archive & ar, const unsigned int version)
+{
+ ar & boost::serialization::base_object<Service>(*this);
+ ar & Hostname;
+ ar & Login;
+ ar & Password;
+}
#include "service.h"
#include "logger.h"
+#include <boost/serialization/array.hpp>
+
typedef boost::shared_ptr<Logger> LoggerPtr;
class ODS : public Service
LoggerPtr Log;
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive &, const unsigned int);
+
public:
+ ODS();
+
ODS(const LoggerPtr&, const std::string&, const std::string&, const std::string&);
~ODS();
/** @file
- * @brief The abstract service interface. This class represents all services.
+ * @brief The abstract service class. This class represents all services.
*
*
*
#include "service.h"
+
/**
* Default Constructor
*/
}
+
/**
* Default Destructor
*/
}
+/**
+ * Although this is an abstract class, we need the serialize function that we can serialize derived classes through a Service *.
+ * @param ar Archive.
+ * @param version Version.
+ */
+template<class Archive>
+void Service::serialize(Archive & ar, const unsigned int version)
+{
+ ar & Lastupdated;
+ ar & Timeout;
+}
+
+
+/**
+ * Setter for member Lastupdated.
+ * @param _lastupdated Value to set Lastupdated to.
+ */
+void Service::set_lastupdated(const int _lastupdated)
+{
+ Lastupdated = _lastupdated;
+}
+
+
+/**
+ * Getter for member Lastupdated.
+ * @return Value of member Lastupdated.
+ */
+int Service::get_lastupdated()
+{
+ return Lastupdated;
+}
+
+
+/**
+ * Setter for member Timeout.
+ * @param _timeout Value to set Timeout to.
+ */
+void Service::set_timeout(const int _timeout)
+{
+ Timeout = _timeout;
+}
+
+
+/**
+ * Getter for member Timeout.
+ * @return Value of member Timeout.
+ */
+int Service::get_timeout()
+{
+ return Timeout;
+}
#include <string>
+#include <boost/serialization/array.hpp>
+
class Service
{
+private:
+ int Lastupdated;
+ int Timeout;
+
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive &, const unsigned int);
+
public:
Service();
virtual void update(const std::string&)=0;
+ void set_lastupdated(const int);
+ int get_lastupdated();
+
+ void set_timeout(const int);
+ int get_timeout();
};
#endif
#include "updater.h"
-#include <boost/foreach.hpp>
-
using namespace std;
/**
}
+/**
+ * Initialize the logging facility with loglevel and syslog.
+ */
void Updater::init_log_facility()
{
Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog());
#ifndef UPDATER_H
#define UPDATER_H
+#include <boost/foreach.hpp>
+
#include "config.h"
#include "logger.h"