ACE_QtReactor Class Reference

An object-oriented event demultiplexor and event handler dispatcher that uses the Qt Library. This class declaration also uses the extension facilities provided by the Qt. So, readers of the class declaration should not be upset with the appearence of the Keywords like Q_OBJECT, private slots etc. They are specific to Qt which uses these as a call back methods implementation mechanism. More...

#include <QtReactor.h>

Inheritance diagram for ACE_QtReactor:

Inheritance graph
[legend]
Collaboration diagram for ACE_QtReactor:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_QtReactor (QApplication *qapp=0, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0, int disable_notify_pipe=0, ACE_Reactor_Notify *notify=0, int mask_signals=1, int s_queue=ACE_SELECT_TOKEN::FIFO)
 Constructor follows .

 ACE_QtReactor (size_t size, QApplication *qapp=0, int restart=0, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0, int disable_notify_pipe=0, ACE_Reactor_Notify *notify=0, int mask_signals=1, int s_queue=ACE_SELECT_TOKEN::FIFO)
 Constructor follows .

virtual ~ACE_QtReactor (void)
void qapplication (QApplication *qapp)
virtual long schedule_timer (ACE_Event_Handler *handler, const void *arg, const ACE_Time_Value &delay_time, 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 Types

typedef ACE_Map_Manager< ACE_HANDLE,
QSocketNotifier *, ACE_Null_Mutex
MAP
 Typedef of a map.


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 with Qt.

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 mask)
 Remove a set of .

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

virtual int QtWaitForMultipleEvents (int width, ACE_Select_Reactor_Handle_Set &wait_set, ACE_Time_Value *max_wait_time)
virtual int bit_ops (ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Select_Reactor_Handle_Set &handle_set, int ops)
 Allow manipulation of the mask and mask.

int set_enable_flag_by_mask (int flag_value, ACE_HANDLE handle, ACE_Reactor_Mask mask)
void create_notifiers_for_handle (ACE_HANDLE handle)
void destroy_notifiers_for_handle (ACE_HANDLE handle)

Protected Attributes

QApplication * qapp_
 Some Qt stuff that we need to have.

MAP read_notifier_
 A notifier for a read.

MAP write_notifier_
 A write notifier.

MAP exception_notifier_
 An exception notifier.

QTimer * qtime_
 The timer class that would provide timer-sgnals & single-shot timers.


Private Slots

void read_event (int FD)
 Dispatch a Read Event.

void write_event (int FD)
 Dispatch a Write Event.

void exception_event (int FD)
 Dispatch an exception event.

void timeout_event (void)
 Dispach a timeout event.


Private Member Functions

void reset_timeout (void)
void reopen_notification_pipe (void)
 reopens notification pipe to create SocketNotifier for it

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

ACE_QtReactoroperator= (const ACE_QtReactor &)

Detailed Description

An object-oriented event demultiplexor and event handler dispatcher that uses the Qt Library. This class declaration also uses the extension facilities provided by the Qt. So, readers of the class declaration should not be upset with the appearence of the Keywords like Q_OBJECT, private slots etc. They are specific to Qt which uses these as a call back methods implementation mechanism.

Note:
Marek Brudka <mbrudka@elka.pw.edu.pl>: ACE_QtReactor was quickly bugfixed to meet ACE 5.4.2 (6.0.0?) deadline. While it passes QtReactor_Test now, there is a great room for improvements as the implementation is rather inefficient and obfuscated To be more specific:

Definition at line 84 of file QtReactor.h.


Member Typedef Documentation

typedef ACE_Map_Manager<ACE_HANDLE, QSocketNotifier *, ACE_Null_Mutex> ACE_QtReactor::MAP [protected]
 

Typedef of a map.

Definition at line 179 of file QtReactor.h.


Constructor & Destructor Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_QtReactor::ACE_QtReactor QApplication *  qapp = 0,
ACE_Sig_Handler = 0,
ACE_Timer_Queue = 0,
int  disable_notify_pipe = 0,
ACE_Reactor_Notify notify = 0,
int  mask_signals = 1,
int  s_queue = ACE_SELECT_TOKEN::FIFO
 

