Renamed PingStatusNotifier to StatusNotifier
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 24 Mar 2011 10:35:15 +0000 (11:35 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 24 Mar 2011 10:35:15 +0000 (11:35 +0100)
- the class scope is not restricted to ping status notification, it is
  responsible to notify the system when certain amount of hosts are down,
  independently of the number of pings given to that host.

src/CMakeLists.txt
src/main.cpp
src/notify/statusnotifier.cpp [moved from src/notify/pingstatusnotifier.cpp with 75% similarity]
src/notify/statusnotifier.h [moved from src/notify/pingstatusnotifier.h with 83% similarity]
src/ping/pinganalyzer.cpp
src/ping/pinganalyzer.h
src/ping/pingscheduler.cpp
src/ping/pingscheduler.h

index 1701940..d63f58f 100644 (file)
@@ -27,7 +27,7 @@ set(SOURCES
     icmp/icmpheader.cpp
     icmp/icmppacket.cpp
     icmp/ipv4header.cpp
-    notify/pingstatusnotifier.cpp
+    notify/statusnotifier.cpp
     notify/statusnotifiercommand.cpp
     ping/boostpinger.cpp
     ping/pinganalyzer.cpp
index e8256d5..dc4d4ff 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "config/configurationreader.h"
 #include "config/host.h"
-#include "notify/pingstatusnotifier.h"
+#include "notify/statusnotifier.h"
 #include "ping/pingscheduler.h"
 
 using namespace std;
@@ -29,8 +29,8 @@ int main( int argc, char* argv[] )
         // TODO init_notifier and get_notifier
         int limit_hosts_down = config.get_limit_hosts_down();
         string status_notifier_cmd = config.get_status_notifier_cmd();
-        shared_ptr<PingStatusNotifier> notifier(
-                new PingStatusNotifier( limit_hosts_down, status_notifier_cmd )
+        shared_ptr<StatusNotifier> notifier(
+                new StatusNotifier( limit_hosts_down, status_notifier_cmd )
         );
 
         // TODO init_pingers()
similarity index 75%
rename from src/notify/pingstatusnotifier.cpp
rename to src/notify/statusnotifier.cpp
index d0dcc20..7493a3f 100644 (file)
@@ -1,4 +1,4 @@
-#include "notify/pingstatusnotifier.h"
+#include "notify/statusnotifier.h"
 
 #include <iostream>
 
@@ -7,10 +7,10 @@
 using namespace std;
 
 //-----------------------------------------------------------------------------
-// PingStatusNotifier
+// StatusNotifier
 //-----------------------------------------------------------------------------
 
-PingStatusNotifier::PingStatusNotifier(
+StatusNotifier::StatusNotifier(
         const int limit_hosts_down,
         const string &status_notifier_cmd
 ) :
@@ -22,11 +22,11 @@ PingStatusNotifier::PingStatusNotifier(
     BOOST_ASSERT( !status_notifier_cmd.empty() );
 }
 
-PingStatusNotifier::~PingStatusNotifier()
+StatusNotifier::~StatusNotifier()
 {
 }
 
-void PingStatusNotifier::notify_host_up( const string &host_address )
+void StatusNotifier::notify_host_up( const string &host_address )
 {
     BOOST_ASSERT( !host_address.empty() );
 
@@ -43,7 +43,7 @@ void PingStatusNotifier::notify_host_up( const string &host_address )
     BOOST_ASSERT( HostsDownList.count( host_address ) == 0 );
 }
 
-void PingStatusNotifier::notify_host_down( const string &host_address )
+void StatusNotifier::notify_host_down( const string &host_address )
 {
     BOOST_ASSERT( !host_address.empty() );
 
@@ -60,7 +60,7 @@ void PingStatusNotifier::notify_host_down( const string &host_address )
     BOOST_ASSERT( HostsDownList.count( host_address ) == 1 );
 }
 
-void PingStatusNotifier::add_host_up( const string &host_address )
+void StatusNotifier::add_host_up( const string &host_address )
 {
     if ( HostsDownList.count( host_address ) > 0 )
     {
@@ -68,18 +68,18 @@ void PingStatusNotifier::add_host_up( const string &host_address )
     }
 }
 
-void PingStatusNotifier::add_host_down( const string &host_address )
+void StatusNotifier::add_host_down( const string &host_address )
 {
     HostsDownList.insert( host_address );
 }
 
-bool PingStatusNotifier::exceeded_host_down_count_limit() const
+bool StatusNotifier::exceeded_host_down_count_limit() const
 {
     int host_down_count = HostsDownList.size();
     return ( host_down_count >= LimitHostsDown );
 }
 
-void PingStatusNotifier::notify_system_up()
+void StatusNotifier::notify_system_up()
 {
     StatusNotifierCmd.set_token_value(
             StatusNotifierCommand::StatusToken,
@@ -89,7 +89,7 @@ void PingStatusNotifier::notify_system_up()
     StatusNotifierCmd.execute();
 }
 
-void PingStatusNotifier::notify_system_down()
+void StatusNotifier::notify_system_down()
 {
     StatusNotifierCmd.set_token_value(
             StatusNotifierCommand::StatusToken,
similarity index 83%
rename from src/notify/pingstatusnotifier.h
rename to src/notify/statusnotifier.h
index 7aca573..18829cc 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef PINGSTATUSNOTIFIER_H
-#define PINGSTATUSNOTIFIER_H
+#ifndef STATUSNOTIFIER_H
+#define STATUSNOTIFIER_H
 
 #include <set>
 #include <string>
@@ -7,7 +7,7 @@
 #include "notify/statusnotifiercommand.h"
 
 //-----------------------------------------------------------------------------
-// PingStatusNotifier
+// StatusNotifier
 //-----------------------------------------------------------------------------
 
 /**
  * keeping track of the number of hosts down.
  * Scope: one object for many hosts.
  */
-class PingStatusNotifier
+class StatusNotifier
 {
 public:
-    PingStatusNotifier(
+    StatusNotifier(
             const int limit_hosts_down,
             const std::string &status_notifier_cmd
     );
-    virtual ~PingStatusNotifier();
+    virtual ~StatusNotifier();
 
     void notify_host_up( const std::string &host_address );
     void notify_host_down( const std::string &host_address );
@@ -43,4 +43,4 @@ private:
 
 };
 
-#endif /* PINGSTATUSNOTIFIER_H */
+#endif /* STATUSNOTIFIER_H */
index d4af2da..ff2326e 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <boost/assert.hpp>
 
-#include "notify/pingstatusnotifier.h"
+#include "notify/statusnotifier.h"
 
 using namespace std;
 using namespace boost;
@@ -16,7 +16,7 @@ using namespace boost;
 PingAnalyzer::PingAnalyzer(
         const string &host_address,
         const int limit_ping_fail_percentage,
-        shared_ptr<PingStatusNotifier> notifier
+        shared_ptr<StatusNotifier> notifier
 ) :
     HostAddress( host_address ),
     Notifier( notifier ),
index 964141e..b9b8c45 100644 (file)
@@ -5,7 +5,7 @@
 
 #include <boost/shared_ptr.hpp>
 
-class PingStatusNotifier;
+class StatusNotifier;
 
 //-----------------------------------------------------------------------------
 // PingAnalyzer
@@ -21,8 +21,8 @@ class PingAnalyzer
 public:
     PingAnalyzer(
             const std::string &host_address,
-            const int ping_fail_threshold_percentage,
-            boost::shared_ptr<PingStatusNotifier> notifier
+            const int limit_ping_fail_percentage,
+            boost::shared_ptr<StatusNotifier> notifier
     );
     virtual ~PingAnalyzer();
 
@@ -39,7 +39,7 @@ private:
 
 private:
     std::string HostAddress;
-    boost::shared_ptr<PingStatusNotifier> Notifier;
+    boost::shared_ptr<StatusNotifier> Notifier;
     int LimitPingFailPercentage;
     int ResolvedIpCount;
     int PingsPerformedCount;
index 5d020d6..0cc0631 100644 (file)
@@ -5,7 +5,7 @@
 #include <boost/bind.hpp>
 
 #include "dns/dnsresolver.h"
-#include "notify/pingstatusnotifier.h"
+#include "notify/statusnotifier.h"
 #include "ping/boostpinger.h"
 
 using namespace std;
@@ -20,9 +20,9 @@ using namespace boost::posix_time;
 PingScheduler::PingScheduler(
         boost::asio::io_service &io_service,
         const string &ping_address,
-        const int ping_interval_in_sec,
+        const long ping_interval_in_sec,
         const int limit_ping_fail_percentage,
-        shared_ptr<PingStatusNotifier> notifier
+        shared_ptr<StatusNotifier> notifier
 
 ) :
     IoService( io_service ),
index 01e1b3a..24cea1c 100644 (file)
@@ -9,7 +9,7 @@
 #include "dns/dnsresolver.h"
 #include "ping/pinganalyzer.h"
 
-class PingStatusNotifier;
+class StatusNotifier;
 
 //-----------------------------------------------------------------------------
 // PingScheduler
@@ -26,9 +26,9 @@ public:
     PingScheduler(
             boost::asio::io_service &io_service,
             const std::string &ping_address,
-            const int ping_interval_in_sec,
+            const long ping_interval_in_sec,
             const int limit_ping_fail_percentage,
-            boost::shared_ptr<PingStatusNotifier> notifier
+            boost::shared_ptr<StatusNotifier> notifier
     );
     virtual ~PingScheduler();
 
@@ -47,7 +47,7 @@ private:
     boost::asio::io_service &IoService;
     boost::asio::deadline_timer Timer;
     boost::posix_time::ptime TimeSentLastPing;
-    const int PingIntervalInSec;
+    const long PingIntervalInSec;
     DnsResolver IpList;
     PingAnalyzer Analyzer;