00001
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 78000 2007-04-12 13:53:51Z johnnyw $")
00013
00014
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016
00017
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
00027 TAO_DII_Deferred_Reply_Dispatcher::~TAO_DII_Deferred_Reply_Dispatcher (void)
00028 {
00029 }
00030
00031
00032 int
00033 TAO_DII_Deferred_Reply_Dispatcher::dispatch_reply (
00034 TAO_Pluggable_Reply_Params ¶ms)
00035 {
00036 if (params.input_cdr_ == 0)
00037 return -1;
00038
00039 this->reply_status_ = params.reply_status_;
00040
00041
00042 ACE_Data_Block *db = this->reply_cdr_.clone_from (*params.input_cdr_);
00043
00044 if (db == 0)
00045 {
00046 if (TAO_debug_level > 2)
00047 {
00048 ACE_ERROR ((
00049 LM_ERROR,
00050 "TAO (%P|%t) - DII_Deferred_Reply_Dispatcher::dispatch_reply "
00051 "clone_from failed \n"));
00052 }
00053 return -1;
00054 }
00055
00056
00057
00058
00059
00060
00061 if (ACE_BIT_DISABLED (db->flags (),
00062 ACE_Message_Block::DONT_DELETE))
00063 db->release ();
00064
00065
00066
00067 CORBA::ULong max = params.svc_ctx_.maximum ();
00068 CORBA::ULong len = params.svc_ctx_.length ();
00069 IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (1);
00070 this->reply_service_info_.replace (max, len, context_list, 1);
00071
00072 if (TAO_debug_level >= 4)
00073 {
00074 ACE_DEBUG ((LM_DEBUG,
00075 ACE_TEXT ("(%P | %t):TAO_Asynch_Reply_Dispatcher::dispatch_reply:\n")));
00076 }
00077
00078 try
00079 {
00080
00081 this->req_->handle_response (this->reply_cdr_, this->reply_status_);
00082 }
00083 catch (const ::CORBA::Exception& ex)
00084 {
00085 if (TAO_debug_level >= 4)
00086 {
00087 ex._tao_print_exception ("Exception during reply handler");
00088 }
00089 }
00090
00091
00092 (void) this->decr_refcount ();
00093
00094 return 1;
00095 }
00096
00097 void
00098 TAO_DII_Deferred_Reply_Dispatcher::connection_closed (void)
00099 {
00100
00101 try
00102 {
00103
00104 CORBA::COMM_FAILURE comm_failure (0, CORBA::COMPLETED_MAYBE);
00105
00106 TAO_OutputCDR out_cdr;
00107
00108 comm_failure._tao_encode (out_cdr);
00109
00110
00111 TAO_InputCDR cdr (out_cdr);
00112
00113 this->req_->handle_response (cdr, TAO_PLUGGABLE_MESSAGE_SYSTEM_EXCEPTION);
00114 }
00115 catch (const ::CORBA::Exception& ex)
00116 {
00117 if (TAO_debug_level >= 4)
00118 {
00119 ex._tao_print_exception (
00120 "DII_Deferred_Reply_Dispacher::connection_closed");
00121 }
00122 }
00123
00124 (void) this->decr_refcount ();
00125 }
00126
00127 TAO_DII_Asynch_Reply_Dispatcher::TAO_DII_Asynch_Reply_Dispatcher (
00128 const Messaging::ReplyHandler_ptr callback,
00129 TAO_ORB_Core *orb_core)
00130 : TAO_Asynch_Reply_Dispatcher_Base (orb_core),
00131 db_ (sizeof buf_,
00132 ACE_Message_Block::MB_DATA,
00133 this->buf_,
00134 orb_core->input_cdr_buffer_allocator (),
00135 orb_core->locking_strategy (),
00136 ACE_Message_Block::DONT_DELETE,
00137 orb_core->input_cdr_dblock_allocator ()),
00138 reply_cdr_ (&db_,
00139 ACE_Message_Block::DONT_DELETE,
00140 TAO_ENCAP_BYTE_ORDER,
00141 TAO_DEF_GIOP_MAJOR,
00142 TAO_DEF_GIOP_MINOR,
00143 orb_core),
00144 callback_ (callback)
00145 {
00146 }
00147
00148 TAO_DII_Asynch_Reply_Dispatcher::~TAO_DII_Asynch_Reply_Dispatcher (void)
00149 {
00150
00151 CORBA::release(callback_);
00152 }
00153
00154 int
00155 TAO_DII_Asynch_Reply_Dispatcher::dispatch_reply (
00156 TAO_Pluggable_Reply_Params ¶ms)
00157 {
00158 this->reply_status_ = params.reply_status_;
00159
00160
00161 ACE_Data_Block *db =
00162 this->reply_cdr_.clone_from (*params.input_cdr_);
00163
00164
00165
00166
00167
00168
00169 if (ACE_BIT_DISABLED (db->flags (),
00170 ACE_Message_Block::DONT_DELETE))
00171 db->release ();
00172
00173
00174
00175 CORBA::ULong max = params.svc_ctx_.maximum ();
00176 CORBA::ULong len = params.svc_ctx_.length ();
00177 IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (1);
00178 this->reply_service_info_.replace (max, len, context_list, 1);
00179
00180 if (TAO_debug_level >= 4)
00181 {
00182 ACE_DEBUG ((LM_DEBUG,
00183 ACE_TEXT ("(%P | %t):")
00184 ACE_TEXT ("TAO_DII_Asynch_Reply_Dispatcher::dispatch_reply: status = %d\n"),
00185 this->reply_status_));
00186 }
00187
00188 try
00189 {
00190
00191 CORBA::Request::_tao_reply_stub (this->reply_cdr_,
00192 this->callback_,
00193 this->reply_status_);
00194 }
00195 catch (const CORBA::Exception& ex)
00196 {
00197 if (TAO_debug_level >= 4)
00198 {
00199 ex._tao_print_exception ("Exception during reply handler");
00200 }
00201 }
00202
00203 (void) this->decr_refcount ();
00204
00205 return 1;
00206 }
00207
00208 void
00209 TAO_DII_Asynch_Reply_Dispatcher::connection_closed (void)
00210 {
00211 try
00212 {
00213
00214 CORBA::COMM_FAILURE comm_failure (0,
00215 CORBA::COMPLETED_MAYBE);
00216
00217 TAO_OutputCDR out_cdr;
00218
00219 comm_failure._tao_encode (out_cdr);
00220
00221
00222 TAO_InputCDR cdr (out_cdr);
00223 CORBA::Request::_tao_reply_stub (
00224 this->reply_cdr_,
00225 this->callback_,
00226 TAO_PLUGGABLE_MESSAGE_SYSTEM_EXCEPTION);
00227 }
00228 catch (const CORBA::Exception& ex)
00229 {
00230 if (TAO_debug_level >= 4)
00231 {
00232 ex._tao_print_exception (
00233 "DII_Asynch_Reply_Dispacher::connection_closed");
00234 }
00235 }
00236
00237 (void) this->decr_refcount ();
00238 }
00239 TAO_END_VERSIONED_NAMESPACE_DECL