Constructor follows .

Parameters:
QApplication *qapp, qapplication which runs events loop

Definition at line 11 of file QtReactor.cpp.

References ACE_Select_Reactor, ACE_Timer_Queue, and reopen_notification_pipe().

00017                  :
00018     ACE_Select_Reactor( sh, tq, disable_notify_pipe,
00019         notify, mask_signals, s_queue),
00020     qapp_(qapp),
00021     qtime_ (0)
00022 {
00023     reopen_notification_pipe();
00024 }

ACE_QtReactor::ACE_QtReactor size_t  size,
QApplication *  qapp = 0,
int  restart = 0,
ACE_Sig_Handler = 0,
ACE_Timer_Queue = 0,
int  disable_notify_pipe = 0,
ACE_Reactor_Notify notify = 0,
int  mask_signals = 1,
int  s_queue = ACE_SELECT_TOKEN::FIFO
 

Constructor follows .

Parameters:
QApplication *qapp, qapplication which runs events loop

Definition at line 27 of file QtReactor.cpp.

References ACE_Select_Reactor, ACE_Timer_Queue, and reopen_notification_pipe().

00035                 :
00036     ACE_Select_Reactor( size, restart, sh, tq,
00037         disable_notify_pipe, notify, mask_signals,
00038         s_queue ),
00039     qapp_(qapp),
00040     qtime_ (0)
00041 
00042 {
00043     reopen_notification_pipe();
00044 }

ACE_QtReactor::~ACE_QtReactor void   )  [virtual]
 

Definition at line 73 of file QtReactor.cpp.

References ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::begin(), ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::end(), exception_notifier_, qtime_, read_notifier_, and write_notifier_.

00074 {
00075     // iterate over QSocketNotifiers for read and release them
00076     MAP::ITERATOR iter = this->read_notifier_.begin ();
00077     MAP::ITERATOR iterEnd = this->read_notifier_.end ();
00078     while( iter != iterEnd )
00079     {
00080         MAP::ENTRY &entry = *iter;
00081         // QOBject destructor notifies qapplication (hopefully) on delete
00082         delete entry.int_id_;
00083         ++iter;
00084     }
00085 
00086     // iterate over QSocketNotifiers for write and release them
00087     this->write_notifier_.begin ();
00088     this->write_notifier_.end ();
00089     while( iter != iterEnd )
00090     {
00091         MAP::ENTRY &entry = *iter;
00092         // QOBject destructor notifies qapplication (hopefully) on delete
00093         delete entry.int_id_;
00094         ++iter;
00095     }
00096 
00097     // iterate over QSocketNotifiers for exceptions and release them
00098     this->exception_notifier_.begin ();
00099     this->exception_notifier_.end ();
00100     while( iter != iterEnd )
00101     {
00102         MAP::ENTRY &entry = *iter;
00103         // QOBject destructor notifies qapplication (hopefully) on delete
00104         delete entry.int_id_;
00105         ++iter;
00106     }
00107 
00108     // QOBject destructor notifies qapplication (hopefully) on delete
00109     delete qtime_;
00110 }

ACE_QtReactor::ACE_QtReactor const ACE_QtReactor  )  [private]
 

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


Member Function Documentation

int ACE_QtReactor::bit_ops ACE_HANDLE  handle,
ACE_Reactor_Mask  mask,
ACE_Select_Reactor_Handle_Set handle_set,
int  ops
[protected, virtual]
 

Allow manipulation of the mask and mask.

Reimplemented from ACE_Select_Reactor_Impl.

Definition at line 262 of file QtReactor.cpp.

References ACE_Reactor_Mask, ACE_Select_Reactor_Impl::bit_ops(), and set_enable_flag_by_mask().

