//$Id$ #include "ace/QtReactor.h" #if defined (ACE_HAS_QT) ACE_ALLOC_HOOK_DEFINE (ACE_QtReactor) // Must be called with lock held ACE_QtReactor::ACE_QtReactor (QApplication *qapp, size_t size, int restart, ACE_Sig_Handler *handler) : ACE_Select_Reactor(size, restart, handler), qapp_(qapp), qtime_ (0) { // When the ACE_Select_Reactor is constructed it creates the notify // pipe and registers it with the register_handler_i() method. The // QtReactor overloads this method BUT because the // register_handler_i occurs when constructing the base class // ACE_Select_Reactor, the ACE_Select_Reactor register_handler_i() // is called not the QtReactor register_handler_i(). This means // that the notify pipe is registered with the ACE_Select_Reactor // event handling code not the QtReactor and so notfications don't // work. To get around this we simply close and re-opened the // notification handler in the constructor of the QtReactor. #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) this->notify_handler_->close (); this->notify_handler_->open (this, 0); #endif /* ACE_MT_SAFE */ } ACE_QtReactor::~ACE_QtReactor (void) { //no-op } void ACE_QtReactor::qapplication (QApplication *qapp) { qapp_ = qapp ; } int ACE_QtReactor::wait_for_multiple_events (ACE_Select_Reactor_Handle_Set &handle_set, ACE_Time_Value *max_wait_time) { ACE_TRACE( "ACE_QtReactor::wait_for_multiple_events" ); int nfound = 0; do { max_wait_time = this->timer_queue_->calculate_timeout (max_wait_time); size_t width = this->handler_rep_.max_handlep1 (); handle_set.rd_mask_ = this->wait_set_.rd_mask_; handle_set.wr_mask_ = this->wait_set_.wr_mask_; handle_set.ex_mask_ = this->wait_set_.ex_mask_; nfound = QtWaitForMultipleEvents (width, handle_set, max_wait_time); } while( nfound == -1 && this->handle_error () > 0 ); if (nfound > 0) { #if !defined (ACE_WIN32) handle_set.rd_mask_.sync (this->handler_rep_.max_handlep1 ()); handle_set.wr_mask_.sync (this->handler_rep_.max_handlep1 ()); handle_set.ex_mask_.sync (this->handler_rep_.max_handlep1 ()); #endif /* ACE_WIN32 */ } return nfound; // Timed out or input available } void ACE_QtReactor::timeout_event (void) { // Deal with any timer events ACE_Select_Reactor_Handle_Set handle_set; this->dispatch (0, handle_set ); // Set next timeout signal this->reset_timeout (); } void ACE_QtReactor::read_event (int handle) { // Send read event ACE_Select_Reactor_Handle_Set dispatch_set; dispatch_set.rd_mask_.set_bit (handle); this->dispatch (1, dispatch_set); } void ACE_QtReactor::write_event (int handle) { // Send write event ACE_Select_Reactor_Handle_Set dispatch_set; dispatch_set.wr_mask_.set_bit (handle); this->dispatch (1, dispatch_set); } void ACE_QtReactor::exception_event (int handle) { // Send exception event ACE_Select_Reactor_Handle_Set dispatch_set; dispatch_set.ex_mask_.set_bit(handle); dispatch (1, dispatch_set); } int ACE_QtReactor::QtWaitForMultipleEvents (int width, ACE_Select_Reactor_Handle_Set &wait_set, ACE_Time_Value */*max_wait_time*/) { // Check to make sure our handle's are all usable. ACE_Select_Reactor_Handle_Set temp_set = wait_set; if (ACE_OS::select (width, temp_set.rd_mask_, temp_set.wr_mask_, temp_set.ex_mask_, (ACE_Time_Value *) &ACE_Time_Value::zero ) == -1) return -1; // Bad file arguments... // Qt processing. this->qapp_->processOneEvent () ; // Reset the width, in case it changed during the upcalls. width = handler_rep_.max_handlep1 (); // Now actually read the result needed by the using //