DII_Reply_Dispatcher.cpp

Go to the documentation of this file.
00001 // DII_Reply_Dispatcher.cpp,v 1.24 2006/03/10 07:19:08 jtc Exp
00002 
00003 #include "tao/DynamicInterface/DII_Reply_Dispatcher.h"
00004 #include "tao/DynamicInterface/Request.h"
00005 #include "tao/Environment.h"
00006 #include "tao/debug.h"
00007 #include "tao/ORB_Core.h"
00008 #include "tao/Pluggable_Messaging_Utils.h"
00009 
00010 
00011 ACE_RCSID(DynamicInterface,
00012           DII_Reply_Dispatcher,
00013           "DII_Reply_Dispatcher.cpp,v 1.24 2006/03/10 07:19:08 jtc Exp")
00014 
00015 
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 // Constructor.
00019 TAO_DII_Deferred_Reply_Dispatcher::TAO_DII_Deferred_Reply_Dispatcher (
00020     const CORBA::Request_ptr req,
00021     TAO_ORB_Core *orb_core)
00022   : TAO_Asynch_Reply_Dispatcher_Base (orb_core)
00023   , req_ (req)
00024 {
00025 }
00026 
00027 // Destructor.
00028 TAO_DII_Deferred_Reply_Dispatcher::~TAO_DII_Deferred_Reply_Dispatcher (void)
00029 {
00030 }
00031 
00032 // Dispatch the reply.
00033 int
00034 TAO_DII_Deferred_Reply_Dispatcher::dispatch_reply (
00035     TAO_Pluggable_Reply_Params &params
00036   )
00037 {
00038   if (params.input_cdr_ == 0)
00039     return -1;
00040 
00041   this->reply_status_ = params.reply_status_;
00042 
00043   // Transfer the <params.input_cdr_>'s content to this->reply_cdr_
00044   ACE_Data_Block *db =
00045     this->reply_cdr_.clone_from (*params.input_cdr_);
00046 
00047 
00048   if (db == 0)
00049     {
00050       if (TAO_debug_level > 2)
00051         {
00052           ACE_ERROR ((
00053             LM_ERROR,
00054             "TAO (%P|%t) - DII_Deferred_Reply_Dispatcher::dispatch_reply "
00055             "clone_from failed \n"));
00056         }
00057       return -1;
00058     }
00059 
00060   // See whether we need to delete the data block by checking the
00061   // flags. We cannot be happy that we initally allocated the
00062   // datablocks of the stack. If this method is called twice, as is in
00063   // some cases where the same invocation object is used to make two
00064   // invocations like forwarding, the release becomes essential.
00065   if (ACE_BIT_DISABLED (db->flags (),
00066                         ACE_Message_Block::DONT_DELETE))
00067     db->release ();
00068 
00069   // Steal the buffer, that way we don't do any unnecesary copies of
00070   // this data.
00071   CORBA::ULong max = params.svc_ctx_.maximum ();
00072   CORBA::ULong len = params.svc_ctx_.length ();
00073   IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (1);
00074   this->reply_service_info_.replace (max, len, context_list, 1);
00075 
00076   if (TAO_debug_level >= 4)
00077     {
00078       ACE_DEBUG ((LM_DEBUG,
00079                   ACE_TEXT ("(%P | %t):TAO_Asynch_Reply_Dispatcher::dispatch_reply:\n")));
00080     }
00081 
00082   ACE_TRY_NEW_ENV
00083     {
00084       // Call the Request back and send the reply data.
00085       this->req_->handle_response (this->reply_cdr_,
00086                                    this->reply_status_
00087                                    ACE_ENV_ARG_PARAMETER);
00088       ACE_TRY_CHECK;
00089     }
00090   ACE_CATCHANY
00091     {
00092       if (TAO_debug_level >= 4)
00093         {
00094           ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00095                                "Exception during reply handler");
00096         }
00097     }
00098   ACE_ENDTRY;
00099 
00100   // This was dynamically allocated. Now the job is done.
00101   (void) this->decr_refcount ();
00102 
00103   return 1;
00104 }
00105 
00106 void
00107 TAO_DII_Deferred_Reply_Dispatcher::connection_closed (void)
00108 {
00109   ACE_DECLARE_NEW_CORBA_ENV;
00110 
00111   ACE_TRY
00112     {
00113       // Generate a fake exception....
00114       CORBA::COMM_FAILURE comm_failure (0,
00115                                         CORBA::COMPLETED_MAYBE);
00116 
00117       TAO_OutputCDR out_cdr;
00118 
00119       comm_failure._tao_encode (out_cdr
00120                                 ACE_ENV_ARG_PARAMETER);
00121       ACE_TRY_CHECK;
00122 
00123       // Turn into an output CDR
00124       TAO_InputCDR cdr (out_cdr);
00125 
00126       this->req_->handle_response (cdr,
00127                                    TAO_PLUGGABLE_MESSAGE_SYSTEM_EXCEPTION
00128                                    ACE_ENV_ARG_PARAMETER);
00129       ACE_TRY_CHECK;
00130     }
00131   ACE_CATCHANY
00132     {
00133       if (TAO_debug_level >= 4)
00134         {
00135           ACE_PRINT_EXCEPTION (
00136               ACE_ANY_EXCEPTION,
00137               "DII_Deferred_Reply_Dispacher::connection_closed"
00138             );
00139         }
00140     }
00141   ACE_ENDTRY;
00142   ACE_CHECK;
00143 
00144   (void) this->decr_refcount ();
00145 }
00146 
00147 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:04:21 2006 for TAO_DynamicInterface by doxygen 1.3.6