00266 {
00267   int result;
00268   ACE_Select_Reactor_Handle_Set preserved_handle_set = handle_set;
00269 
00270   // Call regular bit_ops
00271   if ((result = ACE_Select_Reactor::bit_ops (handle, mask, handle_set, ops)) == -1)
00272     return -1;
00273 
00274   // disable or enable the notifiers based on handle_set and mask
00275   int enableFlag = -1;
00276   if (&handle_set == &this->suspend_set_)
00277     enableFlag = 0;
00278   else if (&handle_set == &this->wait_set_)
00279     enableFlag = 1;
00280   else
00281     // We have no work to do here, so just return
00282     return result;
00283 
00284   switch (ops)
00285     {
00286     case ACE_Reactor::SET_MASK:
00287     case ACE_Reactor::ADD_MASK:
00288       // Enable or disable notifiers based on the specified masks
00289       if (this->set_enable_flag_by_mask (enableFlag, handle, mask) == -1)
00290         {
00291           // We can't just return -1 here because we'll have half-changed things.
00292           // So, we need to restore the old handle_set, then return -1.
00293           handle_set = preserved_handle_set;
00294           return -1;
00295         }
00296       break;
00297 
00298     case ACE_Reactor::CLR_MASK:
00299       if (this->set_enable_flag_by_mask (!enableFlag, handle, mask) == -1)
00300         {
00301           handle_set = preserved_handle_set;
00302           return -1;
00303         }
00304       break;
00305 
00306     default:
00307       // we take no action for any other operations
00308       break;
00309     }
00310 
00311   return result;
00312 }

int ACE_QtReactor::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 545 of file QtReactor.cpp.

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

00548 {
00549   ACE_TRACE ("ACE_QtReactor::cancel_timer") ;
00550 
00551   if (ACE_Select_Reactor::cancel_timer (timer_id,
00552                                         arg,
00553                                         dont_call_handle_close ) == -1 )
00554     return -1 ;
00555   else
00556   {
00557     this->reset_timeout( ) ;
00558     return 0 ;
00559   }
00560 }

int ACE_QtReactor::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 530 of file QtReactor.cpp.

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

00532 {
00533   ACE_TRACE ("ACE_QtReactor::cancel_timer");
00534 
00535   if (ACE_Select_Reactor::cancel_timer (handler,
00536                                         dont_call_handle_close ) == -1 )
00537     return -1 ;
00538   else
00539   {
00540     this->reset_timeout( ) ;
00541     return 0 ;
00542   }
00543 }

void ACE_QtReactor::create_notifiers_for_handle ACE_HANDLE  handle  )  [protected]
 

Definition at line 315 of file QtReactor.cpp.

References ACE_NEW, ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::bind(), exception_event(), exception_notifier_, ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find(), read_event(), read_notifier_, write_event(), and write_notifier_.

Referenced by register_handler_i().

00316 {
00317     QSocketNotifier *qsock_notifier = 0;
00318 
00319     // if there is already a read socket notifier for this handle, do nothing
00320     // otherwise create read notifier
00321     if ( ( this->read_notifier_.find (handle,
00322                qsock_notifier) == -1) )
00323     {
00324         ACE_NEW (qsock_notifier,
00325             QSocketNotifier (int(handle), QSocketNotifier::Read, this));
00326         this->read_notifier_.bind (handle,
00327             qsock_notifier);
00328         QObject::connect (qsock_notifier,
00329             SIGNAL (activated (int)),
00330             this,
00331             SLOT (read_event (int))) ;
00332         // disable; it will be enabled by the regular register_handler_i if
00333         // necessary
00334         qsock_notifier->setEnabled (0);
00335     }
00336 
00337     qsock_notifier = 0;
00338 
00339 
00340     // if there is already a write socket notifier for this handle, do nothing
00341     // otherwise create read notifier
00342     if ((this->write_notifier_.find (handle,
00343              qsock_notifier) == -1))
00344     {
00345         ACE_NEW (qsock_notifier,
00346             QSocketNotifier (int(handle), QSocketNotifier::Write, this));
00347 
00348         this->write_notifier_.bind (handle,
00349             qsock_notifier);
00350 
00351         QObject::connect (qsock_notifier,
00352             SIGNAL (activated (int)),
00353             this,
00354             SLOT (write_event (int)));
00355         // disable; it will be enabled by the regular register_handler_i if
00356         // necessary
00357         qsock_notifier->setEnabled (0);
00358     }
00359 
00360 
00361     qsock_notifier = 0;
00362 
00363     // if there is already a write socket notifier for this handle, do nothing
00364     // otherwise create read notifier
00365     if ((this->exception_notifier_.find (handle,
00366              qsock_notifier) == -1))
00367     {
00368 
00369         ACE_NEW (qsock_notifier,
00370             QSocketNotifier (int(handle), QSocketNotifier::Exception, this));
00371 
00372         this->exception_notifier_.bind (handle,
00373             qsock_notifier);
00374 
00375         QObject::connect (qsock_notifier,
00376             SIGNAL (activated (int)),
00377             this,
00378             SLOT (exception_event (int))) ;
00379         // disable; it will be enabled by the regular register_handler_i if
00380         // necessary
00381         qsock_notifier->setEnabled (0);
00382     }
00383 }

