From 54e7a2fe7fe095e9641dc862ec7bcab92ccd97e9 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Mon, 28 Feb 2011 10:06:00 +0100 Subject: [PATCH] Changed the ping() method interface, which requires just a destination string instead of a whole Host object --- src/main.cpp | 3 ++- src/ping/boostpinger.cpp | 12 +++++------- src/ping/boostpinger.h | 10 +++++----- src/ping/pinger.h | 4 +--- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b2e005b..8a611b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 ) { diff --git a/src/ping/boostpinger.cpp b/src/ping/boostpinger.cpp index 044b151..587a14e 100644 --- a/src/ping/boostpinger.cpp +++ b/src/ping/boostpinger.cpp @@ -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. diff --git a/src/ping/boostpinger.h b/src/ping/boostpinger.h index af2653c..ac592a9 100644 --- a/src/ping/boostpinger.h +++ b/src/ping/boostpinger.h @@ -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; diff --git a/src/ping/pinger.h b/src/ping/pinger.h index 1786800..3d1035c 100644 --- a/src/ping/pinger.h +++ b/src/ping/pinger.h @@ -3,8 +3,6 @@ #include -#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; }; -- 1.7.1