DII_Reply_Dispatcher.cpp

Go to the documentation of this file.
00001 // $Id: DII_Reply_Dispatcher.cpp 79705 2007-09-24 07:45:37Z johnnyw $
00002 
00003 #include "tao/DynamicInterface/DII_Reply_Dispatcher.h"
00004 #include "tao/DynamicInterface/Request.h"
00005 #include "tao/debug.h"
00006 #include "tao/ORB_Core.h"
00007 #include "tao/Pluggable_Messaging_Utils.h"
00008 #include "tao/SystemException.h"
00009 
00010 ACE_RCSID(DynamicInterface,
00011           DII_Reply_Dispatcher,
00012           "$Id: DII_Reply_Dispatcher.cpp 79705 2007-09-24 07:45:37Z johnnyw $")
00013 
00014 
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016 
00017 // Constructor.
00018 TAO_DII_Deferred_Reply_Dispatcher::TAO_DII_Deferred_Reply_Dispatcher (
00019     const CORBA::Request_ptr req,
00020     TAO_ORB_Core *orb_core)
00021   : TAO_Asynch_Reply_Dispatcher_Base (orb_core)
00022   , req_ (req)
00023 {
00024 }
00025 
00026 // Destructor.
00027 TAO_DII_Deferred_Reply_Dispatcher::~TAO_DII_Deferred_Reply_Dispatcher (void)
00028 {
00029 }
00030 
00031 // Dispatch the reply.
00032 int
00033 TAO_DII_Deferred_Reply_Dispatcher::dispatch_reply (
00034     TAO_Pluggable_Reply_Params &params)
00035 {
00036   if (params.input_cdr_ == 0)
00037     return -1;
00038 
00039   this->reply_status_ = params.reply_status ();
00040   this->locate_reply_status_ = params.locate_reply_status ();
00041 
00042   // Transfer the <params.input_cdr_>'s content to this->reply_cdr_
00043   ACE_Data_Block *db = this->reply_cdr_.clone_from (*params.input_cdr_);
00044 
00045   if (db == 0)
00046     {
00047       if (TAO_debug_level > 2)
00048         {
00049           ACE_ERROR ((
00050             LM_ERROR,
00051             "TAO (%P|%t) - DII_Deferred_Reply_Dispatcher::dispatch_reply "
00052             "clone_from failed \n"));
00053         }
00054       return -1;
00055     }
00056 
00057   // See whether we need to delete the data block by checking the
00058   // flags. We cannot be happy that we initally allocated the
00059   // datablocks of the stack. If this method is called twice, as is in
00060   // some cases where the same invocation object is used to make two
00061   // invocations like forwarding, the release becomes essential.
00062   if (ACE_BIT_DISABLED (db->flags (),
00063                         ACE_Message_Block::DONT_DELETE))
00064     db->release ();
00065 
00066   // Steal the buffer, that way we don't do any unnecesary copies of
00067   // this data.
00068   CORBA::ULong max = params.svc_ctx_.maximum ();
00069   CORBA::ULong len = params.svc_ctx_.length ();
00070   IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (1);
00071   this->reply_service_info_.replace (max, len, context_list, 1);
00072 
00073   if (TAO_debug_level >= 4)
00074     {
00075       ACE_DEBUG ((LM_DEBUG,
00076                   ACE_TEXT ("(%P | %t):TAO_Asynch_Reply_Dispatcher::dispatch_reply:\n")));
00077     }
00078 
00079   try
00080     {
00081       // Call the Request back and send the reply data.
00082       this->req_->handle_response (this->reply_cdr_, this->reply_status_);
00083     }
00084   catch (const ::CORBA::Exception& ex)
00085     {
00086       if (TAO_debug_level >= 4)
00087         {
00088           ex._tao_print_exception ("Exception during reply handler");
00089         }
00090     }
00091 
00092   // This was dynamically allocated. Now the job is done.
00093   (void) this->decr_refcount ();
00094 
00095   return 1;
00096 }
00097 
00098 void
00099 TAO_DII_Deferred_Reply_Dispatcher::connection_closed (void)
00100 {
00101 
00102   try
00103     {
00104       // Generate a fake exception....
00105       CORBA::COMM_FAILURE comm_failure (0, CORBA::COMPLETED_MAYBE);
00106 
00107       TAO_OutputCDR out_cdr;
00108 
00109       comm_failure._tao_encode (out_cdr);
00110 
00111       // Turn into an output CDR
00112       TAO_InputCDR cdr (out_cdr);
00113 
00114       this->req_->handle_response (cdr, GIOP::SYSTEM_EXCEPTION);
00115     }
00116   catch (const ::CORBA::Exception& ex)
00117     {
00118       if (TAO_debug_level >= 4)
00119         {
00120           ex._tao_print_exception (
00121             "DII_Deferred_Reply_Dispacher::connection_closed");
00122         }
00123     }
00124 
00125   (void) this->decr_refcount ();
00126 }
00127 
00128 TAO_DII_Asynch_Reply_Dispatcher::TAO_DII_Asynch_Reply_Dispatcher (
00129     const Messaging::ReplyHandler_ptr callback,
00130     TAO_ORB_Core *orb_core)
00131   : TAO_Asynch_Reply_Dispatcher_Base (orb_core),
00132     db_ (sizeof buf_,
00133          ACE_Message_Block::MB_DATA,
00134          this->buf_,
00135          orb_core->input_cdr_buffer_allocator (),
00136          orb_core->locking_strategy (),
00137          ACE_Message_Block::DONT_DELETE,
00138          orb_core->input_cdr_dblock_allocator ()),
00139     reply_cdr_ (&db_,
00140                 ACE_Message_Block::DONT_DELETE,
00141                 TAO_ENCAP_BYTE_ORDER,
00142                 TAO_DEF_GIOP_MAJOR,
00143                 TAO_DEF_GIOP_MINOR,
00144                 orb_core),
00145     callback_ (callback)
00146 {
00147 }
00148 
00149 TAO_DII_Asynch_Reply_Dispatcher::~TAO_DII_Asynch_Reply_Dispatcher (void)
00150 {
00151   // this was handed to us by the caller.
00152   CORBA::release(callback_);
00153 }
00154 
00155 int
00156 TAO_DII_Asynch_Reply_Dispatcher::dispatch_reply (
00157     TAO_Pluggable_Reply_Params &params)
00158 {
00159   this->reply_status_ = params.reply_status ();
00160   this->locate_reply_status_ = params.locate_reply_status ();
00161 
00162   // Transfer the <params.input_cdr_>'s content to this->reply_cdr_
00163   ACE_Data_Block *db =
00164     this->reply_cdr_.clone_from (*params.input_cdr_);
00165 
00166   // See whether we need to delete the data block by checking the
00167   // flags. We cannot be happy that we initally allocated the
00168   // datablocks of the stack. If this method is called twice, as is in
00169   // some cases where the same invocation object is used to make two
00170   // invocations like forwarding, the release becomes essential.
00171   if (ACE_BIT_DISABLED (db->flags (),
00172                         ACE_Message_Block::DONT_DELETE))
00173     db->release ();
00174 
00175   // Steal the buffer, that way we don't do any unnecesary copies of
00176   // this data.
00177   CORBA::ULong max = params.svc_ctx_.maximum ();
00178   CORBA::ULong len = params.svc_ctx_.length ();
00179   IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (1);
00180   this->reply_service_info_.replace (max, len, context_list, 1);
00181 
00182   if (TAO_debug_level >= 4)
00183     {
00184       ACE_DEBUG ((LM_DEBUG,
00185                   ACE_TEXT ("(%P | %t):")
00186                   ACE_TEXT ("TAO_DII_Asynch_Reply_Dispatcher::dispatch_reply: status = %d\n"),
00187                   this->reply_status_));
00188     }
00189 
00190   try
00191     {
00192       // Call the handler with the reply data.
00193       CORBA::Request::_tao_reply_stub (this->reply_cdr_,
00194                                        this->callback_,
00195                                        this->reply_status_);
00196     }
00197   catch (const CORBA::Exception& ex)
00198     {
00199       if (TAO_debug_level >= 4)
00200         {
00201           ex._tao_print_exception ("Exception during reply handler");
00202         }
00203     }
00204   // This was dynamically allocated. Now the job is done.
00205   (void) this->decr_refcount ();
00206 
00207   return 1;
00208 }
00209 
00210 void
00211 TAO_DII_Asynch_Reply_Dispatcher::connection_closed (void)
00212 {
00213   try
00214     {
00215       // Generate a fake exception....
00216       CORBA::COMM_FAILURE comm_failure (0,
00217                                         CORBA::COMPLETED_MAYBE);
00218 
00219       TAO_OutputCDR out_cdr;
00220 
00221       comm_failure._tao_encode (out_cdr);
00222 
00223       // Turn into an output CDR
00224       TAO_InputCDR cdr (out_cdr);
00225       CORBA::Request::_tao_reply_stub (
00226           this->reply_cdr_,
00227           this->callback_,
00228           GIOP::SYSTEM_EXCEPTION);
00229     }
00230   catch (const CORBA::Exception& ex)
00231     {
00232       if (TAO_debug_level >= 4)
00233         {
00234           ex._tao_print_exception (
00235             "DII_Asynch_Reply_Dispacher::connection_closed");
00236         }
00237     }
00238 
00239   (void) this->decr_refcount ();
00240 }
00241 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:43:23 2010 for TAO_DynamicInterface by  doxygen 1.4.7