Commit | Line | Data |
---|---|---|
cd395966 GMF |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
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. | |
13 | ||
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. | |
16 | ||
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. | |
19 | */ | |
20 | ||
21 | #ifndef PINGER_H | |
22 | #define PINGER_H | |
23 | ||
238da857 GMF |
24 | #include <stdint.h> |
25 | ||
cd395966 GMF |
26 | #include <string> |
27 | ||
28 | #include <boost/function.hpp> | |
954945cd | 29 | #include <boost/shared_ptr.hpp> |
cc8d3a02 | 30 | #include <boost/utility.hpp> |
fc7ae593 | 31 | #include <boost/asio/io_service.hpp> |
23f51766 | 32 | #include <boost/asio/ip/address.hpp> |
4606d2b1 | 33 | #include <boost/weak_ptr.hpp> |
fc7ae593 | 34 | |
96c4e7a4 CH |
35 | #include "host/pingstatus.h" |
36 | ||
fc7ae593 CH |
37 | //----------------------------------------------------------------------------- |
38 | // IoServiceItem | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | typedef boost::shared_ptr<boost::asio::io_service> IoServiceItem; | |
cd395966 GMF |
42 | |
43 | //----------------------------------------------------------------------------- | |
44 | // Pinger | |
45 | //----------------------------------------------------------------------------- | |
46 | ||
b6464c7f GMF |
47 | /** |
48 | * @brief Abstract class for pingers. | |
20976656 | 49 | * Scope: one object per host. |
4606d2b1 CH |
50 | * |
51 | * Holds a weak_ptr to itself, so can create shared_ptrs from self | |
52 | * (adapted from amime project) | |
b6464c7f | 53 | */ |
cc8d3a02 | 54 | class Pinger : boost::noncopyable |
cd395966 GMF |
55 | { |
56 | public: | |
4606d2b1 CH |
57 | typedef boost::weak_ptr<Pinger> WeakPtr; |
58 | ||
cd395966 | 59 | virtual void ping( |
23f51766 | 60 | const boost::asio::ip::address &ip, |
238da857 | 61 | const uint16_t destination_port, |
96c4e7a4 | 62 | boost::function<void(PingStatus)> ping_done_callback |
cd395966 GMF |
63 | ) = 0; |
64 | ||
5a9bc2d1 CH |
65 | virtual void stop_pinging() = 0; |
66 | ||
ebf98514 GMF |
67 | protected: |
68 | Pinger(); | |
69 | virtual ~Pinger(); | |
4606d2b1 CH |
70 | |
71 | Pinger::WeakPtr get_myself() const; | |
1ece191b | 72 | virtual void set_myself(const Pinger::WeakPtr &myself); |
4606d2b1 CH |
73 | |
74 | private: | |
75 | Pinger::WeakPtr Myself; | |
cd395966 GMF |
76 | }; |
77 | ||
4606d2b1 | 78 | |
954945cd GMF |
79 | //----------------------------------------------------------------------------- |
80 | // PingerItem | |
81 | //----------------------------------------------------------------------------- | |
82 | ||
83 | typedef boost::shared_ptr<Pinger> PingerItem; | |
84 | ||
a9c88e1c | 85 | #endif // PINGER_H |