Separated Service update into update and perform_update.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 11 Aug 2009 15:27:43 +0000 (17:27 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 11 Aug 2009 15:27:43 +0000 (17:27 +0200)
Improved logging.
Prepared support for IPv6.

src/dhs.cpp
src/dhs.h
src/iphelper.cpp
src/logger.cpp
src/logger.h

index 21fe15a..8d8139c 100644 (file)
@@ -59,11 +59,29 @@ DHS::~DHS()
  */
 void DHS::update(const string& ip)
 {
-    // if update was successful, we need to set the lastupdated base member.
-    time_t actual_time = time(NULL);
-    set_lastupdated(actual_time);
+    if ( this->get_actual_ip() != ip )
+    {
+        this->get_logger()->print_update_service("DHS");
+
+        if ( perform_update(ip) == 0 )
+        {
+            // if update was successful, we need to set the Lastupdated and ActualIP base member.
+            this->set_lastupdated(time(NULL));
+            this->set_actual_ip(ip);
+            this->get_logger()->print_update_service_successful("DHS");
+        }
+    }
+}
+
 
-    get_logger()->print_update_service("DHS");
+/**
+ * Performs the Service update.
+ * @param ip IP Address to set.
+ * @return 0 if all is fine, -1 otherwise.
+ */
+int DHS::perform_update(const std::string& ip)
+{
+    return 0;
 }
 
 
index 6ca1384..feb2fd0 100644 (file)
--- a/src/dhs.h
+++ b/src/dhs.h
@@ -49,6 +49,8 @@ public:
     int get_max_updates_within_timeout() const;
 
     void update(const std::string&);
+
+    int perform_update(const std::string&);
 };
 
 #endif
index 9e9bfff..bc114ed 100644 (file)
@@ -21,8 +21,8 @@ IPHelper::IPHelper()
     : Hostname("")
     , WebcheckUrl("")
     , WebcheckUrlAlt("")
-    , Log(new Logger)
     , UseIPv6(false)
+    , Log(new Logger)
 {
 }
 
@@ -34,8 +34,8 @@ IPHelper::IPHelper(Logger::Ptr _log)
     : Hostname("")
     , WebcheckUrl("")
     , WebcheckUrlAlt("")
-    , Log(new Logger)
     , UseIPv6(false)
+    , Log(new Logger)
 {
     Log = _log;
 }
index d8c2bc1..37d994c 100644 (file)
@@ -744,3 +744,14 @@ void Logger::print_error_hostname_to_ip(const std::string& exception, const std:
         log_error(msg.str());
     }
 }
+
+
+void Logger::print_update_service_successful(const std::string& service)
+{
+    if ( 0 <= Loglevel )
+    {
+        ostringstream msg;
+        msg << "Updated service successful: " << service << endl;
+        log_error(msg.str());
+    }
+}
index 1eb88db..cc767c7 100644 (file)
@@ -130,6 +130,8 @@ public:
     void print_own_ip(const std::string&, const std::string&) const;
 
     void print_error_hostname_to_ip(const std::string&, const std::string&) const;
+
+    void print_update_service_successful(const std::string&);
 };
 
 #endif