ScheduleOutputHandler.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00009 #include "ScheduleOutputHandler.h"
00010 
00011 #include "TransportSendStrategy.h"
00012 
00013 #if !defined (__ACE_INLINE__)
00014 #include "ScheduleOutputHandler.inl"
00015 #endif /* __ACE_INLINE__ */
00016 
00017 void
00018 OpenDDS::DCPS::ScheduleOutputHandler::schedule_output()
00019 {
00020   DBG_ENTRY_LVL("ScheduleOutputHandler","schedule_output",6);
00021 
00022   // Only emit once into the notification queue since we check which
00023   // operation to perform when we process.
00024   if( reference_count_ == 1) {
00025     /// Filter the notifications here to reduce load.
00026     TransportSendStrategy::SendMode mode = strategy_->mode();
00027 
00028     if( ( (state_ ==  Enabled) && (mode == TransportSendStrategy::MODE_DIRECT))
00029      || ( (state_ == Disabled) && ( (mode == TransportSendStrategy::MODE_QUEUE)
00030                                  || (mode == TransportSendStrategy::MODE_SUSPEND)))) {
00031       reactor()->notify(this);
00032     }
00033   }
00034 }
00035 
00036 int
00037 OpenDDS::DCPS::ScheduleOutputHandler::handle_exception(ACE_HANDLE)
00038 {
00039   DBG_ENTRY_LVL("ScheduleOutputHandler","handle_exception",6);
00040 
00041   if( reference_count_ == 1) {
00042     // The containing TransportSendStrategy has unregistered, so we are
00043     // going away and can't determine the mode, don't process.
00044     return -1;
00045   }
00046 
00047   // Check the *current* mode value as it might have been changed since
00048   // we were scheduled to run.
00049   //
00050   // We already hold the Reactor::token_ (since we are being called from
00051   // the reactor), and it will see the recursion and allow the call back
00052   // into the reactor.  We hold no other locks, and so avoid deadlock.
00053   TransportSendStrategy::SendMode mode = strategy_->mode();
00054   bool changed = false;
00055 
00056   ACE_HANDLE handle = strategy_->get_handle();
00057   // We need to recheck the mode here since it might have already changed.
00058   if( mode == TransportSendStrategy::MODE_DIRECT) {
00059     // Don't cancel a canceled handle.
00060     if( state_ == Enabled) {
00061       reactor()->cancel_wakeup(handle, ACE_Event_Handler::WRITE_MASK);
00062       state_ = Disabled;
00063       changed = true;
00064     }
00065 
00066   } else if( (mode == TransportSendStrategy::MODE_QUEUE)
00067           || (mode == TransportSendStrategy::MODE_SUSPEND)) {
00068 
00069     // Don't schedule a scheduled handle.
00070     if( state_ == Disabled) {
00071       reactor()->schedule_wakeup(handle, ACE_Event_Handler::WRITE_MASK);
00072       state_ = Enabled;
00073       changed = true;
00074     }
00075   }
00076 
00077   if (DCPS_debug_level > 4) {
00078     ACE_DEBUG((LM_DEBUG,
00079                ACE_TEXT("(%P|%t) ScheduleOutputHandler::handle_exception() - [%d] ")
00080                ACE_TEXT("%C data queueing for handle %d.\n"),
00081                strategy_->id(),
00082                (changed? ((state_ == Enabled)? "starting": "canceling"): "declining to change"),
00083                handle));
00084   }
00085 
00086   // Terminate the upcall and remove from the reactor, if there (and
00087   // decrement_reference()).
00088   return -1;
00089 }
00090 

Generated on Fri Feb 12 20:05:26 2016 for OpenDDS by  doxygen 1.4.7