From f4fc89579a9ed14930322a9c93e44486225d41fb Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Thu, 28 Apr 2011 11:39:49 +0200 Subject: [PATCH] PingInterval class changed from template to regular class to make it simple. --- src/CMakeLists.txt | 1 + src/host/pinginterval.cpp | 58 +++++++++++++++++++++++++++++++++++ src/host/pinginterval.h | 74 +++++--------------------------------------- src/host/pingscheduler.h | 2 +- 4 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 src/host/pinginterval.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82dbcbe..7e8550b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index 0000000..170b83f --- /dev/null +++ b/src/host/pinginterval.cpp @@ -0,0 +1,58 @@ +#include "host/pinginterval.h" + +#include + +//----------------------------------------------------------------------------- +// 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 ); +} diff --git a/src/host/pinginterval.h b/src/host/pinginterval.h index 6e0a480..1fe84e0 100644 --- a/src/host/pinginterval.h +++ b/src/host/pinginterval.h @@ -1,7 +1,11 @@ #ifndef PINGINTERVAL_H #define PINGINTERVAL_H -#include +//----------------------------------------------------------------------------- +// PingIntervalType +//----------------------------------------------------------------------------- + +typedef long PingIntervalType; //----------------------------------------------------------------------------- // PingInterval @@ -12,14 +16,13 @@ * with helper methods to encapsulate interval computation. * Scope: one object per host. */ -template 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 - PingInterval::PingInterval( - T interval - ) : - OriginalInterval( interval ), - Interval( interval ) - { - BOOST_ASSERT( 0 < interval ); - } - -template - PingInterval::~PingInterval() - { - } - -template - PingInterval::operator T() - { - BOOST_ASSERT( 0 < Interval ); - - return Interval; - } - -template - void PingInterval::back_to_original() - { - Interval = OriginalInterval; - - BOOST_ASSERT( 0 < Interval ); - } - -template - void PingInterval::speed_up() - { - BOOST_ASSERT( 0 < Interval ); - - if ( can_speed_up() ) - { - Interval = Interval / 2; - } - - if ( Interval < 1 ) - { - Interval = 1; - } - - BOOST_ASSERT( 0 < Interval ); - } - -template - bool PingInterval::can_speed_up() const - { - T half_original = OriginalInterval / 2; - - return ( Interval > half_original ); - } - - #endif /* PINGINTERVAL_H */ diff --git a/src/host/pingscheduler.h b/src/host/pingscheduler.h index 88d7603..345e995 100644 --- a/src/host/pingscheduler.h +++ b/src/host/pingscheduler.h @@ -50,7 +50,7 @@ private: std::string LocalNetworkInterfaceName; boost::asio::deadline_timer NextPingTimer; boost::posix_time::ptime TimeSentLastPing; - PingInterval PingIntervalInSec; + PingInterval PingIntervalInSec; DnsResolver IpList; HostStatusAnalyzer HostAnalyzer; -- 1.7.1