Renamed BoostPinger to IcmpPinger
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 19 May 2011 23:46:50 +0000 (20:46 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 19 May 2011 23:46:50 +0000 (20:46 -0300)
- the TCP pinger will be another class to avoid overloading this one with TCP stuff
- the name looks better =)

src/CMakeLists.txt
src/host/icmppinger.cpp [moved from src/host/boostpinger.cpp with 90% similarity]
src/host/icmppinger.h [moved from src/host/boostpinger.h with 88% similarity]
src/host/pingscheduler.cpp
src/host/pingscheduler.h

index 39bfbbf..8926298 100644 (file)
@@ -31,8 +31,8 @@ set(SOURCES
     dns/dnsresolver.cpp
     dns/hostaddress.cpp
     dns/timetolive.cpp
-    host/boostpinger.cpp
     host/hoststatusanalyzer.cpp
+    host/icmppinger.cpp
     host/pinginterval.cpp
     host/pingscheduler.cpp
     icmp/icmpdestinationunreachablemessage.cpp
similarity index 90%
rename from src/host/boostpinger.cpp
rename to src/host/icmppinger.cpp
index e21f121..2f22c5a 100644 (file)
@@ -4,7 +4,7 @@
 // Distributed under the Boost Software License, Version 1.0.
 //    (See accompanying file LICENSE_1_0.txt or copy at
 //          http://www.boost.org/LICENSE_1_0.txt)
-#include "host/boostpinger.h"
+#include "host/icmppinger.h"
 
 #include <istream>
 #include <ostream>
@@ -24,7 +24,6 @@
 #include "icmp/icmppacket.h"
 #include "icmp/icmptype.h"
 #include "icmp/ipv4header.h"
-#include "boostpinger.h"
 
 using namespace std;
 using boost::asio::const_buffers_1;
@@ -38,19 +37,19 @@ using boost::posix_time::seconds;
 using I2n::Logger::GlobalLogger;
 
 //-----------------------------------------------------------------------------
-// BoostPinger
+// IcmpPinger
 //-----------------------------------------------------------------------------
 
-BoostPinger::BoostPinger(
+IcmpPinger::IcmpPinger(
         boost::asio::io_service &io_service,
         string source_network_interface,
         const int echo_reply_timeout_in_sec
 ) :
-    IoService(io_service),
+    IoService( io_service ),
     DestinationEndpoint(),
     Socket( IoService, icmp::v4() ),
     IcmpPacketReceiveTimer( IoService ),
-    Identifier(0),
+    Identifier( 0 ),
     SequenceNumber( 0 ),
     TimeSent( microsec_clock::universal_time() ),
     ReplyBuffer(),
@@ -74,7 +73,7 @@ BoostPinger::BoostPinger(
     memcpy(&Identifier, random_tag.data, sizeof(Identifier));
 }
 
-BoostPinger::~BoostPinger()
+IcmpPinger::~IcmpPinger()
 {
 }
 
@@ -84,7 +83,10 @@ BoostPinger::~BoostPinger()
  * @param destination_ip The address of the host to ping.
  * @param done_handler Done handler will be called on successful ping or timeout
  */
-void BoostPinger::ping( const string &destination_ip, boost::function< void(bool) > ping_done_callback )
+void IcmpPinger::ping(
+        const string &destination_ip,
+        boost::function< void(bool) > ping_done_callback
+)
 {
     BOOST_ASSERT( !destination_ip.empty() );
 
@@ -99,7 +101,7 @@ void BoostPinger::ping( const string &destination_ip, boost::function< void(bool
     start_receive();
 }
 
-void BoostPinger::set_destination_endpoint( const string &destination_ip )
+void IcmpPinger::set_destination_endpoint( const string &destination_ip )
 {
     BOOST_ASSERT( !destination_ip.empty() );
 
@@ -108,7 +110,7 @@ void BoostPinger::set_destination_endpoint( const string &destination_ip )
     DestinationEndpoint = icmp::endpoint( destination_address, port );
 }
 
-void BoostPinger::start_send()
+void IcmpPinger::start_send()
 {
     ++SequenceNumber;
 
@@ -118,7 +120,7 @@ void BoostPinger::start_send()
     send_echo_request( icmp_echo_request_packet );
 }
 
-IcmpPacket BoostPinger::create_echo_request(
+IcmpPacket IcmpPinger::create_echo_request(
         const uint16_t sequence_number
 ) const
 {
@@ -137,7 +139,7 @@ IcmpPacket BoostPinger::create_echo_request(
     return IcmpPacket( icmp_header, icmp_data );
 }
 
-void BoostPinger::send_echo_request( const IcmpPacket &icmp_packet )
+void IcmpPinger::send_echo_request( const IcmpPacket &icmp_packet )
 {
     boost::asio::streambuf request_buffer;
     ostream os( &request_buffer );
@@ -169,7 +171,7 @@ void BoostPinger::send_echo_request( const IcmpPacket &icmp_packet )
     schedule_timeout_echo_reply();
 }
 
-void BoostPinger::schedule_timeout_echo_reply()
+void IcmpPinger::schedule_timeout_echo_reply()
 {
     // Wait up to N seconds for a reply.
     ReceivedReply = false;
@@ -177,11 +179,11 @@ void BoostPinger::schedule_timeout_echo_reply()
             TimeSent + seconds( EchoReplyTimeoutInSec )
     );
     IcmpPacketReceiveTimer.async_wait(
-            boost::bind( &BoostPinger::handle_ping_done, this )
+            boost::bind( &IcmpPinger::handle_ping_done, this )
     );
 }
 
-void BoostPinger::start_receive()
+void IcmpPinger::start_receive()
 {
     // Discard any data already in the buffer.
     ReplyBuffer.consume( ReplyBuffer.size() );
@@ -189,7 +191,7 @@ void BoostPinger::start_receive()
     // Waiting for a reply. We prepare the buffer to receive up to 64KB.
     Socket.async_receive(
             ReplyBuffer.prepare( 65536 ),
-            boost::bind( &BoostPinger::handle_receive_icmp_packet, this, _2 )
+            boost::bind( &IcmpPinger::handle_receive_icmp_packet, this, _2 )
     );
 }
 
@@ -198,7 +200,7 @@ void BoostPinger::start_receive()
  *
  * @return void
  **/
-void BoostPinger::handle_ping_done()
+void IcmpPinger::handle_ping_done()
 {
     // Check ReceivedReply as the timer handler
     // is also called by Timer.cancel();
@@ -225,7 +227,7 @@ void BoostPinger::handle_ping_done()
  * @param bytes_transferred Number of bytes transferred
  * @return void
  **/
-void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
+void IcmpPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
 {
     // The actual number of bytes received is committed to the buffer so that we
     // can extract it using a std::istream object.
@@ -290,7 +292,7 @@ void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
     }
 }
 
-void BoostPinger::print_echo_reply(
+void IcmpPinger::print_echo_reply(
         const IcmpPacket &icmp_packet,
         const size_t &bytes_transferred
 ) const
@@ -315,7 +317,7 @@ void BoostPinger::print_echo_reply(
          << " time=" << elapsed_time << " ms" << endl;
 }
 
-void BoostPinger::print_destination_unreachable(
+void IcmpPinger::print_destination_unreachable(
         const IcmpPacket &icmp_packet
 ) const
 {
@@ -332,7 +334,7 @@ void BoostPinger::print_destination_unreachable(
          << " Destination Net Unreachable" << endl;
 }
 
-void BoostPinger::set_ping_status( BoostPinger::PingStatus ping_status )
+void IcmpPinger::set_ping_status( IcmpPinger::PingStatus ping_status )
 {
     PingerStatus = ping_status;
 }
@@ -346,7 +348,7 @@ void BoostPinger::set_ping_status( BoostPinger::PingStatus ping_status )
  *
  * @return false if the bind failed.
  */
-bool BoostPinger::select_source_network_interface(
+bool IcmpPinger::select_source_network_interface(
         const string &source_network_interface
 )
 {
similarity index 88%
rename from src/host/boostpinger.h
rename to src/host/icmppinger.h
index ebacce7..992917b 100644 (file)
@@ -4,8 +4,8 @@
 // Distributed under the Boost Software License, Version 1.0.
 //    (See accompanying file LICENSE_1_0.txt or copy at
 //          http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOSTPINGER_H
-#define BOOSTPINGER_H
+#ifndef ICMPPINGER_H
+#define ICMPPINGER_H
 
 #include <boost/asio.hpp>
 #include <boost/function.hpp>
 class IcmpPacket;
 
 //-----------------------------------------------------------------------------
-// BoostPinger
+// IcmpPinger
 //-----------------------------------------------------------------------------
 
 /**
  * @brief This class performs ping to host using Boost Asio.
  * Scope: one object per host.
  */
-class BoostPinger
+class IcmpPinger
 {
 public:
-    BoostPinger(
+    IcmpPinger(
             boost::asio::io_service &io_service,
             std::string source_network_interface,
             const int echo_reply_timeout_in_sec
     );
-    virtual ~BoostPinger();
+    virtual ~IcmpPinger();
 
-    void ping( const std::string &destination_ip, boost::function< void(bool) > ping_done_callback);
+    void ping(
+            const std::string &destination_ip,
+            boost::function< void(bool) > ping_done_callback
+    );
 
 private:
     enum PingStatus
@@ -61,7 +64,7 @@ private:
             const IcmpPacket &icmp_packet
     ) const;
 
-    void set_ping_status( BoostPinger::PingStatus ping_status );
+    void set_ping_status( IcmpPinger::PingStatus ping_status );
 
     uint16_t get_identifier() const;
 
@@ -93,9 +96,9 @@ private:
     /// the amount of time to wait for the reply
     int EchoReplyTimeoutInSec;
     /// the status of the pinger
-    BoostPinger::PingStatus PingerStatus;
+    IcmpPinger::PingStatus PingerStatus;
     /// Callback to notify when the ping is done (got reply/timeout)
     boost::function< void(bool) > PingDoneCallback;
 };
 
-#endif /* BOOSTPINGER_H */
+#endif /* ICMPPINGER_H */
index e2ddf03..f18dedb 100644 (file)
@@ -26,7 +26,6 @@ on this file might be covered by the GNU General Public License.
 #include <logfunc.hpp>
 
 #include "dns/dnsresolver.h"
-#include "host/boostpinger.h"
 #include "link/linkstatusanalyzer.h"
 
 using namespace std;
index 1081446..b874f1f 100644 (file)
@@ -27,10 +27,10 @@ on this file might be covered by the GNU General Public License.
 #include <boost/shared_ptr.hpp>
 #include <boost/thread.hpp>
 
-#include "host/boostpinger.h"
 #include "dns/dnsresolver.h"
 #include "link/linkstatusanalyzer.h"
 #include "host/hoststatusanalyzer.h"
+#include "host/icmppinger.h"
 #include "host/pinginterval.h"
 
 //-----------------------------------------------------------------------------
@@ -90,7 +90,7 @@ private:
     /// object responsible to evaluate the status of the host
     HostStatusAnalyzer HostAnalyzer;
     /// Internal boost pinger object
-    BoostPinger Pinger;
+    IcmpPinger Pinger;
     /// thread object
     boost::thread Thread;