Renamed LinkStatusAnalyzer to LinkStatus.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 26 Jan 2012 00:39:46 +0000 (22:39 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 26 Jan 2012 00:39:46 +0000 (22:39 -0200)
    - 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

src/CMakeLists.txt
src/host/hoststatus.cpp
src/host/hoststatus.h
src/host/pingscheduler.cpp
src/host/pingscheduler.h
src/link/linkstatus.cpp [moved from src/link/linkstatusanalyzer.cpp with 81% similarity]
src/link/linkstatus.h [moved from src/link/linkstatusanalyzer.h with 71% similarity]
src/main.cpp
test/mock_linkstatus.h [moved from test/mock_linkstatusanalyzer.h with 74% similarity]
test/test_hoststatus.cpp

index b0fd7ab..d578b39 100644 (file)
@@ -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
index dbe9e96..d7634ee 100644 (file)
@@ -39,7 +39,7 @@ using boost::shared_ptr;
 HostStatus::HostStatus(
         const string &host_address,
         const int ping_fail_limit_percentage,
-        const shared_ptr<LinkStatusAnalyzer> link_analyzer
+        const shared_ptr<LinkStatus> link_analyzer
 ) :
     HostAddress( host_address ),
     LinkAnalyzer( link_analyzer ),
index 491fc39..e01deb2 100644 (file)
@@ -24,7 +24,7 @@ on this file might be covered by the GNU General Public License.
 
 #include <boost/shared_ptr.hpp>
 
-#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<LinkStatusAnalyzer> link_analyzer
+            const boost::shared_ptr<LinkStatus> 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<LinkStatusAnalyzer> LinkAnalyzer;
+    const boost::shared_ptr<LinkStatus> LinkAnalyzer;
     /// the maximum amount of pings that can fail without warning
     int PingFailLimitPercentage;
     /// the amount of IPs that are aliases to the host DNS
index 93bfb93..da3b742 100644 (file)
@@ -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<LinkStatusAnalyzer> link_analyzer
+        shared_ptr<LinkStatus> link_analyzer
 
 ) :
     IoService(),
index 3f7f038..f916565 100644 (file)
@@ -28,7 +28,7 @@ on this file might be covered by the GNU General Public License.
 #include <boost/thread.hpp>
 
 #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<LinkStatusAnalyzer> link_analyzer
+            boost::shared_ptr<LinkStatus> link_analyzer
     );
     ~PingScheduler();
 
similarity index 81%
rename from src/link/linkstatusanalyzer.cpp
rename to src/link/linkstatus.cpp
index 78c6864..3c5bab9 100644 (file)
@@ -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 <iostream>
 
@@ -35,22 +35,22 @@ using I2n::Logger::GlobalLogger;
 typedef lock_guard<mutex> 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<int>( 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
similarity index 71%
rename from src/link/linkstatusanalyzer.h
rename to src/link/linkstatus.h
index ca327ae..dcd30e0 100644 (file)
@@ -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 <set>
 #include <string>
@@ -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<std::string> 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<LinkStatusAnalyzer> LinkStatusAnalyzerItem;
+typedef boost::shared_ptr<LinkStatus> LinkStatusItem;
 
-#endif // LINK_STATUS_ANALYZER_H
+#endif // LINK_STATUS_H
index e4e4b55..3c2b76c 100644 (file)
@@ -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 );
similarity index 74%
rename from test/mock_linkstatusanalyzer.h
rename to test/mock_linkstatus.h
index 1d55dc8..c80e226 100644 (file)
@@ -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 <string>
 
 #include <boost/shared_ptr.hpp>
 
 //-----------------------------------------------------------------------------
-// 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<LinkStatusAnalyzer> LinkStatusAnalyzerItem;
+typedef boost::shared_ptr<LinkStatus> LinkStatusItem;
 
-#endif // LINK_STATUS_ANALYZER_H
+#endif // LINK_STATUS_H
index 920c2dc..a97f92c 100644 (file)
@@ -26,7 +26,7 @@ on this file might be covered by the GNU General Public License.
 #include <boost/asio.hpp>
 #include <boost/test/unit_test.hpp>
 
-#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 );