From: Guilherme Maciel Ferreira Date: Thu, 26 Jan 2012 00:39:46 +0000 (-0200) Subject: Renamed LinkStatusAnalyzer to LinkStatus. X-Git-Tag: v1.3~11^2~32 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=72e54d1c70a595e4b690d532ab4be6ee6149b442;p=pingcheck Renamed LinkStatusAnalyzer to LinkStatus. - This is a stronger noun name; - See "The Gravitational Pull of Functional Decomposition" at http://www.eetimes.com/design/embedded/4006522/Using-object-oriented-methods-to-achieve-C--s-promise-Part-3 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0fd7ab..d578b39 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,7 +79,7 @@ set(SOURCES icmp/icmppinger.cpp ip/ipv4header.cpp ip/ipv6header.cpp - link/linkstatusanalyzer.cpp + link/linkstatus.cpp link/statusnotifiercommand.cpp tcp/tcpheader.cpp tcp/tcppinger.cpp diff --git a/src/host/hoststatus.cpp b/src/host/hoststatus.cpp index dbe9e96..d7634ee 100644 --- a/src/host/hoststatus.cpp +++ b/src/host/hoststatus.cpp @@ -39,7 +39,7 @@ using boost::shared_ptr; HostStatus::HostStatus( const string &host_address, const int ping_fail_limit_percentage, - const shared_ptr link_analyzer + const shared_ptr link_analyzer ) : HostAddress( host_address ), LinkAnalyzer( link_analyzer ), diff --git a/src/host/hoststatus.h b/src/host/hoststatus.h index 491fc39..e01deb2 100644 --- a/src/host/hoststatus.h +++ b/src/host/hoststatus.h @@ -24,7 +24,7 @@ on this file might be covered by the GNU General Public License. #include -#include "link/linkstatusanalyzer.h" +#include "link/linkstatus.h" //----------------------------------------------------------------------------- // HostStatus @@ -41,7 +41,7 @@ public: HostStatus( const std::string &host_address, const int ping_fail_limit_percentage, - const boost::shared_ptr link_analyzer + const boost::shared_ptr link_analyzer ); ~HostStatus(); @@ -61,7 +61,7 @@ private: /// the DNS address of the host to analyze std::string HostAddress; /// the object responsible to analyze the link - const boost::shared_ptr LinkAnalyzer; + const boost::shared_ptr LinkAnalyzer; /// the maximum amount of pings that can fail without warning int PingFailLimitPercentage; /// the amount of IPs that are aliases to the host DNS diff --git a/src/host/pingscheduler.cpp b/src/host/pingscheduler.cpp index 93bfb93..da3b742 100644 --- a/src/host/pingscheduler.cpp +++ b/src/host/pingscheduler.cpp @@ -28,7 +28,7 @@ on this file might be covered by the GNU General Public License. #include "dns/dnsresolver.h" #include "icmp/icmppinger.h" -#include "link/linkstatusanalyzer.h" +#include "link/linkstatus.h" using namespace std; using boost::asio::io_service; @@ -53,7 +53,7 @@ PingScheduler::PingScheduler( const long ping_interval_in_sec, const int ping_fail_percentage_limit, const string &nameserver, - shared_ptr link_analyzer + shared_ptr link_analyzer ) : IoService(), diff --git a/src/host/pingscheduler.h b/src/host/pingscheduler.h index 3f7f038..f916565 100644 --- a/src/host/pingscheduler.h +++ b/src/host/pingscheduler.h @@ -28,7 +28,7 @@ on this file might be covered by the GNU General Public License. #include #include "dns/dnsresolver.h" -#include "link/linkstatusanalyzer.h" +#include "link/linkstatus.h" #include "host/hoststatus.h" #include "host/pinger.h" #include "host/pingerfactory.h" @@ -56,7 +56,7 @@ public: const long ping_interval_in_sec, const int ping_fail_percentage_limit, const std::string &nameserver, - boost::shared_ptr link_analyzer + boost::shared_ptr link_analyzer ); ~PingScheduler(); diff --git a/src/link/linkstatusanalyzer.cpp b/src/link/linkstatus.cpp similarity index 81% rename from src/link/linkstatusanalyzer.cpp rename to src/link/linkstatus.cpp index 78c6864..3c5bab9 100644 --- a/src/link/linkstatusanalyzer.cpp +++ b/src/link/linkstatus.cpp @@ -17,7 +17,7 @@ in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ -#include "link/linkstatusanalyzer.h" +#include "link/linkstatus.h" #include @@ -35,22 +35,22 @@ using I2n::Logger::GlobalLogger; typedef lock_guard mutex_lock_guard; //----------------------------------------------------------------------------- -// LinkStatusAnalyzer +// LinkStatus //----------------------------------------------------------------------------- /** * @brief Creates a link status object. * - * @param hosts_down_limit the maximum amount of different hosts that can be + * @param hosts_down_limit The maximum amount of different hosts that can be * down before the system take any action. - * @param link_up_interval_in_min the amount of time required to the link to + * @param link_up_interval_in_min The amount of time required to the link to * stay up before notify. - * @param link_down_interval_in_min the amount of time required to the link to + * @param link_down_interval_in_min The amount of time required to the link to * stay down before notify. - * @param status_notifier_cmd the command used to notify about link status + * @param status_notifier_cmd The command used to notify about link status * changes. */ -LinkStatusAnalyzer::LinkStatusAnalyzer( +LinkStatus::LinkStatus( const int hosts_down_limit, const int link_up_interval_in_min, const int link_down_interval_in_min, @@ -60,7 +60,7 @@ LinkStatusAnalyzer::LinkStatusAnalyzer( HostsDownList(), LinkUpIntervalInMin( link_up_interval_in_min ), LinkDownIntervalInMin( link_down_interval_in_min ), - CurrentLinkStatus( LinkStatus_Down ), + CurrentLinkStatus( Status_Down ), CurrentNotificationStatus( NotificationStatus_NotReported ), TimeLinkStatusChanged( microsec_clock::universal_time() ), StatusNotifierCmd( status_notifier_cmd ), @@ -71,7 +71,7 @@ LinkStatusAnalyzer::LinkStatusAnalyzer( BOOST_ASSERT( 0 <= link_down_interval_in_min ); } -LinkStatusAnalyzer::~LinkStatusAnalyzer() +LinkStatus::~LinkStatus() { } @@ -83,7 +83,7 @@ LinkStatusAnalyzer::~LinkStatusAnalyzer() * * @param host_address the DNS/IP address of the host that is up. */ -void LinkStatusAnalyzer::notify_host_up( const string &host_address ) +void LinkStatus::notify_host_up( const string &host_address ) { BOOST_ASSERT( !host_address.empty() ); @@ -108,9 +108,9 @@ void LinkStatusAnalyzer::notify_host_up( const string &host_address ) * Note: this object does not resolves IPs, thus you have to send the same host * address in order to the object to consider the same host. * - * @param host_address the DNS/IP address of the host that is down. + * @param host_address The DNS/IP address of the host that is down. */ -void LinkStatusAnalyzer::notify_host_down( const string &host_address ) +void LinkStatus::notify_host_down( const string &host_address ) { BOOST_ASSERT( !host_address.empty() ); @@ -129,7 +129,7 @@ void LinkStatusAnalyzer::notify_host_down( const string &host_address ) BOOST_ASSERT( HostsDownList.count( host_address ) == 1 ); } -void LinkStatusAnalyzer::add_host_up( const string &host_address ) +void LinkStatus::add_host_up( const string &host_address ) { if ( HostsDownList.count( host_address ) > 0 ) { @@ -139,27 +139,27 @@ void LinkStatusAnalyzer::add_host_up( const string &host_address ) } } -void LinkStatusAnalyzer::add_host_down( const string &host_address ) +void LinkStatus::add_host_down( const string &host_address ) { (void) HostsDownList.insert( host_address ); } -bool LinkStatusAnalyzer::exceeded_host_down_limit() const +bool LinkStatus::exceeded_host_down_limit() const { int host_down_count = static_cast( HostsDownList.size() ); return ( host_down_count > HostsDownLimit ); } -void LinkStatusAnalyzer::notify_link_up() +void LinkStatus::notify_link_up() { - set_link_status( LinkStatus_Up ); + set_link_status( Status_Up ); // report the link status only if: it is up longer than a configured amount // of time, and if we haven't reported the new status yet if ( is_link_up_enough_time() && can_report_link_status() ) { - BOOST_ASSERT( CurrentLinkStatus == LinkStatus_Up ); + BOOST_ASSERT( CurrentLinkStatus == Status_Up ); BOOST_ASSERT( CurrentNotificationStatus == NotificationStatus_NotReported ); StatusNotifierCmd.set_token_value( @@ -176,15 +176,15 @@ void LinkStatusAnalyzer::notify_link_up() } } -void LinkStatusAnalyzer::notify_link_down() +void LinkStatus::notify_link_down() { - set_link_status( LinkStatus_Down ); + set_link_status( Status_Down ); // report the link status only if: it is down longer than a configured amount // of time, and if we haven't reported the new status yet if ( is_link_down_enough_time() && can_report_link_status() ) { - BOOST_ASSERT( CurrentLinkStatus == LinkStatus_Down ); + BOOST_ASSERT( CurrentLinkStatus == Status_Down ); BOOST_ASSERT( CurrentNotificationStatus == NotificationStatus_NotReported ); StatusNotifierCmd.set_token_value( @@ -201,9 +201,9 @@ void LinkStatusAnalyzer::notify_link_down() } } -bool LinkStatusAnalyzer::is_link_up_enough_time() const +bool LinkStatus::is_link_up_enough_time() const { - if ( CurrentLinkStatus == LinkStatus_Up ) + if ( CurrentLinkStatus == Status_Up ) { ptime now = microsec_clock::universal_time(); long amount_time_link_is_up = (now - TimeLinkStatusChanged).total_seconds(); @@ -218,9 +218,9 @@ bool LinkStatusAnalyzer::is_link_up_enough_time() const return false; } -bool LinkStatusAnalyzer::is_link_down_enough_time() const +bool LinkStatus::is_link_down_enough_time() const { - if ( CurrentLinkStatus == LinkStatus_Down ) + if ( CurrentLinkStatus == Status_Down ) { ptime now = microsec_clock::universal_time(); long amount_time_link_is_down = (now - TimeLinkStatusChanged).total_seconds(); @@ -235,13 +235,13 @@ bool LinkStatusAnalyzer::is_link_down_enough_time() const return false; } -bool LinkStatusAnalyzer::can_report_link_status() const +bool LinkStatus::can_report_link_status() const { return ( CurrentNotificationStatus == NotificationStatus_NotReported ); } -void LinkStatusAnalyzer::set_link_status( - const LinkStatusAnalyzer::LinkStatus new_link_status +void LinkStatus::set_link_status( + const LinkStatus::Status new_link_status ) { // only reset the control flags if the link status has changed diff --git a/src/link/linkstatusanalyzer.h b/src/link/linkstatus.h similarity index 71% rename from src/link/linkstatusanalyzer.h rename to src/link/linkstatus.h index ca327ae..dcd30e0 100644 --- a/src/link/linkstatusanalyzer.h +++ b/src/link/linkstatus.h @@ -17,8 +17,8 @@ in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ -#ifndef LINK_STATUS_ANALYZER_H -#define LINK_STATUS_ANALYZER_H +#ifndef LINK_STATUS_H +#define LINK_STATUS_H #include #include @@ -30,7 +30,7 @@ on this file might be covered by the GNU General Public License. #include "link/statusnotifiercommand.h" //----------------------------------------------------------------------------- -// LinkStatusAnalyzer +// LinkStatus //----------------------------------------------------------------------------- /** @@ -38,25 +38,25 @@ on this file might be covered by the GNU General Public License. * track of the amount of hosts down. * Scope: one object for many hosts. */ -class LinkStatusAnalyzer +class LinkStatus { public: - LinkStatusAnalyzer( + LinkStatus( const int hosts_down_limit, const int link_up_interval_in_min, const int link_down_interval_in_min, const std::string &status_notifier_cmd ); - ~LinkStatusAnalyzer(); + ~LinkStatus(); void notify_host_up( const std::string &host_address ); void notify_host_down( const std::string &host_address ); private: - enum LinkStatus + enum Status { - LinkStatus_Up, - LinkStatus_Down + Status_Up, + Status_Down }; enum NotificationStatus @@ -79,35 +79,35 @@ private: bool can_report_link_status() const; void set_link_status( - const LinkStatusAnalyzer::LinkStatus new_link_status + const LinkStatus::Status new_link_status ); private: - /// the maximum amount of hosts which can be down before sound the alarm + /// The maximum amount of hosts which can be down before sound the alarm const int HostsDownLimit; - /// list of hosts down (obvious isn't it?) + /// List of hosts down (obvious isn't it?) std::set HostsDownList; - /// interval the link have to be stable in order to consider it is functional + /// Interval the link have to be stable in order to consider it is functional const int LinkUpIntervalInMin; - /// interval the link have to be down in order to consider it is non-functional + /// Interval the link have to be down in order to consider it is non-functional const int LinkDownIntervalInMin; - /// keep track of the actual link status - LinkStatusAnalyzer::LinkStatus CurrentLinkStatus; - /// indicates if the last link status change was notified - LinkStatusAnalyzer::NotificationStatus CurrentNotificationStatus; - /// when was the last time the status changed + /// Keep track of the actual link status + LinkStatus::Status CurrentLinkStatus; + /// Indicates if the last link status change was notified + LinkStatus::NotificationStatus CurrentNotificationStatus; + /// When was the last time the status changed boost::posix_time::ptime TimeLinkStatusChanged; - /// command used to notify the status of the link + /// Command used to notify the status of the link StatusNotifierCommand StatusNotifierCmd; - /// mutual exclusion variable to avoid data races + /// Mutual exclusion variable to avoid data races boost::mutex Mutex; }; //----------------------------------------------------------------------------- -// LinkStatusAnalyzerItem +// LinkStatusItem //----------------------------------------------------------------------------- -typedef boost::shared_ptr LinkStatusAnalyzerItem; +typedef boost::shared_ptr LinkStatusItem; -#endif // LINK_STATUS_ANALYZER_H +#endif // LINK_STATUS_H diff --git a/src/main.cpp b/src/main.cpp index e4e4b55..3c2b76c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,7 @@ on this file might be covered by the GNU General Public License. #include "config/configurationreader.h" #include "config/host.h" -#include "link/linkstatusanalyzer.h" +#include "link/linkstatus.h" #include "host/pingerfactory.h" #include "host/pingprotocol.h" #include "host/pingscheduler.h" @@ -62,7 +62,7 @@ ConfigurationItem get_configuration( return configuration; } -LinkStatusAnalyzerItem get_status_notifier( +LinkStatusItem get_status_notifier( const ConfigurationItem &configuration ) { @@ -70,8 +70,8 @@ LinkStatusAnalyzerItem get_status_notifier( int link_up_interval_in_min = configuration->get_link_up_interval_in_min(); int link_down_interval_in_min = configuration->get_link_down_interval_in_min(); string status_notifier_cmd = configuration->get_status_notifier_cmd(); - LinkStatusAnalyzerItem link_analyzer( - new LinkStatusAnalyzer( + LinkStatusItem link_analyzer( + new LinkStatus( hosts_down_limit, link_up_interval_in_min, link_down_interval_in_min, @@ -90,7 +90,7 @@ void init_logger() void init_pingers( const ConfigurationItem &configuration, - const LinkStatusAnalyzerItem &status_notifier, + const LinkStatusItem &status_notifier, PingSchedulerList *scheduler_list ) { @@ -238,7 +238,7 @@ int main( int argc, char *argv[] ) I2n::Daemon::daemonize(); } - LinkStatusAnalyzerItem status_notifier = get_status_notifier( configuration ); + LinkStatusItem status_notifier = get_status_notifier( configuration ); PingSchedulerList scheduler_list; init_pingers( configuration, status_notifier, &scheduler_list ); diff --git a/test/mock_linkstatusanalyzer.h b/test/mock_linkstatus.h similarity index 74% rename from test/mock_linkstatusanalyzer.h rename to test/mock_linkstatus.h index 1d55dc8..c80e226 100644 --- a/test/mock_linkstatusanalyzer.h +++ b/test/mock_linkstatus.h @@ -18,26 +18,26 @@ This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ -#ifndef LINK_STATUS_ANALYZER_H -#define LINK_STATUS_ANALYZER_H +#ifndef LINK_STATUS_H +#define LINK_STATUS_H #include #include //----------------------------------------------------------------------------- -// LinkStatusAnalyzer +// LinkStatus //----------------------------------------------------------------------------- /** * @brief This is a fake link status class. * Scope: one object for many hosts. */ -class LinkStatusAnalyzer +class LinkStatus { public: - LinkStatusAnalyzer(); - ~LinkStatusAnalyzer(); + LinkStatus(); + ~LinkStatus(); void notify_host_up( const std::string &host_address ); void notify_host_down( const std::string &host_address ); @@ -46,26 +46,26 @@ public: //----------------------------------------------------------------------------- -LinkStatusAnalyzer::LinkStatusAnalyzer() +LinkStatus::LinkStatus() { } -LinkStatusAnalyzer::~LinkStatusAnalyzer() +LinkStatus::~LinkStatus() { } -void LinkStatusAnalyzer::notify_host_up( const std::string &host_address ) +void LinkStatus::notify_host_up( const std::string &host_address ) { } -void LinkStatusAnalyzer::notify_host_down( const std::string &host_address ) +void LinkStatus::notify_host_down( const std::string &host_address ) { } //----------------------------------------------------------------------------- -// LinkStatusAnalyzerItem +// LinkStatusItem //----------------------------------------------------------------------------- -typedef boost::shared_ptr LinkStatusAnalyzerItem; +typedef boost::shared_ptr LinkStatusItem; -#endif // LINK_STATUS_ANALYZER_H +#endif // LINK_STATUS_H diff --git a/test/test_hoststatus.cpp b/test/test_hoststatus.cpp index 920c2dc..a97f92c 100644 --- a/test/test_hoststatus.cpp +++ b/test/test_hoststatus.cpp @@ -26,7 +26,7 @@ on this file might be covered by the GNU General Public License. #include #include -#include "mock_linkstatusanalyzer.h" +#include "mock_linkstatus.h" #include "host/hoststatus.h" @@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE( fail_percentage_10 ) int ping_fail_percentage_limit = 10; int resolved_ip_count = 10; - LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer ); + LinkStatusItem link_status( new LinkStatus ); HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status ); host_status.set_resolved_ip_count( resolved_ip_count ); @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE( fail_percentage_50 ) int ping_fail_percentage_limit = 50; int resolved_ip_count = 10; - LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer ); + LinkStatusItem link_status( new LinkStatus ); HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status ); host_status.set_resolved_ip_count( resolved_ip_count ); @@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE( fail_percentage_80 ) int ping_fail_percentage_limit = 80; int resolved_ip_count = 10; - LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer ); + LinkStatusItem link_status( new LinkStatus ); HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status ); host_status.set_resolved_ip_count( resolved_ip_count );