--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#include "host/pingerfactory.h"
+
+//-----------------------------------------------------------------------------
+// PingerFactory
+//-----------------------------------------------------------------------------
+
+PingerFactory::PingerFactory()
+{
+}
+
+PingerFactory::~PingerFactory()
+{
+}
+
+void PingerFactory::createPinger( PingProtocol type )
+{
+ // TODO
+}
--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#ifndef PINGERFACTORY_H
+#define PINGERFACTORY_H
+
+//-----------------------------------------------------------------------------
+// PingerFactory
+//-----------------------------------------------------------------------------
+
+class PingerFactory
+{
+public:
+ enum PingProtocol
+ {
+ PingProtocol_ICMP,
+ PingProtocol_TCP
+ };
+
+public:
+ PingerFactory();
+ virtual ~PingerFactory();
+
+ void createPinger( PingProtocol type );
+};
+
+#endif /* PINGERFACTORY_H */
#include <logfunc.hpp>
#include "dns/dnsresolver.h"
+#include "icmp/icmppinger.h"
#include "link/linkstatusanalyzer.h"
using namespace std;
PingScheduler::PingScheduler(
const string &network_interface,
const string &destination_address,
+ const PingerFactory::PingProtocol ping_protocol,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
const string &nameserver,
PingIntervalInSec( ping_interval_in_sec ),
IpList( destination_address, nameserver ),
HostAnalyzer( destination_address, ping_fail_percentage_limit, link_analyzer ),
- Pinger(IoService, LocalNetworkInterfaceName, PingReplyTimeout),
+ Ping(),
Thread()
{
+#if 0
+ // TODO read the Factory Design Pattern from Head First
+ Ping = PingerFactory::create( ping_protocol );
+#endif
+ Ping = shared_ptr<Pinger>(
+ new IcmpPinger( IoService, LocalNetworkInterfaceName, PingReplyTimeout )
+ );
}
PingScheduler::~PingScheduler()
{
BOOST_ASSERT( !destination_ip.empty() );
- Pinger.ping( destination_ip, boost::bind(&PingScheduler::ping_done_handler, this, _1) );
+ Ping->ping( destination_ip, boost::bind(&PingScheduler::ping_done_handler, this, _1) );
}
void PingScheduler::setup_next_ping()
#include "dns/dnsresolver.h"
#include "link/linkstatusanalyzer.h"
#include "host/hoststatusanalyzer.h"
+#include "host/pinger.h"
+#include "host/pingerfactory.h"
#include "host/pinginterval.h"
#include "icmp/icmppinger.h"
PingScheduler(
const std::string &network_interface,
const std::string &destination_address,
+ const PingerFactory::PingProtocol ping_protocol,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
const std::string &nameserver,
/// object responsible to evaluate the status of the host
HostStatusAnalyzer HostAnalyzer;
/// Internal boost pinger object
- IcmpPinger Pinger;
+ boost::shared_ptr<Pinger> Ping;
/// thread object
boost::thread Thread;
#include "config/configurationreader.h"
#include "config/host.h"
#include "link/linkstatusanalyzer.h"
+#include "host/pingerfactory.h"
#include "host/pingscheduler.h"
using namespace std;
{
string destination_address = host->get_address();
int ping_interval_in_sec = host->get_interval_in_sec();
+ PingerFactory::PingProtocol protocol = PingerFactory::PingProtocol_ICMP;
PingSchedulerItem scheduler(
new PingScheduler(
local_interface,
destination_address,
+ protocol,
ping_interval_in_sec,
ping_fail_limit,
nameserver,