Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_FlReactor Class Reference

A Reactor implementation that uses the Fast-Light (FL) toolkit for event demultiplexing. This will let us integrate the FL toolkit with ACE and/or TAO. More...

#include <FlReactor.h>

Inheritance diagram for ACE_FlReactor:

Inheritance graph
[legend]
Collaboration diagram for ACE_FlReactor:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_FlReactor (size_t size=DEFAULT_SIZE, int restart=0, ACE_Sig_Handler *=0)
virtual ~ACE_FlReactor (void)
virtual long schedule_timer (ACE_Event_Handler *event_handler, const void *arg, const ACE_Time_Value &delay, const ACE_Time_Value &interval)
virtual int reset_timer_interval (long timer_id, const ACE_Time_Value &interval)
virtual int cancel_timer (ACE_Event_Handler *handler, int dont_call_handle_close=1)
 Cancel all Event_Handlers that match the address of <event_handler>. Returns number of handlers cancelled. More...

virtual int cancel_timer (long timer_id, const void **arg=0, int dont_call_handle_close=1)

Protected Methods

virtual int register_handler_i (ACE_HANDLE handle, ACE_Event_Handler *handler, ACE_Reactor_Mask mask)
 Register a single <handler>. More...

virtual int register_handler_i (const ACE_Handle_Set &handles, ACE_Event_Handler *handler, ACE_Reactor_Mask mask)
 Register a set of <handlers>. More...

virtual int remove_handler_i (ACE_HANDLE handle, ACE_Reactor_Mask mask)
 Remove the <handler> associated with this <handle>. More...

virtual int remove_handler_i (const ACE_Handle_Set &handles, ACE_Reactor_Mask)
 Remove a set of <handles>. More...

virtual int wait_for_multiple_events (ACE_Select_Reactor_Handle_Set &, ACE_Time_Value *)
 Wait for events to occur. More...


Private Methods

void reset_timeout (void)
 This method ensures there's an Fl timeout for the first timeout in the Reactor's Timer_Queue. More...

 ACE_FlReactor (const ACE_FlReactor &)
 Deny access since member-wise won't work... More...

ACE_FlReactor & operator= (const ACE_FlReactor &)

Static Private Methods

void fl_io_proc (int fd, void *)
void fl_timeout_proc (void *)

Detailed Description

A Reactor implementation that uses the Fast-Light (FL) toolkit for event demultiplexing. This will let us integrate the FL toolkit with ACE and/or TAO.

As many other GUI toolkits FL supports a minimal set of callbacks to handle event demultiplexing, namely simple methods to add file descriptors to the event demuxing set or timeout events. This class adapts this simple mechanisms so they are compatible with ACE's Reactor.

Definition at line 45 of file FlReactor.h.


Constructor & Destructor Documentation

ACE_FlReactor::ACE_FlReactor size_t    size = DEFAULT_SIZE,
int    restart = 0,
ACE_Sig_Handler   = 0
 

Definition at line 16 of file FlReactor.cpp.

References ACE_Reactor_Notify::close, ACE_Select_Reactor_Impl::notify_handler_, and ACE_Reactor_Notify::open.

00019   : ACE_Select_Reactor (size, restart, h)
00020 {
00021   // When the ACE_Select_Reactor is constructed it creates the notify
00022   // pipe and registers it with the register_handler_i() method. The
00023   // FlReactor overloads this method BUT because the
00024   // register_handler_i occurs when constructing the base class
00025   // ACE_Select_Reactor, the ACE_Select_Reactor register_handler_i()
00026   // is called not the FlReactor register_handler_i().  This means
00027   // that the notify pipe is registered with the ACE_Select_Reactor
00028   // event handling code not the FlReactor and so notfications don't
00029   // work.  To get around this we simply close and re-opened the
00030   // notification handler in the constructor of the FlReactor.
00031 
00032 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00033   this->notify_handler_->close ();
00034   this->notify_handler_->open (this, 0);
00035 #endif /* ACE_MT_SAFE */
00036 }

