From: Guilherme Maciel Ferreira Date: Wed, 9 Mar 2011 08:47:23 +0000 (+0100) Subject: Renamed PingCheck class to PingScheduler. X-Git-Tag: v1.0~152 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=4bb97b452c941eee89680ad83b1656097a02083f;p=pingcheck Renamed PingCheck class to PingScheduler. - this name describes better the main purpose behind this class, which is to call the pinger in configured intervals --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c5bf24..74e9cc9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 ) diff --git a/src/main.cpp b/src/main.cpp index 43db4c7..1dfbb68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 diff --git a/src/ping/pingcheck.cpp b/src/ping/pingscheduler.cpp similarity index 75% rename from src/ping/pingcheck.cpp rename to src/ping/pingscheduler.cpp index 9551d16..5a85fac 100644 --- a/src/ping/pingcheck.cpp +++ b/src/ping/pingscheduler.cpp @@ -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(); } diff --git a/src/ping/pingcheck.h b/src/ping/pingscheduler.h similarity index 77% rename from src/ping/pingcheck.h rename to src/ping/pingscheduler.h index e733385..d81c04d 100644 --- a/src/ping/pingcheck.h +++ b/src/ping/pingscheduler.h @@ -1,5 +1,5 @@ -#ifndef PINGCHECK_H -#define PINGCHECK_H +#ifndef PINGSCHEDULER_H +#define PINGSCHEDULER_H #include #include @@ -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 PingCheckItem; +typedef boost::shared_ptr PingSchedulerItem; -#endif /* PINGCHECK_H */ +#endif /* PINGSCHEDULER_H */