1 #include "ace/FlReactor/FlReactor.h"
3 #include /**/ <FL/Fl.H>
5 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
7 ACE_ALLOC_HOOK_DEFINE (ACE_FlReactor
)
9 // Must be called with lock held
10 ACE_FlReactor::ACE_FlReactor (size_t size
,
13 : ACE_Select_Reactor (size
, restart
, h
)
15 // When the ACE_Select_Reactor is constructed it creates the notify
16 // pipe and registers it with the register_handler_i() method. The
17 // FlReactor overloads this method BUT because the
18 // register_handler_i occurs when constructing the base class
19 // ACE_Select_Reactor, the ACE_Select_Reactor register_handler_i()
20 // is called not the FlReactor register_handler_i(). This means
21 // that the notify pipe is registered with the ACE_Select_Reactor
22 // event handling code not the FlReactor and so notfications don't
23 // work. To get around this we simply close and re-opened the
24 // notification handler in the constructor of the FlReactor.
26 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
27 this->notify_handler_
->close ();
28 this->notify_handler_
->open (this, 0);
29 #endif /* ACE_MT_SAFE */
32 ACE_FlReactor::~ACE_FlReactor ()
36 // This is just the <wait_for_multiple_events> from ace/Reactor.cpp
37 // but we use the Fl functions to wait for an event, not <select>
40 ACE_FlReactor::wait_for_multiple_events (ACE_Select_Reactor_Handle_Set
&handle_set
,
41 ACE_Time_Value
*max_wait_time
)
43 ACE_TRACE ("ACE_FlReactor::wait_for_multiple_events");
48 max_wait_time
= this->timer_queue_
->calculate_timeout (max_wait_time
);
50 size_t width
= this->handler_rep_
.max_handlep1 ();
51 handle_set
.rd_mask_
= this->wait_set_
.rd_mask_
;
52 handle_set
.wr_mask_
= this->wait_set_
.wr_mask_
;
53 handle_set
.ex_mask_
= this->wait_set_
.ex_mask_
;
55 // Check to make sure our handle's are all usable.
56 ACE_Select_Reactor_Handle_Set temp_set
= handle_set
;
58 ACE_Time_Value zero
= ACE_Time_Value::zero
;
59 if (ACE_OS::select (width
,
64 return -1; // Bad file arguments...
66 // Instead of waiting using <select>, just use the Fl mechanism
67 // to wait for one or more events...
69 // Wait for something to happen.
71 if (max_wait_time
!= 0)
72 t
= max_wait_time
->sec () + max_wait_time
->usec () / 1000000.0F
;
78 // Reset the width, in case it changed during the upcalls.
79 width
= this->handler_rep_
.max_handlep1 ();
81 // Now actually read the result needed by the <Select_Reactor>
83 zero
= ACE_Time_Value::zero
;
84 nfound
= ACE_OS::select (width
,
89 } while (nfound
== -1 && this->handle_error () > 0);
93 #if !defined (ACE_WIN32)
94 handle_set
.rd_mask_
.sync (this->handler_rep_
.max_handlep1 ());
95 handle_set
.wr_mask_
.sync (this->handler_rep_
.max_handlep1 ());
96 handle_set
.ex_mask_
.sync (this->handler_rep_
.max_handlep1 ());
97 #endif /* ACE_WIN32 */
99 return nfound
; // Timed out or input available
103 ACE_FlReactor::fl_io_proc (int fd
, void* reactor
)
105 ACE_FlReactor
*self
= static_cast<ACE_FlReactor
*> (reactor
);
106 ACE_HANDLE handle
= (ACE_HANDLE
)fd
; //reinterpret_cast<ACE_HANDLE> (fd);
108 // my copy isn't const.
109 ACE_Time_Value zero
= ACE_Time_Value::zero
;
111 ACE_Select_Reactor_Handle_Set wait_set
;
113 // Deal with one file event.
115 // - read which kind of event
116 if (self
->wait_set_
.rd_mask_
.is_set (handle
))
117 wait_set
.rd_mask_
.set_bit (handle
);
118 if (self
->wait_set_
.wr_mask_
.is_set (handle
))
119 wait_set
.wr_mask_
.set_bit (handle
);
120 if (self
->wait_set_
.ex_mask_
.is_set (handle
))
121 wait_set
.ex_mask_
.set_bit (handle
);
123 int result
= ACE_OS::select (fd
+ 1,
126 wait_set
.ex_mask_
, &zero
);
128 ACE_Select_Reactor_Handle_Set dispatch_set
;
130 // - Use only that one file event (removes events for other files).
133 if (wait_set
.rd_mask_
.is_set (handle
))
134 dispatch_set
.rd_mask_
.set_bit (handle
);
135 if (wait_set
.wr_mask_
.is_set (handle
))
136 dispatch_set
.wr_mask_
.set_bit (handle
);
137 if (wait_set
.ex_mask_
.is_set (handle
))
138 dispatch_set
.ex_mask_
.set_bit (handle
);
140 self
->dispatch (1, dispatch_set
);
145 ACE_FlReactor::fl_timeout_proc (void* reactor
)
147 ACE_FlReactor
*self
= static_cast<ACE_FlReactor
*> (reactor
);
149 // Deal with any timer events
150 ACE_Select_Reactor_Handle_Set handle_set
;
151 self
->dispatch (0, handle_set
);
152 self
->reset_timeout ();
157 ACE_FlReactor::register_handler_i (ACE_HANDLE handle
,
158 ACE_Event_Handler
*handler
,
159 ACE_Reactor_Mask mask
)
161 ACE_TRACE ("ACE_FlReactor::register_handler_i");
163 int result
= ACE_Select_Reactor::register_handler_i (handle
,
170 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::READ_MASK
))
171 ACE_SET_BITS (condition
, FL_READ
);
172 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::WRITE_MASK
))
173 ACE_SET_BITS (condition
, FL_WRITE
);
174 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::EXCEPT_MASK
))
175 ACE_SET_BITS (condition
, FL_EXCEPT
);
176 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::ACCEPT_MASK
))
177 ACE_SET_BITS (condition
, FL_READ
);
178 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::CONNECT_MASK
))
180 ACE_SET_BITS (condition
, FL_WRITE
); // connected, you may write
181 ACE_SET_BITS (condition
, FL_READ
); // connected, you have data/err
186 Fl::add_fd ((int)handle
, // reinterpret_cast<int> (handle),
187 ACE_FlReactor::fl_io_proc
,
194 ACE_FlReactor::register_handler_i (const ACE_Handle_Set
&handles
,
195 ACE_Event_Handler
*handler
,
196 ACE_Reactor_Mask mask
)
198 return ACE_Select_Reactor::register_handler_i (handles
,
204 ACE_FlReactor::remove_handler_i (ACE_HANDLE handle
,
205 ACE_Reactor_Mask mask
)
207 ACE_TRACE ("ACE_FlReactor::remove_handler_i");
209 // In the registration phase we registered first with
210 // ACE_Select_Reactor and then with X. Now we are now doing things
213 // First clean up the corresponding X11Input.
214 Fl::remove_fd ((int)handle
); // reinterpret_cast<int> (handle);
216 // Now let the reactor do its work.
217 return ACE_Select_Reactor::remove_handler_i (handle
,
222 ACE_FlReactor::remove_handler_i (const ACE_Handle_Set
&handles
,
223 ACE_Reactor_Mask mask
)
225 return ACE_Select_Reactor::remove_handler_i (handles
,
229 // The following function ensures there's an Fl timeout for the first
230 // timeout in the Reactor's Timer_Queue.
233 ACE_FlReactor::reset_timeout ()
235 ACE_Time_Value
*max_wait_time
=
236 this->timer_queue_
->calculate_timeout (0);
238 if (max_wait_time
!= 0)
240 float t
= max_wait_time
->sec ()
241 + max_wait_time
->usec () / 1000000.0F
;
243 ACE_FlReactor::fl_timeout_proc
,
249 ACE_FlReactor::reset_timer_interval
251 const ACE_Time_Value
&interval
)
253 ACE_TRACE ("ACE_FlReactor::reset_timer_interval");
254 ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token
, ace_mon
, this->token_
, -1));
257 ACE_Select_Reactor::reset_timer_interval (timer_id
,
264 this->reset_timeout ();
270 ACE_FlReactor::schedule_timer (ACE_Event_Handler
*event_handler
,
272 const ACE_Time_Value
&delay
,
273 const ACE_Time_Value
&interval
)
275 ACE_TRACE ("ACE_FlReactor::schedule_timer");
276 ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token
, ace_mon
, this->token_
, -1));
278 long result
= ACE_Select_Reactor::schedule_timer (event_handler
,
286 this->reset_timeout ();
292 ACE_FlReactor::cancel_timer (ACE_Event_Handler
*handler
,
293 int dont_call_handle_close
)
295 ACE_TRACE ("ACE_FlReactor::cancel_timer");
297 if (ACE_Select_Reactor::cancel_timer (handler
,
298 dont_call_handle_close
) == -1)
302 this->reset_timeout ();
308 ACE_FlReactor::cancel_timer (long timer_id
,
310 int dont_call_handle_close
)
312 ACE_TRACE ("ACE_FlReactor::cancel_timer");
314 if (ACE_Select_Reactor::cancel_timer (timer_id
,
316 dont_call_handle_close
) == -1)
320 this->reset_timeout ();
325 ACE_END_VERSIONED_NAMESPACE_DECL