ACE_FlReactor::~ACE_FlReactor void    [virtual]
 

Definition at line 38 of file FlReactor.cpp.

00039 {
00040 }

ACE_FlReactor::ACE_FlReactor const ACE_FlReactor &    [private]
 

Deny access since member-wise won't work...


Member Function Documentation

int ACE_FlReactor::cancel_timer long    timer_id,
const void **    arg = 0,
int    dont_call_handle_close = 1
[virtual]
 

Cancel the single Event_Handler that matches the <timer_id> value (which was returned from the schedule method). If arg is non-NULL then it will be set to point to the ``magic cookie'' argument passed in when the Event_Handler was registered. This makes it possible to free up the memory and avoid memory leaks. Returns 1 if cancellation succeeded and 0 if the <timer_id> wasn't found.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 315 of file FlReactor.cpp.

References ACE_TRACE, ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::cancel_timer, and reset_timeout.

00318 {
00319   ACE_TRACE ("ACE_FlReactor::cancel_timer");
00320 
00321   if (ACE_Select_Reactor::cancel_timer (timer_id,
00322                                         arg,
00323                                         dont_call_handle_close) == -1)
00324     return -1;
00325   else
00326     {
00327       this->reset_timeout ();
00328       return 0;
00329     }
00330 }

int ACE_FlReactor::cancel_timer ACE_Event_Handler   handler,
int    dont_call_handle_close = 1
[virtual]
 

Cancel all Event_Handlers that match the address of <event_handler>. Returns number of handlers cancelled.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 299 of file FlReactor.cpp.

References ACE_TRACE, ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::cancel_timer, and reset_timeout.

00301 {
00302   ACE_TRACE ("ACE_FlReactor::cancel_timer");
00303 
00304   if (ACE_Select_Reactor::cancel_timer (handler,
00305                                         dont_call_handle_close) == -1)
00306     return -1;
00307   else
00308     {
00309       this->reset_timeout ();
00310       return 0;
00311     }
00312 }

void ACE_FlReactor::fl_io_proc int    fd,
void *   
[static, private]
 

Definition at line 110 of file FlReactor.cpp.

References ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::dispatch, ACE_Select_Reactor_Handle_Set::ex_mask_, ACE_Handle_Set::is_set, ACE_Select_Reactor_Handle_Set::rd_mask_, ACE_OS::select, ACE_Handle_Set::set_bit, ACE_Select_Reactor_Impl::wait_set_, ACE_Select_Reactor_Handle_Set::wr_mask_, and ACE_Time_Value::zero.

Referenced by register_handler_i.

00111 {
00112   ACE_FlReactor *self = ACE_static_cast(ACE_FlReactor *, reactor);
00113   ACE_HANDLE handle = (ACE_HANDLE)fd; //ACE_reinterpret_cast(ACE_HANDLE, fd);
00114 
00115   // my copy isn't const.
00116   ACE_Time_Value zero = ACE_Time_Value::zero;
00117 
00118   ACE_Select_Reactor_Handle_Set wait_set;
00119 
00120   // Deal with one file event.
00121 
00122   // - read which kind of event
00123   if (self->wait_set_.rd_mask_.is_set (handle))
00124     wait_set.rd_mask_.set_bit (handle);
00125   if (self->wait_set_.wr_mask_.is_set (handle))
00126     wait_set.wr_mask_.set_bit (handle);
00127   if (self->wait_set_.ex_mask_.is_set (handle))
00128     wait_set.ex_mask_.set_bit (handle);
00129 
00130   int result = ACE_OS::select (fd + 1,
00131                                wait_set.rd_mask_,
00132                                wait_set.wr_mask_,
00133                                wait_set.ex_mask_, &zero);
00134 
00135   ACE_Select_Reactor_Handle_Set dispatch_set;
00136 
00137   // - Use only that one file event (removes events for other files).
00138   if (result > 0)
00139     {
00140       if (wait_set.rd_mask_.is_set (handle))
00141         dispatch_set.rd_mask_.set_bit (handle);
00142       if (wait_set.wr_mask_.is_set (handle))
00143         dispatch_set.wr_mask_.set_bit (handle);
00144       if (wait_set.ex_mask_.is_set (handle))
00145         dispatch_set.ex_mask_.set_bit (handle);
00146 
00147       self->dispatch (1, dispatch_set);
00148     }
00149 }

