Fixed typos
[ACE_TAO.git] / ACE / ace / Event_Handler.cpp
blob6a44bf58eeaa77b20ea5328e815d37fb8ddf6115
1 // Event_Handler.cpp
2 #include "ace/Event_Handler.h"
3 #include "ace/OS_Errno.h"
4 #include "ace/Reactor.h"
5 #include "ace/Thread_Manager.h"
6 /* Need to see if ACE_HAS_BUILTIN_ATOMIC_OP defined */
7 #include "ace/Atomic_Op.h"
9 #if !defined (__ACE_INLINE__)
10 #include "ace/Event_Handler.inl"
11 #endif /* __ACE_INLINE__ */
13 #include <algorithm>
15 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 // Implement conceptually abstract virtual functions in the base class
18 // so derived classes don't have to implement unused ones.
19 ACE_Event_Handler::ACE_Event_Handler (ACE_Reactor *r,
20 int p)
21 : reference_count_ (1),
22 priority_ (p),
23 reactor_ (r),
24 reference_counting_policy_ (Reference_Counting_Policy::DISABLED)
26 // ACE_TRACE ("ACE_Event_Handler::ACE_Event_Handler");
29 ACE_Event_Handler::~ACE_Event_Handler (void)
31 // ACE_TRACE ("ACE_Event_Handler::~ACE_Event_Handler");
34 // Gets the file descriptor associated with this I/O device.
35 ACE_HANDLE
36 ACE_Event_Handler::get_handle (void) const
38 ACE_TRACE ("ACE_Event_Handler::get_handle");
39 return ACE_INVALID_HANDLE;
42 // Sets the file descriptor associated with this I/O device.
43 void
44 ACE_Event_Handler::set_handle (ACE_HANDLE)
46 ACE_TRACE ("ACE_Event_Handler::set_handle");
49 // Gets the priority of this handler.
50 int
51 ACE_Event_Handler::priority (void) const
53 ACE_TRACE ("ACE_Event_Handler::priority");
54 return this->priority_;
57 // Sets the priority
58 void
59 ACE_Event_Handler::priority (int priority)
61 ACE_TRACE ("ACE_Event_Handler::priority");
62 this->priority_ = priority;
65 // Called when the object is about to be removed from the Dispatcher
66 // tables.
67 int
68 ACE_Event_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
70 ACE_TRACE ("ACE_Event_Handler::handle_close");
71 return -1;
74 // Called when input becomes available on fd.
75 int
76 ACE_Event_Handler::handle_input (ACE_HANDLE)
78 ACE_TRACE ("ACE_Event_Handler::handle_input");
79 return -1;
82 // Called when output is possible on fd.
83 int
84 ACE_Event_Handler::handle_output (ACE_HANDLE)
86 ACE_TRACE ("ACE_Event_Handler::handle_output");
87 return -1;
90 // Called when urgent data is available on fd.
91 int
92 ACE_Event_Handler::handle_exception (ACE_HANDLE)
94 ACE_TRACE ("ACE_Event_Handler::handle_exception");
95 return -1;
98 // Called when timer expires, TV stores the current time.
99 int
100 ACE_Event_Handler::handle_timeout (const ACE_Time_Value &, const void *)
102 ACE_TRACE ("ACE_Event_Handler::handle_timeout");
103 return -1;
106 // Called when a monitored Process exits
108 ACE_Event_Handler::handle_exit (ACE_Process *)
110 ACE_TRACE ("ACE_Event_Handler::handle_exit");
111 return -1;
114 // Called when a registered signal occurs.
116 ACE_Event_Handler::handle_signal (int, siginfo_t *, ucontext_t *)
118 ACE_TRACE ("ACE_Event_Handler::handle_signal");
119 return -1;
123 ACE_Event_Handler::resume_handler (void)
125 ACE_TRACE ("ACE_Event_Handler::resume_handler");
127 // Return a default value and allow the reactor to take care of
128 // resuming the handler
129 return ACE_Event_Handler::ACE_REACTOR_RESUMES_HANDLER;
133 ACE_Event_Handler::handle_qos (ACE_HANDLE)
135 ACE_TRACE ("ACE_Event_Handler::handle_qos");
136 return -1;
140 ACE_Event_Handler::handle_group_qos (ACE_HANDLE)
142 ACE_TRACE ("ACE_Event_Handler::handle_group_qos");
143 return -1;
146 void
147 ACE_Event_Handler::reactor (ACE_Reactor *reactor)
149 ACE_TRACE ("ACE_Event_Handler::reactor");
150 this->reactor_ = reactor;
153 ACE_Reactor *
154 ACE_Event_Handler::reactor (void) const
156 ACE_TRACE ("ACE_Event_Handler::reactor");
157 return this->reactor_;
160 ACE_Reactor_Timer_Interface *
161 ACE_Event_Handler::reactor_timer_interface (void) const
163 ACE_TRACE ("ACE_Event_Handler::reactor_timer_interface");
164 return this->reactor_;
167 ACE_Event_Handler::Reference_Count
168 ACE_Event_Handler::add_reference (void)
170 bool const reference_counting_required =
171 this->reference_counting_policy ().value () ==
172 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
174 if (reference_counting_required)
175 return ++this->reference_count_;
176 else
177 return 1;
180 ACE_Event_Handler::Reference_Count
181 ACE_Event_Handler::remove_reference (void)
183 bool const reference_counting_required =
184 this->reference_counting_policy ().value () ==
185 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
187 if (reference_counting_required)
189 Reference_Count result =
190 --this->reference_count_;
192 if (result == 0)
193 delete this;
195 return result;
197 else
199 return 1;
203 ACE_Event_Handler::Policy::~Policy (void)
207 ACE_Event_Handler::Reference_Counting_Policy::Reference_Counting_Policy (Reference_Counting_Policy::Value value)
208 : value_ (value)
212 ACE_Event_Handler::Reference_Counting_Policy::Value
213 ACE_Event_Handler::Reference_Counting_Policy::value (void) const
215 return this->value_;
218 void
219 ACE_Event_Handler::Reference_Counting_Policy::value (ACE_Event_Handler::Reference_Counting_Policy::Value value)
221 this->value_ = value;
224 ACE_Event_Handler::Reference_Counting_Policy &
225 ACE_Event_Handler::reference_counting_policy (void)
227 return this->reference_counting_policy_;
230 ACE_THR_FUNC_RETURN
231 ACE_Event_Handler::read_adapter (void *args)
233 ACE_Event_Handler *this_ptr = static_cast<ACE_Event_Handler *> (args);
234 ACE_Reactor *r = this_ptr->reactor ();
236 while (this_ptr->handle_input (ACE_STDIN) != -1)
237 continue;
239 this_ptr->handle_close (ACE_STDIN, ACE_Event_Handler::READ_MASK);
240 // It's possible for handle_close() to "delete this" so we need to
241 // cache the reactor pointer and use it here.
242 r->notify ();
244 return 0;
248 ACE_Event_Handler::register_stdin_handler (ACE_Event_Handler *eh,
249 ACE_Reactor *reactor,
250 ACE_Thread_Manager *thr_mgr,
251 int flags)
253 #if defined (ACE_WIN32)
254 ACE_UNUSED_ARG (reactor);
256 eh->reactor (reactor);
257 return thr_mgr->spawn (&read_adapter, static_cast<void *> (eh), flags);
258 #else
259 // Keep compilers happy.
260 ACE_UNUSED_ARG (flags);
261 ACE_UNUSED_ARG (thr_mgr);
262 return reactor->register_handler (ACE_STDIN,
264 ACE_Event_Handler::READ_MASK);
265 #endif /* ACE_WIN32 */
269 ACE_Event_Handler::remove_stdin_handler (ACE_Reactor *reactor,
270 ACE_Thread_Manager * /* thr_mgr */)
272 #if defined (ACE_WIN32)
273 ACE_UNUSED_ARG (reactor);
275 // What should we do here?
276 ACE_NOTSUP_RETURN (-1);
277 #else
278 return reactor->remove_handler (ACE_STDIN,
279 ACE_Event_Handler::READ_MASK);
280 #endif /* ACE_WIN32 */
283 // ---------------------------------------------------------------------
285 ACE_Event_Handler_var::ACE_Event_Handler_var (void)
286 : ptr_ (0)
290 ACE_Event_Handler_var::ACE_Event_Handler_var (ACE_Event_Handler *p)
291 : ptr_ (p)
295 ACE_Event_Handler_var::ACE_Event_Handler_var (const ACE_Event_Handler_var &b)
296 : ptr_ (b.ptr_)
298 if (this->ptr_ != 0)
300 this->ptr_->add_reference ();
304 ACE_Event_Handler_var::~ACE_Event_Handler_var (void)
306 if (this->ptr_ != 0)
308 ACE_Errno_Guard eguard (errno);
309 this->ptr_->remove_reference ();
313 ACE_Event_Handler_var &
314 ACE_Event_Handler_var::operator= (ACE_Event_Handler *p)
316 if (this->ptr_ != p)
318 ACE_Event_Handler_var tmp (p);
319 std::swap (this->ptr_, tmp.ptr_);
322 return *this;
325 ACE_Event_Handler_var &
326 ACE_Event_Handler_var::operator= (const ACE_Event_Handler_var &b)
328 ACE_Event_Handler_var tmp (b);
329 std::swap (this->ptr_, tmp.ptr_);
331 return *this;
334 ACE_Event_Handler *
335 ACE_Event_Handler_var::operator->() const
337 return this->ptr_;
340 ACE_Event_Handler *
341 ACE_Event_Handler_var::handler (void) const
343 return this->ptr_;
346 ACE_Event_Handler *
347 ACE_Event_Handler_var::release (void)
349 ACE_Event_Handler * const old = this->ptr_;
350 this->ptr_ = 0;
351 return old;
354 void
355 ACE_Event_Handler_var::reset (ACE_Event_Handler *p)
357 *this = p;
360 #if defined (ACE_HAS_CPP11)
361 ACE_Event_Handler_var::operator bool() const
363 return this->ptr_ == nullptr ? false : true;
366 bool
367 ACE_Event_Handler_var::operator ==(std::nullptr_t) const
369 return this->ptr_ == nullptr ? true : false;
372 bool
373 ACE_Event_Handler_var::operator !=(std::nullptr_t) const
375 return this->ptr_ == nullptr ? false : true;
378 #endif /* ACE_HAS_CPP11 */
380 // ---------------------------------------------------------------------
382 ACE_Notification_Buffer::ACE_Notification_Buffer (void)
383 : eh_ (0),
384 mask_ (ACE_Event_Handler::NULL_MASK)
386 ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
389 ACE_Notification_Buffer::ACE_Notification_Buffer (ACE_Event_Handler *eh,
390 ACE_Reactor_Mask mask)
391 : eh_ (eh),
392 mask_ (mask)
394 ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
397 ACE_END_VERSIONED_NAMESPACE_DECL