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"
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
,
17 : reference_count_ (1),
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.
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.
35 ACE_Event_Handler::set_handle (ACE_HANDLE
)
37 ACE_TRACE ("ACE_Event_Handler::set_handle");
40 // Gets the priority of this handler.
42 ACE_Event_Handler::priority () const
44 ACE_TRACE ("ACE_Event_Handler::priority");
45 return this->priority_
;
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
59 ACE_Event_Handler::handle_close (ACE_HANDLE
, ACE_Reactor_Mask
)
61 ACE_TRACE ("ACE_Event_Handler::handle_close");
65 // Called when input becomes available on fd.
67 ACE_Event_Handler::handle_input (ACE_HANDLE
)
69 ACE_TRACE ("ACE_Event_Handler::handle_input");
73 // Called when output is possible on fd.
75 ACE_Event_Handler::handle_output (ACE_HANDLE
)
77 ACE_TRACE ("ACE_Event_Handler::handle_output");
81 // Called when urgent data is available on fd.
83 ACE_Event_Handler::handle_exception (ACE_HANDLE
)
85 ACE_TRACE ("ACE_Event_Handler::handle_exception");
89 // Called when timer expires, TV stores the current time.
91 ACE_Event_Handler::handle_timeout (const ACE_Time_Value
&, const void *)
93 ACE_TRACE ("ACE_Event_Handler::handle_timeout");
97 // Called when a monitored Process exits
99 ACE_Event_Handler::handle_exit (ACE_Process
*)
101 ACE_TRACE ("ACE_Event_Handler::handle_exit");
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");
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");
131 ACE_Event_Handler::handle_group_qos (ACE_HANDLE
)
133 ACE_TRACE ("ACE_Event_Handler::handle_group_qos");
138 ACE_Event_Handler::reactor (ACE_Reactor
*reactor
)
140 ACE_TRACE ("ACE_Event_Handler::reactor");
141 this->reactor_
= 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_
;
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_
;
193 ACE_Event_Handler::Policy::~Policy ()
197 ACE_Event_Handler::Reference_Counting_Policy::Reference_Counting_Policy (Reference_Counting_Policy::Value value
)
202 ACE_Event_Handler::Reference_Counting_Policy::Value
203 ACE_Event_Handler::Reference_Counting_Policy::value () const
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_
;
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)
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.
238 ACE_Event_Handler::register_stdin_handler (ACE_Event_Handler
*eh
,
239 ACE_Reactor
*reactor
,
240 ACE_Thread_Manager
*thr_mgr
,
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
);
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);
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 ()
280 ACE_Event_Handler_var::ACE_Event_Handler_var (ACE_Event_Handler
*p
)
285 ACE_Event_Handler_var::ACE_Event_Handler_var (const ACE_Event_Handler_var
&b
)
290 this->ptr_
->add_reference ();
294 ACE_Event_Handler_var::~ACE_Event_Handler_var ()
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
)
308 ACE_Event_Handler_var
tmp (p
);
309 std::swap (this->ptr_
, tmp
.ptr_
);
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_
);
325 ACE_Event_Handler_var::operator->() const
331 ACE_Event_Handler_var::handler () const
337 ACE_Event_Handler_var::release ()
339 ACE_Event_Handler
* const old
= this->ptr_
;
345 ACE_Event_Handler_var::reset (ACE_Event_Handler
*p
)
350 ACE_Event_Handler_var::operator bool() const
352 return this->ptr_
!= nullptr;
356 ACE_Event_Handler_var::operator ==(std::nullptr_t
) const
358 return this->ptr_
== nullptr;
362 ACE_Event_Handler_var::operator !=(std::nullptr_t
) const
364 return this->ptr_
!= nullptr;
367 // ---------------------------------------------------------------------
369 ACE_Notification_Buffer::ACE_Notification_Buffer ()
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
)
381 ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
384 ACE_END_VERSIONED_NAMESPACE_DECL