Make x.0.10 publicly available
[ACE_TAO.git] / ACE / tests / Network_Adapters_Test.h
blob2541e6eafeda8ff50012705369951c73014ac8eb
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Network_Adapters_Test.h
7 * Definitions for Network_Adapters_Test.cpp.
9 * @author Robert S. Iakobashvili <roberti@go-WLAN.com> <coroberti@walla.co.il> Gonzalo A. Diethelm <gonzalo.diethelm@aditiva.com> made aceing
11 //=============================================================================
14 #ifndef ACE_NETWORK_ADAPTERS_TEST_H
15 #define ACE_NETWORK_ADAPTERS_TEST_H
17 #include "ace/Ping_Socket.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #if defined (ACE_HAS_ICMP_SUPPORT) && (ACE_HAS_ICMP_SUPPORT == 1)
24 # ifndef ACE_LACKS_GETPROTOBYNAME
26 #include "ace/Reactor.h"
27 #include "ace/INET_Addr.h"
28 #include "ace/Event_Handler.h"
29 #include "ace/Mutex.h"
32 * Echo_Handler performs echo-checks against a single ICMP echo-point.
34 class Echo_Handler : public ACE_Event_Handler
36 public:
37 /// Default constructor
38 Echo_Handler ();
40 /// Destructor
41 virtual ~Echo_Handler ();
43 /**
44 * Initialization of a handler, performing echo-checks against a
45 * SINGLE echo-point (supposed to be a really reliable, like hub,
46 * router).
48 * <reactor> - to be used for demultiplexing of any input and
49 * timeout
50 * <reply_wait> - time to wait for reply
51 * <remote_addr> - pointer to the remote address to sent to ICMP
52 * ECHO_CHECK datagram
53 * <success_status> - a pointer to char to be set as a 0 - on
54 * success, and 1 - when failed
55 * <max_attempts_num> - maximum number of attempts to perform
56 * <local_addr> - the local address to bind the underlaying
57 * ACE::Ping_Socket; useful for checks of local network adapters
58 * <connect_to_remote> - whether to connect the underlaying
59 * ACE::Ping_Socket to the remote address (1), or not (0)
61 int open (ACE_Reactor * const reactor,
62 const ACE_Time_Value & reply_wait,
63 const ACE_INET_Addr & remote_addr,
64 ACE_TCHAR * success_status = 0,
65 size_t max_attempts_num = 1,
66 const ACE_Addr & local_addr = ACE_Addr::sap_any,
67 int connect_to_remote = 0);
69 /**
70 * Initialization of a handler, performing echo-checks against
71 * MULTIPLE echo-points.
73 * <reactor> - to be used for demultiplexing of any input and
74 * timeout;
75 * <reply_wait> - time to wait for reply;
76 * <remote_addrs> - an array of remote addresses to sent to ICMP
77 * ECHO_CHECK datagram;
78 * <success_status> - an array of chars, each of them representing
79 * a respective remote address to be set as a 0 - on success, and
80 * 1 - when failed;
81 * <max_attempts_num> - maximum number of attempts to perform;
82 * <local_addr> - the local address to bind the underlaying
83 * ACE::Ping_Socket; useful for checks of the local network adapters
84 * connectivity;
86 int open (ACE_Reactor * const reactor,
87 ACE_Time_Value const & reply_wait,
88 ACE_INET_Addr const remote_addrs[],
89 size_t number_remotes,
90 ACE_TCHAR * success_status = 0,
91 size_t max_attempts_num = 1,
92 ACE_Addr const & local_addr = ACE_Addr::sap_any);
94 /// Returns reference to the ACE::Ping_Socket. Necessary for ACE_Reactor.
95 virtual ACE_HANDLE get_handle () const;
97 /**
98 * Takes care of the input. Reads the incoming ICMP datagrams and
99 * calls for process_incoming () of the ping_socket for processing.
101 virtual int handle_input (ACE_HANDLE handle);
104 * Decides, if we need to continue checks (when at least a single
105 * address not returned ICMP_ECHO_REPLY and number of attempts,
106 * set in open () not expired). If yes, calls for dispatch_echo_checks (),
107 * if not returns -1 to initiate clean-up.
109 virtual int handle_timeout (ACE_Time_Value const & tv,
110 void const * arg = 0);
112 /// Makes clean-up
113 virtual int handle_close (ACE_HANDLE handle,
114 ACE_Reactor_Mask close_mask);
116 /// Calls send_echo_check() for all remote_addrs_
117 int dispatch_echo_checks (int first_call = 0);
119 /// Access to ping_socket.
120 ACE_Ping_Socket& ping_socket ();
122 /// Returns 1 if a single char of success_status_ is 0
123 /// (connected).
124 int does_echo_test_successful ();
126 private:
127 /// Wrapper for sending/receiving ICMPs.
128 ACE_Ping_Socket ping_socket_;
130 /// Time to wait for reply.
131 ACE_Time_Value reply_wait_;
133 /// Remote address to ping on it
134 ACE_INET_Addr *remote_addrs_;
136 /// Number of remote echo points
137 size_t number_remotes_;
139 /// When 0 - success, 1 - failed.
140 ACE_TCHAR *success_status_;
142 /// If 1 - we 'own'
143 int delete_success_status_;
145 /// Maximum number of attempts.
146 size_t max_attempts_num_;
148 /// The number of the current attempt.
149 size_t current_attempt_;
151 /// Whether to make connect to the remote address or not. May be
152 /// buggy on some platforms.
153 int connect_to_remote_;
158 * Class Stop_Handler - the most important class of the process.
159 * Knows how to stop all this business.
161 class Stop_Handler : public ACE_Event_Handler
163 public:
164 #ifdef ACE_HAS_THREADS
165 typedef ACE_Atomic_Op<ACE_Mutex, long> counter_sig;
166 #else
167 typedef long counter_sig;
168 #endif
170 // Constructor.
171 Stop_Handler (ACE_Reactor * const reactor = ACE_Reactor::instance ());
173 // Destructor.
174 virtual ~Stop_Handler ();
176 // Initialization. Registers this for SIGINT, SIGTERM and SIGQUIT.
177 virtual int open ();
179 // De-registers this from the reactor and stops reactors event_loop.
180 virtual int handle_close (ACE_HANDLE handle,
181 ACE_Reactor_Mask close_mask);
183 // Called by reactor from the notification queue.
184 virtual int handle_input (ACE_HANDLE);
186 // Dispatches handle_input () notification.
187 virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
189 virtual int handle_timeout (ACE_Time_Value const & current_time,
190 void const * act = 0);
192 // Register handler with us for stopping.
193 virtual int register_handler (ACE_Event_Handler * handler);
195 // Unregister handler, registered before with us for stopping.
196 virtual int unregister_handler (ACE_Event_Handler * handler);
198 private:
199 enum
201 HANDLERS_TO_STOP_TABLE_SIZE = 10
204 // Flag to prevent multiple dispatching of handle_input ().
205 counter_sig counter_;
207 // Table to place here pointers to all tasks in the process.
208 ACE_Event_Handler * handlers_to_stop_[HANDLERS_TO_STOP_TABLE_SIZE];
210 ACE_Sig_Set registered_signals_;
215 * TODO comment
217 class Repeats_Handler : public ACE_Event_Handler
219 public:
220 // Constructor.
221 Repeats_Handler ();
223 // Destructor.
224 virtual ~Repeats_Handler ();
226 // Initialization.
227 virtual int open (Echo_Handler *check_handler,
228 ACE_Reactor * const reactor = ACE_Reactor::instance (),
229 unsigned int seconds_timer = 60);
231 virtual int handle_close (ACE_HANDLE handle,
232 ACE_Reactor_Mask close_mask);
234 // dispatches a new echo-checks series
235 virtual int handle_timeout (ACE_Time_Value const & current_time,
236 void const * act = 0);
238 private:
239 // an instance of a handler
240 Echo_Handler * check_handler_;
242 // timer in seconds to repeat the checks
243 unsigned int seconds_timer_;
245 // counts repeats
246 unsigned long counter_;
249 # endif // ACE_LACKS_GETPROTOBYNAME
250 #endif /* ACE_HAS_ICMP_SUPPORT == 1 */
252 #endif /* ACE_NETWORK_ADAPTERS_TEST_H */