Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / tests / Network_Adapters_Test.h
blob20fa181c2990426c4c53995b0521e150fe0b13e2
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 (void);
40 /// Destructor
41 virtual ~Echo_Handler (void);
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 (void) 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 (void);
122 /// Returns 1 if a single char of success_status_ is 0
123 /// (connected).
124 int does_echo_test_successful (void);
126 private:
128 /// Wrapper for sending/receiving ICMPs.
129 ACE_Ping_Socket ping_socket_;
131 /// Time to wait for reply.
132 ACE_Time_Value reply_wait_;
134 /// Remote address to ping on it
135 ACE_INET_Addr *remote_addrs_;
137 /// Number of remote echo points
138 size_t number_remotes_;
140 /// When 0 - success, 1 - failed.
141 ACE_TCHAR *success_status_;
143 /// If 1 - we 'own'
144 int delete_success_status_;
146 /// Maximum number of attempts.
147 size_t max_attempts_num_;
149 /// The number of the current attempt.
150 size_t current_attempt_;
152 /// Whether to make connect to the remote address or not. May be
153 /// buggy on some platforms.
154 int connect_to_remote_;
159 * Class Stop_Handler - the most important class of the process.
160 * Knows how to stop all this business.
162 class Stop_Handler : public ACE_Event_Handler
164 public:
165 #ifdef ACE_HAS_THREADS
166 typedef ACE_Atomic_Op<ACE_Mutex, long> counter_sig;
167 #else
168 typedef long counter_sig;
169 #endif
171 // Constructor.
172 Stop_Handler (ACE_Reactor * const reactor = ACE_Reactor::instance ());
174 // Destructor.
175 virtual ~Stop_Handler (void);
177 // Initialization. Registers this for SIGINT, SIGTERM and SIGQUIT.
178 virtual int open (void);
180 // De-registers this from the reactor and stops reactors event_loop.
181 virtual int handle_close (ACE_HANDLE handle,
182 ACE_Reactor_Mask close_mask);
184 // Called by reactor from the notification queue.
185 virtual int handle_input (ACE_HANDLE);
187 // Dispatches handle_input () notification.
188 virtual int handle_signal (int signum,
189 siginfo_t * = 0,
190 ucontext_t * = 0);
192 virtual int handle_timeout (ACE_Time_Value const & current_time,
193 void const * act = 0);
195 // Register handler with us for stopping.
196 virtual int register_handler (ACE_Event_Handler * handler);
198 // Unregister handler, registered before with us for stopping.
199 virtual int unregister_handler (ACE_Event_Handler * handler);
201 private:
203 enum
205 HANDLERS_TO_STOP_TABLE_SIZE = 10
208 // Flag to prevent multiple dispatching of handle_input ().
209 counter_sig counter_;
211 // Table to place here pointers to all tasks in the process.
212 ACE_Event_Handler * handlers_to_stop_[HANDLERS_TO_STOP_TABLE_SIZE];
214 ACE_Sig_Set registered_signals_;
219 * TODO comment
221 class Repeats_Handler : public ACE_Event_Handler
223 public:
224 // Constructor.
225 Repeats_Handler (void);
227 // Destructor.
228 virtual ~Repeats_Handler (void);
230 // Initialization.
231 virtual int open (Echo_Handler *check_handler,
232 ACE_Reactor * const reactor = ACE_Reactor::instance (),
233 unsigned int seconds_timer = 60);
235 virtual int handle_close (ACE_HANDLE handle,
236 ACE_Reactor_Mask close_mask);
238 // dispatches a new echo-checks series
239 virtual int handle_timeout (ACE_Time_Value const & current_time,
240 void const * act = 0);
242 private:
243 // an instance of a handler
244 Echo_Handler * check_handler_;
246 // timer in seconds to repeat the checks
247 unsigned int seconds_timer_;
249 // counts repeats
250 unsigned long counter_;
253 # endif // ACE_LACKS_GETPROTOBYNAME
254 #endif /* ACE_HAS_ICMP_SUPPORT == 1 */
256 #endif /* ACE_NETWORK_ADAPTERS_TEST_H */