PingInterval class changed from template to regular class to make it simple.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 28 Apr 2011 09:39:49 +0000 (11:39 +0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 28 Apr 2011 09:39:49 +0000 (11:39 +0200)
src/CMakeLists.txt
src/host/pinginterval.cpp [new file with mode: 0644]
src/host/pinginterval.h
src/host/pingscheduler.h

index 82dbcbe..7e8550b 100644 (file)
@@ -30,6 +30,7 @@ set(SOURCES
     dns/timetolive.cpp
     host/boostpinger.cpp
     host/hoststatusanalyzer.cpp
+    host/pinginterval.cpp
     host/pingscheduler.cpp
     icmp/icmpdestinationunreachablemessage.cpp
     icmp/icmpechoreplymessage.cpp
diff --git a/src/host/pinginterval.cpp b/src/host/pinginterval.cpp
new file mode 100644 (file)
index 0000000..170b83f
--- /dev/null
@@ -0,0 +1,58 @@
+#include "host/pinginterval.h"
+
+#include <boost/assert.hpp>
+
+//-----------------------------------------------------------------------------
+// PingInterval
+//-----------------------------------------------------------------------------
+
+PingInterval::PingInterval(
+        PingIntervalType interval
+) :
+    OriginalInterval( interval ),
+    Interval( interval )
+{
+    BOOST_ASSERT( 0 < interval );
+}
+
+PingInterval::~PingInterval()
+{
+}
+
+PingInterval::operator PingIntervalType()
+{
+    BOOST_ASSERT( 0 < Interval );
+
+    return Interval;
+}
+
+void PingInterval::back_to_original()
+{
+    Interval = OriginalInterval;
+
+    BOOST_ASSERT( 0 < Interval );
+}
+
+void PingInterval::speed_up()
+{
+    BOOST_ASSERT( 0 < Interval );
+
+    if ( can_speed_up() )
+    {
+        Interval = Interval / 2;
+    }
+
+    if ( Interval < 1 )
+    {
+        Interval = 1;
+    }
+
+    BOOST_ASSERT( 0 < Interval );
+}
+
+bool PingInterval::can_speed_up() const
+{
+    PingIntervalType half_original = OriginalInterval / 2;
+
+    return ( Interval > half_original );
+}
index 6e0a480..1fe84e0 100644 (file)
@@ -1,7 +1,11 @@
 #ifndef PINGINTERVAL_H
 #define PINGINTERVAL_H
 
-#include <boost/assert.hpp>
+//-----------------------------------------------------------------------------
+// PingIntervalType
+//-----------------------------------------------------------------------------
+
+typedef long PingIntervalType;
 
 //-----------------------------------------------------------------------------
 // PingInterval
  * with helper methods to encapsulate interval computation.
  * Scope: one object per host.
  */
-template<typename T>
 class PingInterval
 {
 public:
-    PingInterval( T interval );
+    PingInterval( PingIntervalType interval );
     ~PingInterval();
 
-    operator T();
+    operator PingIntervalType();
 
     void back_to_original();
     void speed_up();
@@ -28,68 +31,9 @@ private:
     bool can_speed_up() const;
 
 private:
-    const T OriginalInterval;
-    T Interval;
+    const PingIntervalType OriginalInterval;
+    PingIntervalType Interval;
 
 };
 
-
-template<typename T>
-    PingInterval<T>::PingInterval(
-            T interval
-    ) :
-        OriginalInterval( interval ),
-        Interval( interval )
-    {
-        BOOST_ASSERT( 0 < interval );
-    }
-
-template<typename T>
-    PingInterval<T>::~PingInterval()
-    {
-    }
-
-template<typename T>
-    PingInterval<T>::operator T()
-    {
-        BOOST_ASSERT( 0 < Interval );
-
-        return Interval;
-    }
-
-template<typename T>
-    void PingInterval<T>::back_to_original()
-    {
-        Interval = OriginalInterval;
-
-        BOOST_ASSERT( 0 < Interval );
-    }
-
-template<typename T>
-    void PingInterval<T>::speed_up()
-    {
-        BOOST_ASSERT( 0 < Interval );
-
-        if ( can_speed_up() )
-        {
-            Interval = Interval / 2;
-        }
-
-        if ( Interval < 1 )
-        {
-            Interval = 1;
-        }
-
-        BOOST_ASSERT( 0 < Interval );
-    }
-
-template<typename T>
-    bool PingInterval<T>::can_speed_up() const
-    {
-        T half_original = OriginalInterval / 2;
-
-        return ( Interval > half_original );
-    }
-
-
 #endif /* PINGINTERVAL_H */
index 88d7603..345e995 100644 (file)
@@ -50,7 +50,7 @@ private:
     std::string LocalNetworkInterfaceName;
     boost::asio::deadline_timer NextPingTimer;
     boost::posix_time::ptime TimeSentLastPing;
-    PingInterval<long> PingIntervalInSec;
+    PingInterval PingIntervalInSec;
     DnsResolver IpList;
     HostStatusAnalyzer HostAnalyzer;