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 (void)
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
,
90 } while (nfound
== -1 && this->handle_error () > 0);
94 #if !defined (ACE_WIN32)
95 handle_set
.rd_mask_
.sync (this->handler_rep_
.max_handlep1 ());
96 handle_set
.wr_mask_
.sync (this->handler_rep_
.max_handlep1 ());
97 handle_set
.ex_mask_
.sync (this->handler_rep_
.max_handlep1 ());
98 #endif /* ACE_WIN32 */
100 return nfound
; // Timed out or input available
104 ACE_FlReactor::fl_io_proc (int fd
, void* reactor
)
106 ACE_FlReactor
*self
= static_cast<ACE_FlReactor
*> (reactor
);
107 ACE_HANDLE handle
= (ACE_HANDLE
)fd
; //reinterpret_cast<ACE_HANDLE> (fd);
109 // my copy isn't const.
110 ACE_Time_Value zero
= ACE_Time_Value::zero
;
112 ACE_Select_Reactor_Handle_Set wait_set
;
114 // Deal with one file event.
116 // - read which kind of event
117 if (self
->wait_set_
.rd_mask_
.is_set (handle
))
118 wait_set
.rd_mask_
.set_bit (handle
);
119 if (self
->wait_set_
.wr_mask_
.is_set (handle
))
120 wait_set
.wr_mask_
.set_bit (handle
);
121 if (self
->wait_set_
.ex_mask_
.is_set (handle
))
122 wait_set
.ex_mask_
.set_bit (handle
);
124 int result
= ACE_OS::select (fd
+ 1,
127 wait_set
.ex_mask_
, &zero
);
129 ACE_Select_Reactor_Handle_Set dispatch_set
;
131 // - Use only that one file event (removes events for other files).
134 if (wait_set
.rd_mask_
.is_set (handle
))
135 dispatch_set
.rd_mask_
.set_bit (handle
);
136 if (wait_set
.wr_mask_
.is_set (handle
))
137 dispatch_set
.wr_mask_
.set_bit (handle
);
138 if (wait_set
.ex_mask_
.is_set (handle
))
139 dispatch_set
.ex_mask_
.set_bit (handle
);
141 self
->dispatch (1, dispatch_set
);
146 ACE_FlReactor::fl_timeout_proc (void* reactor
)
148 ACE_FlReactor
*self
= static_cast<ACE_FlReactor
*> (reactor
);
150 // Deal with any timer events
151 ACE_Select_Reactor_Handle_Set handle_set
;
152 self
->dispatch (0, handle_set
);
153 self
->reset_timeout ();
158 ACE_FlReactor::register_handler_i (ACE_HANDLE handle
,
159 ACE_Event_Handler
*handler
,
160 ACE_Reactor_Mask mask
)
162 ACE_TRACE ("ACE_FlReactor::register_handler_i");
164 int result
= ACE_Select_Reactor::register_handler_i (handle
,
171 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::READ_MASK
))
172 ACE_SET_BITS (condition
, FL_READ
);
173 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::WRITE_MASK
))
174 ACE_SET_BITS (condition
, FL_WRITE
);
175 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::EXCEPT_MASK
))
176 ACE_SET_BITS (condition
, FL_EXCEPT
);
177 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::ACCEPT_MASK
))
178 ACE_SET_BITS (condition
, FL_READ
);
179 if (ACE_BIT_ENABLED (mask
, ACE_Event_Handler::CONNECT_MASK
))
181 ACE_SET_BITS (condition
, FL_WRITE
); // connected, you may write
182 ACE_SET_BITS (condition
, FL_READ
); // connected, you have data/err
187 Fl::add_fd ((int)handle
, // reinterpret_cast<int> (handle),
188 ACE_FlReactor::fl_io_proc
,
195 ACE_FlReactor::register_handler_i (const ACE_Handle_Set
&handles
,
196 ACE_Event_Handler
*handler
,
197 ACE_Reactor_Mask mask
)
199 return ACE_Select_Reactor::register_handler_i (handles
,
205 ACE_FlReactor::remove_handler_i (ACE_HANDLE handle
,
206 ACE_Reactor_Mask mask
)
208 ACE_TRACE ("ACE_FlReactor::remove_handler_i");
210 // In the registration phase we registered first with
211 // ACE_Select_Reactor and then with X. Now we are now doing things
214 // First clean up the corresponding X11Input.
215 Fl::remove_fd ((int)handle
); // reinterpret_cast<int> (handle);
217 // Now let the reactor do its work.
218 return ACE_Select_Reactor::remove_handler_i (handle
,
223 ACE_FlReactor::remove_handler_i (const ACE_Handle_Set
&handles
,
224 ACE_Reactor_Mask mask
)
226 return ACE_Select_Reactor::remove_handler_i (handles
,
230 // The following function ensures there's an Fl timeout for the first
231 // timeout in the Reactor's Timer_Queue.
234 ACE_FlReactor::reset_timeout (void)
236 ACE_Time_Value
*max_wait_time
=
237 this->timer_queue_
->calculate_timeout (0);
239 if (max_wait_time
!= 0)
241 float t
= max_wait_time
->sec ()
242 + max_wait_time
->usec () / 1000000.0F
;
244 ACE_FlReactor::fl_timeout_proc
,
250 ACE_FlReactor::reset_timer_interval
252 const ACE_Time_Value
&interval
)
254 ACE_TRACE ("ACE_FlReactor::reset_timer_interval");
255 ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token
, ace_mon
, this->token_
, -1));
258 ACE_Select_Reactor::reset_timer_interval (timer_id
,
265 this->reset_timeout ();
271 ACE_FlReactor::schedule_timer (ACE_Event_Handler
*event_handler
,
273 const ACE_Time_Value
&delay
,
274 const ACE_Time_Value
&interval
)
276 ACE_TRACE ("ACE_FlReactor::schedule_timer");
277 ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token
, ace_mon
, this->token_
, -1));
279 long result
= ACE_Select_Reactor::schedule_timer (event_handler
,
287 this->reset_timeout ();
293 ACE_FlReactor::cancel_timer (ACE_Event_Handler
*handler
,
294 int dont_call_handle_close
)
296 ACE_TRACE ("ACE_FlReactor::cancel_timer");
298 if (ACE_Select_Reactor::cancel_timer (handler
,
299 dont_call_handle_close
) == -1)
303 this->reset_timeout ();
309 ACE_FlReactor::cancel_timer (long timer_id
,
311 int dont_call_handle_close
)
313 ACE_TRACE ("ACE_FlReactor::cancel_timer");
315 if (ACE_Select_Reactor::cancel_timer (timer_id
,
317 dont_call_handle_close
) == -1)
321 this->reset_timeout ();
326 ACE_END_VERSIONED_NAMESPACE_DECL