Changed the ping() method interface, which requires just a destination string instead...
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Mon, 28 Feb 2011 09:06:00 +0000 (10:06 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Mon, 28 Feb 2011 09:19:05 +0000 (10:19 +0100)
src/main.cpp
src/ping/boostpinger.cpp
src/ping/boostpinger.h
src/ping/pinger.h

index b2e005b..8a611b7 100644 (file)
@@ -23,7 +23,8 @@ int main( int argc, char* argv[] )
             BoostPinger p( io_service );
             Configuration config = config_reader.get_configuration();
             Host host = config.get_host();
-            p.ping( host );
+            string destination = host.get_address();
+            p.ping( destination );
         }
         catch ( std::exception& e )
         {
index 044b151..587a14e 100644 (file)
@@ -20,7 +20,7 @@ namespace posix_time = boost::posix_time;
 //-----------------------------------------------------------------------------
 
 BoostPinger::BoostPinger(
-        boost::asio::io_service& io_service
+        boost::asio::io_service &io_service
 ) :
     io_service( io_service ),
     Resolver( io_service ),
@@ -38,12 +38,10 @@ BoostPinger::~BoostPinger()
 {
 }
 
-void BoostPinger::ping( const Host &host )
+void BoostPinger::ping( const std::string &destination )
 {
-    BOOST_ASSERT( !host.get_address().empty() );
-    BOOST_ASSERT( ( 0 < host.get_interval() ) && ( host.get_interval() < UINT_MAX ) );
+    BOOST_ASSERT( !destination.empty() );
 
-    std::string destination = host.get_address();
     icmp::resolver::query query( icmp::v4(), destination, "" );
     DestinationEndpoint = *Resolver.resolve( query );
 
@@ -82,7 +80,7 @@ void BoostPinger::start_send()
     }
 }
 
-void BoostPinger::send( const boost::asio::streambuf& request_buffer )
+void BoostPinger::send( const boost::asio::streambuf &request_buffer )
 {
     // Send the request.
     TimeSent = posix_time::microsec_clock::universal_time();
@@ -116,7 +114,7 @@ void BoostPinger::start_receive()
     );
 }
 
-void BoostPinger::handle_receive( const std::size_t length )
+void BoostPinger::handle_receive( const std::size_t &length )
 {
     // The actual number of bytes received is committed to the buffer so that we
     // can extract it using a std::istream object.
index af2653c..ac592a9 100644 (file)
@@ -16,23 +16,23 @@ using boost::asio::deadline_timer;
 class BoostPinger : public Pinger
 {
 public:
-    BoostPinger( boost::asio::io_service& io_service );
+    BoostPinger( boost::asio::io_service &io_service );
     virtual ~BoostPinger();
 
-    void ping( const Host &host );
+    void ping( const std::string &destination );
 
 private:
     void start_send();
-    void send( const boost::asio::streambuf& request_buffer );
+    void send( const boost::asio::streambuf &request_buffer );
     void handle_timeout();
 
     void start_receive();
-    void handle_receive( const std::size_t length );
+    void handle_receive( const std::size_t &length );
 
     static uint16_t get_identifier();
 
 private:
-    boost::asio::io_service& io_service;
+    boost::asio::io_service &io_service;
     icmp::resolver Resolver;
     icmp::endpoint DestinationEndpoint;
     icmp::socket Socket;
index 1786800..3d1035c 100644 (file)
@@ -3,8 +3,6 @@
 
 #include <string>
 
-#include "host.h"
-
 //-----------------------------------------------------------------------------
 // Pinger
 //-----------------------------------------------------------------------------
@@ -15,7 +13,7 @@ public:
     Pinger();
     virtual ~Pinger();
 
-    virtual void ping( const Host &host ) = 0;
+    virtual void ping( const std::string &destination ) = 0;
 
 };