void ACE_FlReactor::fl_timeout_proc void *    [static, private]
 

Definition at line 152 of file FlReactor.cpp.

References ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::dispatch, and reset_timeout.

Referenced by reset_timeout.

00153 {
00154   ACE_FlReactor *self = ACE_static_cast (ACE_FlReactor *, reactor);
00155 
00156   // Deal with any timer events
00157   ACE_Select_Reactor_Handle_Set handle_set;
00158   self->dispatch (0, handle_set);
00159   self->reset_timeout ();
00160 }

ACE_FlReactor& ACE_FlReactor::operator= const ACE_FlReactor &    [private]
 

int ACE_FlReactor::register_handler_i const ACE_Handle_Set   handles,
ACE_Event_Handler   handler,
ACE_Reactor_Mask    mask
[protected, virtual]
 

Register a set of <handlers>.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 201 of file FlReactor.cpp.

References ACE_Reactor_Mask, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::register_handler_i.

00204 {
00205   return ACE_Select_Reactor::register_handler_i (handles,
00206                                                  handler,
00207                                                  mask);
00208 }

int ACE_FlReactor::register_handler_i ACE_HANDLE    handle,
ACE_Event_Handler   handler,
ACE_Reactor_Mask    mask
[protected, virtual]
 

Register a single <handler>.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 164 of file FlReactor.cpp.

References ACE_Event_Handler::ACCEPT_MASK, ACE_BIT_ENABLED, ACE_Reactor_Mask, ACE_SET_BITS, ACE_TRACE, ACE_Event_Handler::CONNECT_MASK, ACE_Event_Handler::EXCEPT_MASK, fl_io_proc, ACE_Event_Handler::READ_MASK, ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::register_handler_i, and ACE_Event_Handler::WRITE_MASK.

00167 {
00168   ACE_TRACE ("ACE_FlReactor::register_handler_i");
00169 
00170   int result = ACE_Select_Reactor::register_handler_i (handle,
00171                                                        handler, mask);
00172   if (result == -1)
00173     return -1;
00174 
00175   int condition = 0;
00176 
00177   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK))
00178     ACE_SET_BITS (condition, FL_READ);
00179   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::WRITE_MASK))
00180     ACE_SET_BITS (condition, FL_WRITE);
00181   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK))
00182     ACE_SET_BITS (condition, FL_EXCEPT);
00183   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK))
00184     ACE_SET_BITS (condition, FL_READ);
00185   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK))
00186     {
00187       ACE_SET_BITS (condition, FL_WRITE); // connected, you may write
00188       ACE_SET_BITS (condition, FL_READ);  // connected, you have data/err
00189     }
00190 
00191   if (condition != 0)
00192     {
00193       Fl::add_fd ((int)handle, // ACE_reinterpret_cast(int,handle),
00194                   ACE_FlReactor::fl_io_proc,
00195                   this);
00196     }
00197   return 0;
00198 }

int ACE_FlReactor::remove_handler_i const ACE_Handle_Set   handles,
ACE_Reactor_Mask   
[protected, virtual]
 

Remove a set of <handles>.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 229 of file FlReactor.cpp.

References ACE_Reactor_Mask, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::remove_handler_i.

00231 {
00232   return ACE_Select_Reactor::remove_handler_i (handles,
00233                                                mask);
00234 }