void ACE_QtReactor::destroy_notifiers_for_handle ACE_HANDLE  handle  )  [protected]
 

Definition at line 386 of file QtReactor.cpp.

References exception_notifier_, ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find(), read_notifier_, ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::unbind(), and write_notifier_.

Referenced by register_handler_i(), and remove_handler_i().

00387 {
00388   QSocketNotifier *qsock_notifier = 0;
00389 
00390   // Looks for the handle in the maps and removes them.
00391 
00392   if ((this->read_notifier_.find (handle,
00393                                   qsock_notifier) != -1))
00394     {
00395       this->read_notifier_.unbind (handle,
00396                                    qsock_notifier);
00397       delete qsock_notifier;
00398     }
00399 
00400   if ((this->write_notifier_.find (handle,
00401                                    qsock_notifier) != -1))
00402     {
00403       this->write_notifier_.unbind (handle,
00404                                     qsock_notifier);
00405       delete qsock_notifier;
00406     }
00407 
00408 
00409   if ((this->exception_notifier_.find (handle,
00410                                        qsock_notifier) != -1))
00411     {
00412       this->exception_notifier_.unbind (handle,
00413                                         qsock_notifier);
00414       delete qsock_notifier;
00415     }
00416 }

void ACE_QtReactor::exception_event int  FD  )  [private, slot]
 

Dispatch an exception event.

Definition at line 190 of file QtReactor.cpp.

References ACE_Reactor_Mask, ACE_TRACE, ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dispatch(), ACE_Select_Reactor_Handle_Set::ex_mask_, exception_notifier_, ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::mask_ops(), ACE_Handle_Set::set_bit(), and set_enable_flag_by_mask().

Referenced by create_notifiers_for_handle().

00191 {
00192   ACE_TRACE ("ACE_QtReactor::exception_event");
00193 
00194   ACE_HANDLE handle = ACE_HANDLE( p_handle );
00195 
00196 
00197 #ifdef ACE_QTREACTOR_CLEAR_PENDING_EVENTS
00198   // disable socket notifier to clear pending events
00199   QSocketNotifier *qsock_notifier = 0;
00200   if ( ( this->exception_notifier_.find( handle, qsock_notifier) != -1) )
00201     qsock_notifier->setEnabled( false );
00202 #endif /* ACE_QTREACTOR_CLEAR_PENDING_EVENTS  */
00203 
00204   // The core of exception event handling
00205   ACE_Select_Reactor_Handle_Set dispatch_set;
00206 
00207   dispatch_set.ex_mask_.set_bit( handle );
00208   dispatch (1, dispatch_set);
00209 
00210 #ifdef ACE_QTREACTOR_CLEAR_PENDING_EVENTS
00211   // enable socket notifier according to current mask
00212   ACE_Reactor_Mask mask = 0;
00213   mask = mask_ops( handle, mask, ACE_Reactor::GET_MASK );
00214   if ( -1 != mask )
00215         set_enable_flag_by_mask ( 1, handle, mask);
00216 #endif /* ACE_QTREACTOR_CLEAR_PENDING_EVENTS  */
00217 }

