2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
28 #include <boost/asio.hpp>
29 #include <boost/function.hpp>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/circular_buffer.hpp>
33 #include "dns/resolverbase.h"
34 #include "host/pinger.h"
35 #include "host/pingprotocol.h"
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 typedef boost::circular_buffer<PingProtocol> CircularProtocolList;
44 * @brief This class is a wrapper to the Pingers, and serves to alternate
46 * Scope: one object per host.
52 const IoServiceItem io_serv,
53 const std::string &network_interface,
54 const std::string &destination_address,
55 const uint16_t destination_port,
56 const int resolved_ip_ttl_threshold,
57 const int ping_reply_timeout,
58 const PingProtocolList &protocol_list
60 virtual ~PingRotate();
62 void ping( boost::function<void(bool)> ping_done_callback );
66 void start_resolving_ping_address();
67 int get_resolved_ip_count() const;
68 bool have_up_to_date_ip() const;
75 void set_ping_done_callback( boost::function<void(bool)> ping_done_callback );
76 void ping_done_handler( bool ping_success ) const;
78 void init_ping_protocol();
79 void update_ping_protocol();
80 void get_next_ping_protocol();
81 bool can_change_ping_protocol() const;
83 void update_dns_resolver( PingProtocol current_protocol );
86 void dns_resolve_callback(const bool was_success, const int cname_count);
92 /// The IO service object, which has the loop event
93 IoServiceItem IoService;
94 /// The network interface name
95 std::string NetworkInterfaceName;
97 ResolverItem Resolver;
98 /// The address to ping
99 std::string DestinationAddress;
100 /// The port to ping at destination host (same port to all protocols in the list)
101 uint16_t DestinationPort;
102 /// time threshold for address resolution
103 int ResolvedIpTtlThreshold;
104 /// timeout for ping reply
105 const int PingReplyTimeout;
106 /// The list of protocols to ping
107 CircularProtocolList ProtocolRotate;
108 /// Internal boost pinger object
110 /// The callback function
111 boost::function<void(bool)> PingDoneCallback;
112 /// a flag whether DNS resolution is finished or currently underway
113 bool DnsResolutionFinished;
114 /// a flag whether we should ping as soon as dns is ready
118 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
122 typedef boost::shared_ptr<PingRotate> PingRotateItem;
124 #endif // PING_ROTATE_H