Moved PingCheck class to its own file, replaced the old one with a new semantic.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 3 Mar 2011 10:38:24 +0000 (11:38 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 3 Mar 2011 10:38:24 +0000 (11:38 +0100)
src/CMakeLists.txt
src/main.cpp
src/ping/pingcheck.cpp
src/ping/pingcheck.h

index 0e536c7..8d8f4e3 100644 (file)
@@ -14,6 +14,7 @@ set( SOURCES
     ping/icmpheader.cpp
     ping/icmppacket.cpp
     ping/ipv4header.cpp
+    ping/pingcheck.cpp
     ping/pinger.cpp
     main.cpp
 )
index 64da9f9..6dbf200 100644 (file)
@@ -6,81 +6,12 @@
 
 #include "configurationreader.h"
 #include "host.h"
-#include "boostpinger.h"
+#include "pingcheck.h"
 
 using namespace std;
 
-class PingCheck
-{
-public:
-    PingCheck( Host host ) :
-        Host_( host )
-    {
-    }
-
-    void start_pinging()
-    {
-        cout << "[start_pinging]" << endl;
-
-        string destination = Host_.get_address();
-        size_t ping_set_total = 100; // TODO configurable:
-        size_t ping_set_count = 0;
-        while ( ping_set_count < ping_set_total )
-        {
-            ping_schedule( destination );
-
-            ping_set_count++;
-        }
-    }
-
-private:
-
-    void ping_schedule( const string &destination )
-    {
-        cout << "[ping_schedule]" << endl;
-
-        try
-        {
-            ping( destination );
-        }
-        catch ( std::exception& e )
-        {
-            std::cerr << "Exception: " << e.what() << std::endl;
-            return;
-        }
-
-        wait();
-    }
-
-    void ping( const string &destination ) throw ( std::exception& )
-    {
-        cout << "[ping]" << endl;
-
-        size_t times_to_ping = 3; // TODO configurable: this must be automatically selected
-        boost::asio::io_service io_service;
-        BoostPinger pinger( io_service );
-        pinger.ping( destination, times_to_ping );
-    }
-
-    void wait()
-    {
-        cout << "[wait]" << endl;
-
-        boost::asio::io_service io_service;
-        deadline_timer timer( io_service );
-        std::size_t interval = Host_.get_interval(); // TODO configurable:
-        timer.expires_from_now( boost::posix_time::seconds( interval ) );
-        timer.wait();
-    }
-
-private:
-    Host Host_;
-
-};
-
 int main( int argc, char* argv[] )
 {
-    // sends the program command line to be parsed by the configuration reader
     ConfigurationReader config_reader;
     bool read_success = config_reader.parse( argc, argv );
     if ( read_success )
index 4a33cef..5994669 100644 (file)
@@ -1,39 +1,72 @@
+#include <boost/asio.hpp>
+#include <iostream>
+
+#include "boostpinger.h"
+
 #include "pingcheck.h"
 
 //-----------------------------------------------------------------------------
 // PingCheck
 //-----------------------------------------------------------------------------
 
-PingCheck::PingCheck() :
-    configuration( NULL ),
-    ping_managers()
+PingCheck::PingCheck( Host host ) :
+    Host_( host )
 {
 }
 
-PingCheck::PingCheck( const PingCheck& ) :
-    configuration( NULL ),
-    ping_managers()
+PingCheck::~PingCheck()
 {
 }
 
-PingCheck::~PingCheck()
+void PingCheck::start_pinging()
 {
+    std::cout << "[start_pinging]" << std::endl;
+
+    std::string destination = Host_.get_address();
+    std::size_t ping_set_total = 3; // TODO configurable:
+    std::size_t ping_set_count = 0;
+    while ( ping_set_count < ping_set_total )
+    {
+        ping_and_wait( destination );
+
+        ping_set_count++;
+    }
 }
 
-PingCheck& PingCheck::operator=( const PingCheck& )
+void PingCheck::ping_and_wait( const std::string &destination )
 {
-    return *this;
+    std::cout << "[ping_and_wait]" << std::endl;
+
+    try
+    {
+        ping( destination );
+
+        wait();
+    }
+    catch ( std::exception& e )
+    {
+        std::cerr << "Exception: " << e.what() << std::endl;
+        return;
+    }
+}
+
+void PingCheck::ping( const std::string &destination ) throw ( std::exception& )
+{
+    std::cout << "[ping]" << std::endl;
+
+    std::size_t times_to_ping = 3; // TODO configurable: this must be automatically selected
+    boost::asio::io_service io_service;
+    BoostPinger pinger( io_service );
+    pinger.ping( destination, times_to_ping );
 }
 
-void PingCheck::init_ping_managers() const
+void PingCheck::wait()
 {
-    // starts N ping managers with a host and an interval, this was read in configuration
-    //  for each host in configuration
-    //
-    //
-    //
-    //
-    //
-    //
-    //
+    std::cout << "[wait]" << std::endl;
+
+    boost::asio::io_service io_service;
+    deadline_timer timer( io_service );
+    std::size_t interval = Host_.get_interval(); // TODO configurable:
+    timer.expires_from_now( boost::posix_time::seconds( interval ) );
+    timer.wait();
 }
index 14c8341..652af6e 100644 (file)
@@ -1,10 +1,9 @@
 #ifndef PINGCHECK_H
 #define PINGCHECK_H
 
-#include <map>
+#include <string>
 
-#include "configuration.h"
-#include "pingmanager.h"
+#include "host.h"
 
 //-----------------------------------------------------------------------------
 // PingCheck
 class PingCheck
 {
 public:
-    PingCheck();
-    PingCheck( const PingCheck& other );
+    PingCheck( Host host );
     virtual ~PingCheck();
 
-    PingCheck& operator=( const PingCheck& other );
+    void start_pinging();
 
-    void init_ping_managers() const;
+private:
+    void ping_and_wait( const std::string &destination );
+    void ping( const std::string &destination ) throw ( std::exception& );
+    void wait();
 
 private:
-    Configuration *configuration;
-    std::multimap<int, PingManager> ping_managers;
+    Host Host_;
 
 };