ACE_QtReactor& ACE_QtReactor::operator= const ACE_QtReactor  )  [private]
 

void ACE_QtReactor::qapplication QApplication *  qapp  ) 
 

Definition at line 113 of file QtReactor.cpp.

References qapp_.

00114 {
00115   // reparent QSocketNotifiers and QTimer
00116   qapp_ = qapp ;
00117 }

int ACE_QtReactor::QtWaitForMultipleEvents int  width,
ACE_Select_Reactor_Handle_Set wait_set,
ACE_Time_Value max_wait_time
[protected, virtual]
 

Definition at line 564 of file QtReactor.cpp.

References ACE_Select_Reactor_Handle_Set::ex_mask_, ACE_Select_Reactor_Handler_Repository::max_handlep1(), qapp_, ACE_Select_Reactor_Handle_Set::rd_mask_, ACE_OS::select(), and ACE_Select_Reactor_Handle_Set::wr_mask_.

Referenced by wait_for_multiple_events().

00567 {
00568   // Check to make sure our handle's are all usable.
00569   ACE_Select_Reactor_Handle_Set temp_set = wait_set;
00570 
00571   if (ACE_OS::select (width,
00572                       temp_set.rd_mask_,
00573                       temp_set.wr_mask_,
00574                       temp_set.ex_mask_,
00575                       (ACE_Time_Value *) &ACE_Time_Value::zero ) == -1)
00576     return -1; // Bad file arguments...
00577 
00578   // Qt processing.
00579   this->qapp_->processOneEvent ();
00580 
00581   // Reset the width, in case it changed during the upcalls.
00582   width = handler_rep_.max_handlep1 ();
00583 
00584   // Now actually read the result needed by the <Select_Reactor> using
00585   // <select>.
00586   return ACE_OS::select(width,
00587                         wait_set.rd_mask_,
00588                         wait_set.wr_mask_,
00589                         wait_set.ex_mask_,
00590                         (ACE_Time_Value *) &ACE_Time_Value::zero);
00591 }

void ACE_QtReactor::read_event int  FD  )  [private, slot]
 

Dispatch a Read Event.

Definition at line 131 of file QtReactor.cpp.

References ACE_Reactor_Mask, ACE_TRACE, ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dispatch(), ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::mask_ops(), ACE_Select_Reactor_Handle_Set::rd_mask_, read_notifier_, ACE_Handle_Set::set_bit(), and set_enable_flag_by_mask().

Referenced by create_notifiers_for_handle().

00132 {
00133   ACE_TRACE ("ACE_QtReactor::read_event");
00134 
00135   ACE_HANDLE handle = ACE_HANDLE( p_handle );
00136 
00137 #ifdef ACE_QTREACTOR_CLEAR_PENDING_EVENTS
00138   // disable socket notifier to clear pending events
00139   QSocketNotifier *qsock_notifier = 0;
00140   if ( ( this->read_notifier_.find( handle,
00141              qsock_notifier) != -1) )
00142     qsock_notifier->setEnabled( false );
00143 #endif /* ACE_QTREACTOR_CLEAR_PENDING_EVENTS  */
00144 
00145   // The core of read event handling
00146   ACE_Select_Reactor_Handle_Set dispatch_set;
00147 
00148   dispatch_set.rd_mask_.set_bit ( handle );
00149   this->dispatch (1, dispatch_set);
00150 
00151 #ifdef ACE_QTREACTOR_CLEAR_PENDING_EVENTS
00152   // enable socket notifier according to current mask
00153   ACE_Reactor_Mask mask = 0;
00154   mask = mask_ops( handle, mask, ACE_Reactor::GET_MASK );
00155   if ( -1 != mask )
00156         set_enable_flag_by_mask ( 1, handle, mask);
00157 #endif /* ACE_QTREACTOR_CLEAR_PENDING_EVENTS  */
00158 }

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

Register a set of with Qt.

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 443 of file QtReactor.cpp.

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

