Renamed PingCheck class to PingScheduler.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Wed, 9 Mar 2011 08:47:23 +0000 (09:47 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Wed, 9 Mar 2011 14:28:02 +0000 (15:28 +0100)
- this name describes better the main purpose behind this class, which is to call the pinger in configured intervals

src/CMakeLists.txt
src/main.cpp
src/ping/pingscheduler.cpp [moved from src/ping/pingcheck.cpp with 75% similarity]
src/ping/pingscheduler.h [moved from src/ping/pingcheck.h with 77% similarity]

index 2c5bf24..74e9cc9 100644 (file)
@@ -15,8 +15,8 @@ set( SOURCES
     icmp/ipv4header.cpp
     ping/boostpinger.cpp
     ping/host.cpp
-    ping/pingcheck.cpp
     ping/pinger.cpp
+    ping/pingscheduler.cpp
     main.cpp
 )
 
index 43db4c7..1dfbb68 100644 (file)
@@ -4,31 +4,36 @@
 
 #include "configurationreader.h"
 #include "host.h"
-#include "pingcheck.h"
+#include "pingscheduler.h"
 
 using namespace std;
 using namespace boost::asio;
 
 int main( int argc, char* argv[] )
 {
+    // TODO load_configuration() or read_configuration()
     ConfigurationReader config_reader;
     bool read_success = config_reader.parse( argc, argv );
     if ( read_success )
     {
         io_service io_service;
 
+        // TODO init_pingers()
         Configuration config = config_reader.get_configuration();
         vector< HostItem > hosts = config.get_hosts();
-        vector< PingCheckItem > check_list;
+        vector< PingSchedulerItem > scheduler_list;
         BOOST_FOREACH( HostItem host, hosts )
         {
-            PingCheckItem check( new PingCheck( io_service, *host ) );
-            check_list.push_back( check );
+            PingSchedulerItem scheduler(
+                    new PingScheduler( io_service, *host )
+            );
+            scheduler_list.push_back( scheduler );
         }
 
-        BOOST_FOREACH( PingCheckItem check, check_list )
+        // TODO ping_loop()
+        BOOST_FOREACH( PingSchedulerItem scheduler, scheduler_list )
         {
-            check->start_pinging();
+            scheduler->start_pinging();
         }
 
         // Main loop to handle ping requests when they were scheduled
similarity index 75%
rename from src/ping/pingcheck.cpp
rename to src/ping/pingscheduler.cpp
index 9551d16..5a85fac 100644 (file)
@@ -3,17 +3,17 @@
 
 #include "boostpinger.h"
 
-#include "pingcheck.h"
+#include "pingscheduler.h"
 
 using namespace std;
 using namespace boost::asio;
 using namespace boost::posix_time;
 
 //-----------------------------------------------------------------------------
-// PingCheck
+// PingScheduler
 //-----------------------------------------------------------------------------
 
-PingCheck::PingCheck(
+PingScheduler::PingScheduler(
         boost::asio::io_service &io_service,
         const Host &host
 ) :
@@ -24,14 +24,14 @@ PingCheck::PingCheck(
 {
 }
 
-PingCheck::~PingCheck()
+PingScheduler::~PingScheduler()
 {
 }
 
-void PingCheck::start_pinging()
+void PingScheduler::start_pinging()
 {
     string destination = DestinationHost.get_address();
-    uint ping_set_total = 1; // TODO configurable:
+    uint ping_set_total = 1; // TODO configurable: amount of pings each time
     uint ping_set_count = 0;
     while ( ping_set_count < ping_set_total )
     {
@@ -41,7 +41,7 @@ void PingCheck::start_pinging()
     }
 }
 
-void PingCheck::ping( const string &destination )
+void PingScheduler::ping( const string &destination )
 {
     BOOST_ASSERT( !destination.empty() );
 
@@ -55,7 +55,7 @@ void PingCheck::ping( const string &destination )
     schedule_next_ping();
 }
 
-void PingCheck::update_ping_statistics()
+void PingScheduler::update_ping_statistics()
 {
     ptime now = microsec_clock::universal_time(); // TODO
     cerr << "- Time elapsed since last ping = "
@@ -63,14 +63,14 @@ void PingCheck::update_ping_statistics()
     TimeSentLastPing = microsec_clock::universal_time(); // TODO
 }
 
-void PingCheck::schedule_next_ping()
+void PingScheduler::schedule_next_ping()
 {
     uint interval = DestinationHost.get_interval(); // TODO configurable:
     Timer.expires_from_now( seconds( interval ) );
-    Timer.async_wait( boost::bind( &PingCheck::handle_next_ping, this ) );
+    Timer.async_wait( boost::bind( &PingScheduler::handle_next_ping, this ) );
 }
 
-void PingCheck::handle_next_ping()
+void PingScheduler::handle_next_ping()
 {
     start_pinging();
 }
similarity index 77%
rename from src/ping/pingcheck.h
rename to src/ping/pingscheduler.h
index e733385..d81c04d 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef PINGCHECK_H
-#define PINGCHECK_H
+#ifndef PINGSCHEDULER_H
+#define PINGSCHEDULER_H
 
 #include <boost/asio.hpp>
 #include <boost/shared_ptr.hpp>
@@ -8,17 +8,17 @@
 #include "host.h"
 
 //-----------------------------------------------------------------------------
-// PingCheck
+// PingScheduler
 //-----------------------------------------------------------------------------
 
-class PingCheck
+class PingScheduler
 {
 public:
-    PingCheck(
+    PingScheduler(
             boost::asio::io_service &io_service,
             const Host &host
     );
-    virtual ~PingCheck();
+    virtual ~PingScheduler();
 
     void start_pinging();
 
@@ -37,9 +37,9 @@ private:
 };
 
 //-----------------------------------------------------------------------------
-// PingCheckItem
+// PingSchedulerItem
 //-----------------------------------------------------------------------------
 
-typedef boost::shared_ptr<PingCheck> PingCheckItem;
+typedef boost::shared_ptr<PingScheduler> PingSchedulerItem;
 
-#endif /* PINGCHECK_H */
+#endif /* PINGSCHEDULER_H */