int ACE_FlReactor::remove_handler_i ACE_HANDLE    handle,
ACE_Reactor_Mask    mask
[protected, virtual]
 

Remove the <handler> associated with this <handle>.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 211 of file FlReactor.cpp.

References ACE_Reactor_Mask, ACE_TRACE, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::remove_handler_i.

00213 {
00214   ACE_TRACE ("ACE_FlReactor::remove_handler_i");
00215 
00216   // In the registration phase we registered first with
00217   // ACE_Select_Reactor and then with X.  Now we are now doing things
00218   // in reverse order.
00219 
00220   // First clean up the corresponding X11Input.
00221   Fl::remove_fd ((int)handle); // ACE_reinterpret_cast(int,handle));
00222 
00223   // Now let the reactor do its work.
00224   return ACE_Select_Reactor::remove_handler_i (handle,
00225                                                mask);
00226 }

void ACE_FlReactor::reset_timeout void    [private]
 

This method ensures there's an Fl timeout for the first timeout in the Reactor's Timer_Queue.

Definition at line 240 of file FlReactor.cpp.

References ACE_Timer_Queue_T< ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall< ACE_SYNCH_RECURSIVE_MUTEX >, ACE_SYNCH_RECURSIVE_MUTEX >::calculate_timeout, fl_timeout_proc, ACE_Time_Value::sec, ACE_Select_Reactor_Impl::timer_queue_, and ACE_Time_Value::usec.

Referenced by cancel_timer, fl_timeout_proc, and schedule_timer.

00241 {
00242   ACE_Time_Value *max_wait_time =
00243     this->timer_queue_->calculate_timeout (0);
00244 
00245   if (max_wait_time != 0)
00246     {
00247       float t = max_wait_time->sec ()
00248         + max_wait_time->usec () / 1000000.0F;
00249       Fl::add_timeout (t,
00250                        ACE_FlReactor::fl_timeout_proc,
00251                        this);
00252     }
00253 }

int ACE_FlReactor::reset_timer_interval long    timer_id,
const ACE_Time_Value   interval
[virtual]
 

Resets the interval of the timer represented by <timer_id> to <interval>, which is specified in relative time to the current <gettimeofday>. If <interval> is equal to <ACE_Time_Value::zero>, the timer will become a non-rescheduling timer. Returns 0 if successful, -1 if not.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 257 of file FlReactor.cpp.

References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::reset_timer_interval.

00259 {
00260   ACE_TRACE ("ACE_FlReactor::reset_timer_interval");
00261   ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token, ace_mon, this->token_, -1));
00262 
00263   int result =
00264     ACE_Select_Reactor::reset_timer_interval (timer_id,
00265                                               interval);
00266 
00267   if (result == -1)
00268     return -1;
00269   else
00270     {
00271       this->reset_timeout ();
00272       return result;
00273     }
00274 }

long ACE_FlReactor::schedule_timer ACE_Event_Handler   event_handler,
const void *    arg,
const ACE_Time_Value   delay,
const ACE_Time_Value   interval
[virtual]
 

Schedule an ACE_Event_Handler that will expire after an amount of time. The return value of this method, a timer_id value, uniquely identifies the event_handler in the ACE_Reactor's internal list of timers. This timer_id value can be used to cancel the timer with the cancel_timer() call.

See also:
cancel_timer() , reset_timer_interval()
Parameters:
event_handler  event handler to schedule on reactor
arg  argument passed to the handle_timeout() method of event_handler
delay  time interval after which the timer will expire
interval  time interval after which the timer will be automatically rescheduled
Returns:
-1 on failure, a timer_id value on success

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 277 of file FlReactor.cpp.

References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, reset_timeout, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::schedule_timer.