00446 {
00447   return ACE_Select_Reactor::register_handler_i(handles,
00448                                                 handler,
00449                                                 mask);
00450 }

int ACE_QtReactor::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 419 of file QtReactor.cpp.

References ACE_Reactor_Mask, ACE_TRACE, create_notifiers_for_handle(), destroy_notifiers_for_handle(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::find_handler(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::register_handler_i().

00422 {
00423   ACE_TRACE ("ACE_QtReactor::register_handler_i");
00424 
00425   this->create_notifiers_for_handle (handle);
00426 
00427   int result;
00428   if ((result = ACE_Select_Reactor::register_handler_i(handle,
00429                                                        handler,
00430                                                        mask ))
00431       == -1)
00432     {
00433         // destroy notifiers only when there is no handler for handle
00434         if ( !ACE_Select_Reactor::find_handler( handle ) )
00435             this->destroy_notifiers_for_handle (handle);
00436       return -1;
00437     }
00438 
00439   return 0;
00440 }

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

Remove a set of .

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 466 of file QtReactor.cpp.

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

00468 {
00469   return ACE_Select_Reactor::remove_handler_i (handles,
00470                                                mask);
00471 }

int ACE_QtReactor::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 452 of file QtReactor.cpp.

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

00454 {
00455   ACE_TRACE ("ACE_QtReactor::remove_handler_i");
00456 
00457   int result = ACE_Select_Reactor::remove_handler_i (handle, mask);
00458   // destroy notifiers only when there is no handler for handle
00459   if ( !ACE_Select_Reactor::find_handler( handle ) )
00460       this->destroy_notifiers_for_handle (handle);
00461   return result;
00462 }

void ACE_QtReactor::reopen_notification_pipe void   )  [private]
 

reopens notification pipe to create SocketNotifier for it

Definition at line 46 of file QtReactor.cpp.

References ACE_Reactor_Notify::close(), ACE_Reactor_Notify::open(), ACE_Select_Reactor_Handle_Set::rd_mask_, and ACE_Handle_Set::reset().

Referenced by ACE_QtReactor().

00047 {
00048   // When the ACE_Select_Reactor is constructed it creates the notify
00049   // pipe and registers it with the register_handler_i() method. The
00050   // QtReactor overloads this method BUT because the
00051   // register_handler_i occurs when constructing the base class
00052   // ACE_Select_Reactor, the ACE_Select_Reactor register_handler_i()
00053   // is called not the QtReactor register_handler_i().  This means
00054   // that the notify pipe is registered with the ACE_Select_Reactor
00055   // event handling code not the QtReactor and so notfications don't
00056   // work.  To get around this we simply close and re-opened the
00057   // notification handler in the constructor of the QtReactor.
00058 
00059 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00060     if ( initialized_ )
00061     {
00062         this->notify_handler_->close ();
00063 
00064         // Patch for MS Windows: close and open doesn't clear the read
00065         // fd_set, so reset it manually
00066         this->wait_set_.rd_mask_.reset ();
00067 
00068         this->notify_handler_->open (this, 0);
00069     }
00070 #endif /* ACE_MT_SAFE */
00071 }

void ACE_QtReactor::reset_timeout void   )  [private]
 

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

Definition at line 477 of file QtReactor.cpp.

References ACE_NEW, ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::calculate_timeout(), ACE_Time_Value::msec(), qtime_, and timeout_event().

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

00478 {
00479   if (this->qtime_ != 0)
00480     {
00481       delete this->qtime_;
00482       this->qtime_ = 0;
00483     }
00484 
00485   ACE_Time_Value *max_wait_time =
00486     this->timer_queue_->calculate_timeout (0) ;
00487 
00488   if (max_wait_time)
00489   {
00490     ACE_NEW (this->qtime_,
00491              QTimer);
00492 
00493     QObject::connect (qtime_,
00494                       SIGNAL (timeout ()),
00495                       this,
00496                       SLOT (timeout_event ()));
00497 
00498     qtime_->start(max_wait_time->msec(), 1);
00499   }
00500 
00501 }

