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 Member Functions

 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)
virtual int cancel_timer (long timer_id, const void **arg=0, int dont_call_handle_close=1)

Protected Member Functions

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

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

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

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

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


Private Member Functions

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

ACE_FlReactoroperator= (const ACE_FlReactor &)

Static Private Member Functions

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 46 of file FlReactor.h.


Constructor & Destructor Documentation

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

Definition at line 14 of file FlReactor.cpp.

References ACE_Select_Reactor, ACE_Reactor_Notify::close(), and ACE_Reactor_Notify::open().

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

ACE_FlReactor::~ACE_FlReactor void   )  [virtual]
 

Definition at line 36 of file FlReactor.cpp.

00037 {
00038 }

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

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 313 of file FlReactor.cpp.

References ACE_TRACE, ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::cancel_timer(), and reset_timeout().

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

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

Cancel all that match the address of . If is 0 then the method of will be invoked. Returns number of handler's cancelled.

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 297 of file FlReactor.cpp.

References ACE_TRACE, ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::cancel_timer(), and reset_timeout().

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

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

Definition at line 108 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_, and ACE_Select_Reactor_Handle_Set::wr_mask_.

Referenced by register_handler_i().

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

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

Definition at line 150 of file FlReactor.cpp.

References ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dispatch(), and reset_timeout().

Referenced by reset_timeout().

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

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 .

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 199 of file FlReactor.cpp.

References ACE_Reactor_Mask, and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::register_handler_i().

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

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

Register a single .

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 162 of file FlReactor.cpp.

References ACE_BIT_ENABLED, ACE_Reactor_Mask, ACE_SET_BITS, ACE_TRACE, fl_io_proc(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::register_handler_i().

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

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

Remove a set of .

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 227 of file FlReactor.cpp.

References ACE_Reactor_Mask, and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::remove_handler_i().

00229 {
00230   return ACE_Select_Reactor::remove_handler_i (handles,
00231                                                mask);
00232 }

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

Remove the associated with this .

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 209 of file FlReactor.cpp.

References ACE_Reactor_Mask, ACE_TRACE, and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::remove_handler_i().

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

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 238 of file FlReactor.cpp.

References ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::calculate_timeout(), fl_timeout_proc(), ACE_Time_Value::sec(), and ACE_Time_Value::usec().

Referenced by cancel_timer(), fl_timeout_proc(), and schedule_timer().

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

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

Resets the interval of the timer represented by to , which is specified in relative time to the current . If 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 255 of file FlReactor.cpp.

References ACE_GUARD_RETURN, ACE_Select_Reactor_Token, ACE_TRACE, and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::reset_timer_interval().

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

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 275 of file FlReactor.cpp.

References ACE_GUARD_RETURN, ACE_Select_Reactor_Token, ACE_TRACE, reset_timeout(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::schedule_timer().

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

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 44 of file FlReactor.cpp.

References ACE_TRACE, ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::calculate_timeout(), ACE_Select_Reactor_Handle_Set::ex_mask_, ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::handle_error(), 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_Time_Value::usec(), and ACE_Select_Reactor_Handle_Set::wr_mask_.

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


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:22:24 2006 for ACE by doxygen 1.3.6