- this name describes better the main purpose behind this class, which is to call the pinger in configured intervals
icmp/ipv4header.cpp
ping/boostpinger.cpp
ping/host.cpp
- ping/pingcheck.cpp
ping/pinger.cpp
+ ping/pingscheduler.cpp
main.cpp
)
#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
#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
) :
{
}
-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 )
{
}
}
-void PingCheck::ping( const string &destination )
+void PingScheduler::ping( const string &destination )
{
BOOST_ASSERT( !destination.empty() );
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 = "
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();
}
-#ifndef PINGCHECK_H
-#define PINGCHECK_H
+#ifndef PINGSCHEDULER_H
+#define PINGSCHEDULER_H
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#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();
};
//-----------------------------------------------------------------------------
-// PingCheckItem
+// PingSchedulerItem
//-----------------------------------------------------------------------------
-typedef boost::shared_ptr<PingCheck> PingCheckItem;
+typedef boost::shared_ptr<PingScheduler> PingSchedulerItem;
-#endif /* PINGCHECK_H */
+#endif /* PINGSCHEDULER_H */