long ACE_QtReactor::schedule_timer ACE_Event_Handler handler,
const void *  arg,
const ACE_Time_Value delay_time,
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 505 of file QtReactor.cpp.

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

00509 {
00510   ACE_TRACE ("ACE_QtReactor::schedule_timer");
00511   ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token,
00512                             ace_mon,
00513                             this->token_,
00514                             -1));
00515 
00516   long result;
00517   if ((result = ACE_Select_Reactor::schedule_timer(handler,
00518                                                    arg,
00519                                                    delay_time,
00520                                                    interval)) == -1 )
00521     return -1;
00522   else
00523   {
00524     this->reset_timeout ();
00525     return result;
00526   }
00527 }

int ACE_QtReactor::set_enable_flag_by_mask int  flag_value,
ACE_HANDLE  handle,
ACE_Reactor_Mask  mask
[protected]
 

Definition at line 220 of file QtReactor.cpp.

References ACE_BIT_ENABLED, ACE_Reactor_Mask, exception_notifier_, ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find(), read_notifier_, and write_notifier_.

Referenced by bit_ops(), exception_event(), read_event(), and write_event().

00223 {
00224   QSocketNotifier *qs_not;
00225 
00226   if (ACE_BIT_ENABLED(mask, ACE_Event_Handler::READ_MASK) ||
00227       ACE_BIT_ENABLED( mask, ACE_Event_Handler::ACCEPT_MASK))
00228     {
00229       // Find the current notifier
00230       qs_not = 0;
00231       if ((this->read_notifier_.find (handle, qs_not) == -1))
00232         return -1;
00233 
00234       qs_not->setEnabled (flag_value);
00235     }
00236 
00237   if (ACE_BIT_ENABLED( mask, ACE_Event_Handler::WRITE_MASK) ||
00238       ACE_BIT_ENABLED( mask, ACE_Event_Handler::ACCEPT_MASK) ||
00239       ACE_BIT_ENABLED( mask, ACE_Event_Handler::CONNECT_MASK))
00240     {
00241       qs_not = 0;
00242       if ((this->write_notifier_.find (handle, qs_not) == -1))
00243         return -1;
00244 
00245       qs_not->setEnabled (flag_value);
00246     }
00247 
00248   if (ACE_BIT_ENABLED( mask,
00249                        ACE_Event_Handler::EXCEPT_MASK))
00250     {
00251       qs_not = 0;
00252       if ((this->exception_notifier_.find (handle, qs_not) == -1))
00253         return -1;
00254 
00255       qs_not->setEnabled (flag_value);
00256     }
00257 
00258   return 0;
00259 }

void ACE_QtReactor::timeout_event void   )  [private, slot]
 

Dispach a timeout event.

Definition at line 120 of file QtReactor.cpp.

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

Referenced by reset_timeout().

00121 {
00122   // Deal with any timer events
00123   ACE_Select_Reactor_Handle_Set handle_set;
00124   this->dispatch (0, handle_set );
00125 
00126   // Set next timeout signal
00127   this->reset_timeout ();
00128 }

int ACE_QtReactor::wait_for_multiple_events ACE_Select_Reactor_Handle_Set handle_set,
ACE_Time_Value max_wait_time
[protected, virtual]
 

Wait for events to occur.

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

Definition at line 595 of file QtReactor.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(), QtWaitForMultipleEvents(), ACE_Select_Reactor_Handle_Set::rd_mask_, ACE_Handle_Set::sync(), and ACE_Select_Reactor_Handle_Set::wr_mask_.