00281 {
00282   ACE_TRACE ("ACE_FlReactor::schedule_timer");
00283   ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token, ace_mon, this->token_, -1));
00284 
00285   long result = ACE_Select_Reactor::schedule_timer (event_handler,
00286                                                     arg,
00287                                                     delay,
00288                                                     interval);
00289   if (result == -1)
00290     return -1;
00291   else
00292     {
00293       this->reset_timeout ();
00294       return result;
00295     }
00296 }

int ACE_FlReactor::wait_for_multiple_events ACE_Select_Reactor_Handle_Set  ,
ACE_Time_Value  
[protected, virtual]
 

Wait for events to occur.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 46 of file FlReactor.cpp.

References ACE_TRACE, ACE_Timer_Queue_T< ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall< ACE_SYNCH_RECURSIVE_MUTEX >, ACE_SYNCH_RECURSIVE_MUTEX >::calculate_timeout, ACE_Select_Reactor_Handle_Set::ex_mask_, ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::handle_error, ACE_Select_Reactor_Impl::handler_rep_, ACE_Select_Reactor_Handler_Repository::max_handlep1, ACE_Select_Reactor_Handle_Set::rd_mask_, ACE_Time_Value::sec, ACE_OS::select, ACE_Handle_Set::sync, ACE_Select_Reactor_Impl::timer_queue_, ACE_Time_Value::usec, ACE_Select_Reactor_Impl::wait_set_, ACE_Select_Reactor_Handle_Set::wr_mask_, and ACE_Time_Value::zero.

00048 {
00049   ACE_TRACE ("ACE_FlReactor::wait_for_multiple_events");
00050   int nfound;
00051 
00052   do
00053     {
00054       max_wait_time = this->timer_queue_->calculate_timeout (max_wait_time);
00055 
00056       size_t width = this->handler_rep_.max_handlep1 ();
00057       handle_set.rd_mask_ = this->wait_set_.rd_mask_;
00058       handle_set.wr_mask_ = this->wait_set_.wr_mask_;
00059       handle_set.ex_mask_ = this->wait_set_.ex_mask_;
00060 
00061       // Check to make sure our handle's are all usable.
00062       ACE_Select_Reactor_Handle_Set temp_set = handle_set;
00063 
00064       ACE_Time_Value zero = ACE_Time_Value::zero;
00065       if (ACE_OS::select (width,
00066                           temp_set.rd_mask_,
00067                           temp_set.wr_mask_,
00068                           temp_set.ex_mask_,
00069                           &zero) == -1)
00070         return -1; // Bad file arguments...
00071 
00072       // Instead of waiting using <select>, just use the Fl mechanism
00073       // to wait for one or more events...
00074 
00075       // Wait for something to happen.
00076       double t = 0;
00077       if (max_wait_time != 0)
00078         t = max_wait_time->sec () + max_wait_time->usec () / 1000000.0F;
00079 
00080       while (t > 0) {
00081         t = Fl::wait (t);
00082       }
00083 
00084       // Reset the width, in case it changed during the upcalls.
00085       width = this->handler_rep_.max_handlep1 ();
00086 
00087       // Now actually read the result needed by the <Select_Reactor>
00088       // using <select>.
00089       zero = ACE_Time_Value::zero;
00090       nfound = ACE_OS::select (width,
00091                                handle_set.rd_mask_,
00092                                handle_set.wr_mask_,
00093                                handle_set.ex_mask_,
00094                                &zero);
00095 
00096     } while (nfound == -1 && this->handle_error () > 0);
00097 
00098   if (nfound > 0)
00099     {
00100 #if !defined (ACE_WIN32)
00101       handle_set.rd_mask_.sync (this->handler_rep_.max_handlep1 ());
00102       handle_set.wr_mask_.sync (this->handler_rep_.max_handlep1 ());
00103       handle_set.ex_mask_.sync (this->handler_rep_.max_handlep1 ());
00104 #endif /* ACE_WIN32 */
00105     }
00106   return nfound; // Timed out or input available
00107 }


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:48:04 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002