Synch_Reply_Dispatcher.cpp

Go to the documentation of this file.
00001 // Synch_Reply_Dispatcher.cpp,v 1.27 2006/04/19 09:07:33 jwillemsen Exp
00002 
00003 #include "tao/Synch_Reply_Dispatcher.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/Pluggable_Messaging_Utils.h"
00006 #include "tao/debug.h"
00007 
00008 
00009 ACE_RCSID (tao,
00010            Synch_Reply_Dispatcher,
00011            "Synch_Reply_Dispatcher.cpp,v 1.27 2006/04/19 09:07:33 jwillemsen Exp")
00012 
00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00014 
00015 // Constructor.
00016 TAO_Synch_Reply_Dispatcher::TAO_Synch_Reply_Dispatcher (
00017     TAO_ORB_Core *orb_core,
00018     IOP::ServiceContextList &sc
00019   )
00020   : reply_service_info_ (sc),
00021     orb_core_ (orb_core),
00022     db_ (sizeof buf_,
00023          ACE_Message_Block::MB_DATA,
00024          this->buf_,
00025          this->orb_core_->input_cdr_buffer_allocator (),
00026          this->orb_core_->locking_strategy (),
00027          ACE_Message_Block::DONT_DELETE,
00028          this->orb_core_->input_cdr_dblock_allocator ()),
00029     reply_cdr_ (&db_,
00030                 ACE_Message_Block::DONT_DELETE,
00031                 TAO_ENCAP_BYTE_ORDER,
00032                 TAO_DEF_GIOP_MAJOR,
00033                 TAO_DEF_GIOP_MINOR,
00034                 orb_core)
00035 {
00036   // As a TAO_LF_Event we start in the active state....
00037   this->state_changed_i (TAO_LF_Event::LFS_ACTIVE);
00038 }
00039 
00040 // Destructor.
00041 TAO_Synch_Reply_Dispatcher::~TAO_Synch_Reply_Dispatcher (void)
00042 {
00043 }
00044 
00045 TAO_InputCDR &
00046 TAO_Synch_Reply_Dispatcher::reply_cdr (void)
00047 {
00048   return this->reply_cdr_;
00049 }
00050 
00051 int
00052 TAO_Synch_Reply_Dispatcher::dispatch_reply (
00053     TAO_Pluggable_Reply_Params &params)
00054 {
00055   if (params.input_cdr_ == 0)
00056     return -1;
00057 
00058   this->reply_status_ = params.reply_status_;
00059 
00060   // Steal the buffer, that way we don't do any unnecesary copies of
00061   // this data.
00062   CORBA::ULong const max = params.svc_ctx_.maximum ();
00063   CORBA::ULong const len = params.svc_ctx_.length ();
00064   IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (1);
00065   this->reply_service_info_.replace (max, len, context_list, 1);
00066 
00067   // Must reset the message state, it is possible that the same reply
00068   // dispatcher is used because the request must be re-sent.
00069   //this->message_state_.reset (0);
00070 
00071   // Transfer the <params.input_cdr_>'s content to this->reply_cdr_
00072   if (ACE_BIT_DISABLED ((*params.input_cdr_).start()->data_block()->flags(),
00073                         ACE_Message_Block::DONT_DELETE))
00074   {
00075     // Data block is on the heap, so just duplicate it.
00076     this->reply_cdr_ = *params.input_cdr_;
00077     this->reply_cdr_.clr_mb_flags( ACE_Message_Block::DONT_DELETE );
00078   }
00079   else
00080   {
00081     ACE_Data_Block *db =
00082       this->reply_cdr_.clone_from (*params.input_cdr_);
00083 
00084     if (db == 0)
00085       {
00086         if (TAO_debug_level > 2)
00087           {
00088             ACE_ERROR ((LM_ERROR,
00089                         "TAO (%P|%t) - Synch_Reply_Dispatcher::dispatch_reply "
00090                         "clone_from failed \n"));
00091           }
00092         return -1;
00093       }
00094 
00095     // See whether we need to delete the data block by checking the
00096     // flags. We cannot be happy that we initally allocated the
00097     // datablocks of the stack. If this method is called twice, as is in
00098     // some cases where the same invocation object is used to make two
00099     // invocations like forwarding, the release becomes essential.
00100     if (ACE_BIT_DISABLED (db->flags (),
00101                           ACE_Message_Block::DONT_DELETE))
00102       {
00103         db->release ();
00104       }
00105   }
00106 
00107   this->state_changed (TAO_LF_Event::LFS_SUCCESS,
00108                        this->orb_core_->leader_follower ());
00109 
00110   return 1;
00111 }
00112 
00113 void
00114 TAO_Synch_Reply_Dispatcher::connection_closed (void)
00115 {
00116   this->state_changed (TAO_LF_Event::LFS_CONNECTION_CLOSED,
00117                        this->orb_core_->leader_follower ());
00118 }
00119 
00120 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:22 2006 for TAO by doxygen 1.3.6