00598 {
00599   ACE_TRACE ("ACE_QtReactor::wait_for_multiple_events");
00600 
00601   int nfound = 0;
00602   do
00603   {
00604     max_wait_time = this->timer_queue_->calculate_timeout (max_wait_time);
00605     size_t width = this->handler_rep_.max_handlep1 ();
00606     handle_set.rd_mask_ = this->wait_set_.rd_mask_;
00607     handle_set.wr_mask_ = this->wait_set_.wr_mask_;
00608     handle_set.ex_mask_ = this->wait_set_.ex_mask_;
00609 
00610     nfound = QtWaitForMultipleEvents (width,
00611                                       handle_set,
00612                                       max_wait_time);
00613 
00614   } while( nfound == -1 && this->handle_error () > 0 );
00615 
00616   if (nfound > 0)
00617   {
00618 #if !defined (ACE_WIN32)
00619     handle_set.rd_mask_.sync (this->handler_rep_.max_handlep1 ());
00620     handle_set.wr_mask_.sync (this->handler_rep_.max_handlep1 ());
00621     handle_set.ex_mask_.sync (this->handler_rep_.max_handlep1 ());
00622 #endif /* ACE_WIN32 */
00623   }
00624 
00625   return nfound;
00626   // Timed out or input available
00627 }

void ACE_QtReactor::write_event int  FD  )  [private, slot]
 

Dispatch a Write Event.

Definition at line 161 of file QtReactor.cpp.

References ACE_Reactor_Mask, ACE_TRACE, ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dispatch(), ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::mask_ops(), ACE_Handle_Set::set_bit(), set_enable_flag_by_mask(), ACE_Select_Reactor_Handle_Set::wr_mask_, and write_notifier_.

Referenced by create_notifiers_for_handle().

00162 {
00163   ACE_TRACE ("ACE_QtReactor::write_event");
00164 
00165   ACE_HANDLE handle = ACE_HANDLE( p_handle );
00166 
00167 #ifdef ACE_QTREACTOR_CLEAR_PENDING_EVENTS
00168   // disable socket notifier to clear pending events
00169   QSocketNotifier *qsock_notifier = 0;
00170   if ( ( this->write_notifier_.find( handle, qsock_notifier) != -1) )
00171     qsock_notifier->setEnabled( false );
00172 #endif /* ACE_QTREACTOR_CLEAR_PENDING_EVENTS  */
00173 
00174   // The core of write event handling
00175   ACE_Select_Reactor_Handle_Set dispatch_set;
00176 
00177   dispatch_set.wr_mask_.set_bit( handle );
00178   this->dispatch (1, dispatch_set);
00179 
00180 #ifdef ACE_QTREACTOR_CLEAR_PENDING_EVENTS
00181   // enable socket notifier according to current mask
00182   ACE_Reactor_Mask mask = 0;
00183   mask = mask_ops( handle, mask, ACE_Reactor::GET_MASK );
00184   if ( -1 != mask )
00185         set_enable_flag_by_mask ( 1, handle, mask);
00186 #endif /* ACE_QTREACTOR_CLEAR_PENDING_EVENTS  */
00187 }


Member Data Documentation

MAP ACE_QtReactor::exception_notifier_ [protected]
 

An exception notifier.

Definition at line 188 of file QtReactor.h.

Referenced by create_notifiers_for_handle(), destroy_notifiers_for_handle(), exception_event(), set_enable_flag_by_mask(), and ~ACE_QtReactor().

QApplication* ACE_QtReactor::qapp_ [protected]
 

Some Qt stuff that we need to have.

Definition at line 176 of file QtReactor.h.

Referenced by qapplication(), and QtWaitForMultipleEvents().

QTimer* ACE_QtReactor::qtime_ [protected]
 

The timer class that would provide timer-sgnals & single-shot timers.

Definition at line 191 of file QtReactor.h.

Referenced by reset_timeout(), and ~ACE_QtReactor().

MAP ACE_QtReactor::read_notifier_ [protected]
 

A notifier for a read.

Definition at line 182 of file QtReactor.h.

Referenced by create_notifiers_for_handle(), destroy_notifiers_for_handle(), read_event(), set_enable_flag_by_mask(), and ~ACE_QtReactor().

MAP ACE_QtReactor::write_notifier_ [protected]
 

A write notifier.

Definition at line 185 of file QtReactor.h.

Referenced by create_notifiers_for_handle(), destroy_notifiers_for_handle(), set_enable_flag_by_mask(), write_event(), and ~ACE_QtReactor().


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