Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Event_Handler.cpp
blobb67015a0691eb08523323c66be3d8b6e1cd1c44e
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 #include <algorithm>
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 // Implement conceptually abstract virtual functions in the base class
14 // so derived classes don't have to implement unused ones.
15 ACE_Event_Handler::ACE_Event_Handler (ACE_Reactor *r,
16 int p)
17 : reference_count_ (1),
18 priority_ (p),
19 reactor_ (r),
20 reference_counting_policy_ (Reference_Counting_Policy::DISABLED)
22 // ACE_TRACE ("ACE_Event_Handler::ACE_Event_Handler");
25 // Gets the file descriptor associated with this I/O device.
26 ACE_HANDLE
27 ACE_Event_Handler::get_handle () const
29 ACE_TRACE ("ACE_Event_Handler::get_handle");
30 return ACE_INVALID_HANDLE;
33 // Sets the file descriptor associated with this I/O device.
34 void
35 ACE_Event_Handler::set_handle (ACE_HANDLE)
37 ACE_TRACE ("ACE_Event_Handler::set_handle");
40 // Gets the priority of this handler.
41 int
42 ACE_Event_Handler::priority () const
44 ACE_TRACE ("ACE_Event_Handler::priority");
45 return this->priority_;
48 // Sets the priority
49 void
50 ACE_Event_Handler::priority (int priority)
52 ACE_TRACE ("ACE_Event_Handler::priority");
53 this->priority_ = priority;
56 // Called when the object is about to be removed from the Dispatcher
57 // tables.
58 int
59 ACE_Event_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
61 ACE_TRACE ("ACE_Event_Handler::handle_close");
62 return -1;
65 // Called when input becomes available on fd.
66 int
67 ACE_Event_Handler::handle_input (ACE_HANDLE)
69 ACE_TRACE ("ACE_Event_Handler::handle_input");
70 return -1;
73 // Called when output is possible on fd.
74 int
75 ACE_Event_Handler::handle_output (ACE_HANDLE)
77 ACE_TRACE ("ACE_Event_Handler::handle_output");
78 return -1;
81 // Called when urgent data is available on fd.
82 int
83 ACE_Event_Handler::handle_exception (ACE_HANDLE)
85 ACE_TRACE ("ACE_Event_Handler::handle_exception");
86 return -1;
89 // Called when timer expires, TV stores the current time.
90 int
91 ACE_Event_Handler::handle_timeout (const ACE_Time_Value &, const void *)
93 ACE_TRACE ("ACE_Event_Handler::handle_timeout");
94 return -1;
97 // Called when a monitored Process exits
98 int
99 ACE_Event_Handler::handle_exit (ACE_Process *)
101 ACE_TRACE ("ACE_Event_Handler::handle_exit");
102 return -1;
105 // Called when a registered signal occurs.
107 ACE_Event_Handler::handle_signal (int, siginfo_t *, ucontext_t *)
109 ACE_TRACE ("ACE_Event_Handler::handle_signal");
110 return -1;
114 ACE_Event_Handler::resume_handler ()
116 ACE_TRACE ("ACE_Event_Handler::resume_handler");
118 // Return a default value and allow the reactor to take care of
119 // resuming the handler
120 return ACE_Event_Handler::ACE_REACTOR_RESUMES_HANDLER;
124 ACE_Event_Handler::handle_qos (ACE_HANDLE)
126 ACE_TRACE ("ACE_Event_Handler::handle_qos");
127 return -1;
131 ACE_Event_Handler::handle_group_qos (ACE_HANDLE)
133 ACE_TRACE ("ACE_Event_Handler::handle_group_qos");
134 return -1;
137 void
138 ACE_Event_Handler::reactor (ACE_Reactor *reactor)
140 ACE_TRACE ("ACE_Event_Handler::reactor");
141 this->reactor_ = reactor;
144 ACE_Reactor *
145 ACE_Event_Handler::reactor () const
147 ACE_TRACE ("ACE_Event_Handler::reactor");
148 return this->reactor_;
151 ACE_Reactor_Timer_Interface *
152 ACE_Event_Handler::reactor_timer_interface () const
154 ACE_TRACE ("ACE_Event_Handler::reactor_timer_interface");
155 return this->reactor_;
158 ACE_Event_Handler::Reference_Count
159 ACE_Event_Handler::add_reference ()
161 bool const reference_counting_required =
162 this->reference_counting_policy ().value () ==
163 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
165 if (reference_counting_required)
166 return ++this->reference_count_;
167 else
168 return 1;
171 ACE_Event_Handler::Reference_Count
172 ACE_Event_Handler::remove_reference ()
174 bool const reference_counting_required =
175 this->reference_counting_policy ().value () ==
176 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
178 if (reference_counting_required)
180 Reference_Count const result = --this->reference_count_;
182 if (result == 0)
183 delete this;
185 return result;
187 else
189 return 1;
193 ACE_Event_Handler::Policy::~Policy ()
197 ACE_Event_Handler::Reference_Counting_Policy::Reference_Counting_Policy (Reference_Counting_Policy::Value value)
198 : value_ (value)
202 ACE_Event_Handler::Reference_Counting_Policy::Value
203 ACE_Event_Handler::Reference_Counting_Policy::value () const
205 return this->value_;
208 void
209 ACE_Event_Handler::Reference_Counting_Policy::value (ACE_Event_Handler::Reference_Counting_Policy::Value value)
211 this->value_ = value;
214 ACE_Event_Handler::Reference_Counting_Policy &
215 ACE_Event_Handler::reference_counting_policy ()
217 return this->reference_counting_policy_;
220 ACE_THR_FUNC_RETURN
221 ACE_Event_Handler::read_adapter (void *args)
223 ACE_Event_Handler *this_ptr = static_cast<ACE_Event_Handler *> (args);
224 ACE_Reactor *r = this_ptr->reactor ();
226 while (this_ptr->handle_input (ACE_STDIN) != -1)
227 continue;
229 this_ptr->handle_close (ACE_STDIN, ACE_Event_Handler::READ_MASK);
230 // It's possible for handle_close() to "delete this" so we need to
231 // cache the reactor pointer and use it here.
232 r->notify ();
234 return 0;
238 ACE_Event_Handler::register_stdin_handler (ACE_Event_Handler *eh,
239 ACE_Reactor *reactor,
240 ACE_Thread_Manager *thr_mgr,
241 int flags)
243 #if defined (ACE_WIN32)
244 ACE_UNUSED_ARG (reactor);
246 eh->reactor (reactor);
247 return thr_mgr->spawn (&read_adapter, static_cast<void *> (eh), flags);
248 #else
249 // Keep compilers happy.
250 ACE_UNUSED_ARG (flags);
251 ACE_UNUSED_ARG (thr_mgr);
252 return reactor->register_handler (ACE_STDIN,
254 ACE_Event_Handler::READ_MASK);
255 #endif /* ACE_WIN32 */
259 ACE_Event_Handler::remove_stdin_handler (ACE_Reactor *reactor,
260 ACE_Thread_Manager * /* thr_mgr */)
262 #if defined (ACE_WIN32)
263 ACE_UNUSED_ARG (reactor);
265 // What should we do here?
266 ACE_NOTSUP_RETURN (-1);
267 #else
268 return reactor->remove_handler (ACE_STDIN,
269 ACE_Event_Handler::READ_MASK);
270 #endif /* ACE_WIN32 */
273 // ---------------------------------------------------------------------
275 ACE_Event_Handler_var::ACE_Event_Handler_var ()
276 : ptr_ (0)
280 ACE_Event_Handler_var::ACE_Event_Handler_var (ACE_Event_Handler *p)
281 : ptr_ (p)
285 ACE_Event_Handler_var::ACE_Event_Handler_var (const ACE_Event_Handler_var &b)
286 : ptr_ (b.ptr_)
288 if (this->ptr_ != 0)
290 this->ptr_->add_reference ();
294 ACE_Event_Handler_var::~ACE_Event_Handler_var ()
296 if (this->ptr_ != 0)
298 ACE_Errno_Guard eguard (errno);
299 this->ptr_->remove_reference ();
303 ACE_Event_Handler_var &
304 ACE_Event_Handler_var::operator= (ACE_Event_Handler *p)
306 if (this->ptr_ != p)
308 ACE_Event_Handler_var tmp (p);
309 std::swap (this->ptr_, tmp.ptr_);
312 return *this;
315 ACE_Event_Handler_var &
316 ACE_Event_Handler_var::operator= (const ACE_Event_Handler_var &b)
318 ACE_Event_Handler_var tmp (b);
319 std::swap (this->ptr_, tmp.ptr_);
321 return *this;
324 ACE_Event_Handler *
325 ACE_Event_Handler_var::operator->() const
327 return this->ptr_;
330 ACE_Event_Handler *
331 ACE_Event_Handler_var::handler () const
333 return this->ptr_;
336 ACE_Event_Handler *
337 ACE_Event_Handler_var::release ()
339 ACE_Event_Handler * const old = this->ptr_;
340 this->ptr_ = 0;
341 return old;
344 void
345 ACE_Event_Handler_var::reset (ACE_Event_Handler *p)
347 *this = p;
350 ACE_Event_Handler_var::operator bool() const
352 return this->ptr_ != nullptr;
355 bool
356 ACE_Event_Handler_var::operator ==(std::nullptr_t) const
358 return this->ptr_ == nullptr;
361 bool
362 ACE_Event_Handler_var::operator !=(std::nullptr_t) const
364 return this->ptr_ != nullptr;
367 // ---------------------------------------------------------------------
369 ACE_Notification_Buffer::ACE_Notification_Buffer ()
370 : eh_ (0),
371 mask_ (ACE_Event_Handler::NULL_MASK)
373 ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
376 ACE_Notification_Buffer::ACE_Notification_Buffer (ACE_Event_Handler *eh,
377 ACE_Reactor_Mask mask)
378 : eh_ (eh),
379 mask_ (mask)
381 ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
384 ACE_END_VERSIONED_NAMESPACE_DECL