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__ */
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
,
21 : reference_count_ (1),
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.
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.
44 ACE_Event_Handler::set_handle (ACE_HANDLE
)
46 ACE_TRACE ("ACE_Event_Handler::set_handle");
49 // Gets the priority of this handler.
51 ACE_Event_Handler::priority (void) const
53 ACE_TRACE ("ACE_Event_Handler::priority");
54 return this->priority_
;
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
68 ACE_Event_Handler::handle_close (ACE_HANDLE
, ACE_Reactor_Mask
)
70 ACE_TRACE ("ACE_Event_Handler::handle_close");
74 // Called when input becomes available on fd.
76 ACE_Event_Handler::handle_input (ACE_HANDLE
)
78 ACE_TRACE ("ACE_Event_Handler::handle_input");
82 // Called when output is possible on fd.
84 ACE_Event_Handler::handle_output (ACE_HANDLE
)
86 ACE_TRACE ("ACE_Event_Handler::handle_output");
90 // Called when urgent data is available on fd.
92 ACE_Event_Handler::handle_exception (ACE_HANDLE
)
94 ACE_TRACE ("ACE_Event_Handler::handle_exception");
98 // Called when timer expires, TV stores the current time.
100 ACE_Event_Handler::handle_timeout (const ACE_Time_Value
&, const void *)
102 ACE_TRACE ("ACE_Event_Handler::handle_timeout");
106 // Called when a monitored Process exits
108 ACE_Event_Handler::handle_exit (ACE_Process
*)
110 ACE_TRACE ("ACE_Event_Handler::handle_exit");
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");
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");
140 ACE_Event_Handler::handle_group_qos (ACE_HANDLE
)
142 ACE_TRACE ("ACE_Event_Handler::handle_group_qos");
147 ACE_Event_Handler::reactor (ACE_Reactor
*reactor
)
149 ACE_TRACE ("ACE_Event_Handler::reactor");
150 this->reactor_
= 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_
;
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_
;
203 ACE_Event_Handler::Policy::~Policy (void)
207 ACE_Event_Handler::Reference_Counting_Policy::Reference_Counting_Policy (Reference_Counting_Policy::Value value
)
212 ACE_Event_Handler::Reference_Counting_Policy::Value
213 ACE_Event_Handler::Reference_Counting_Policy::value (void) const
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_
;
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)
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.
248 ACE_Event_Handler::register_stdin_handler (ACE_Event_Handler
*eh
,
249 ACE_Reactor
*reactor
,
250 ACE_Thread_Manager
*thr_mgr
,
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
);
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);
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)
290 ACE_Event_Handler_var::ACE_Event_Handler_var (ACE_Event_Handler
*p
)
295 ACE_Event_Handler_var::ACE_Event_Handler_var (const ACE_Event_Handler_var
&b
)
300 this->ptr_
->add_reference ();
304 ACE_Event_Handler_var::~ACE_Event_Handler_var (void)
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
)
318 ACE_Event_Handler_var
tmp (p
);
319 std::swap (this->ptr_
, tmp
.ptr_
);
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_
);
335 ACE_Event_Handler_var::operator->() const
341 ACE_Event_Handler_var::handler (void) const
347 ACE_Event_Handler_var::release (void)
349 ACE_Event_Handler
* const old
= this->ptr_
;
355 ACE_Event_Handler_var::reset (ACE_Event_Handler
*p
)
360 #if defined (ACE_HAS_CPP11)
361 ACE_Event_Handler_var::operator bool() const
363 return this->ptr_
== nullptr ? false : true;
367 ACE_Event_Handler_var::operator ==(std::nullptr_t
) const
369 return this->ptr_
== nullptr ? true : false;
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)
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
)
394 ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
397 ACE_END_VERSIONED_NAMESPACE_DECL