Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / DynamicInterface / DII_Reply_Dispatcher.cpp
blobc84438c6a553d31441b43b45d4e3f829ae61b17a
1 #include "tao/DynamicInterface/DII_Reply_Dispatcher.h"
2 #include "tao/DynamicInterface/Request.h"
3 #include "tao/debug.h"
4 #include "tao/ORB_Core.h"
5 #include "tao/Pluggable_Messaging_Utils.h"
6 #include "tao/SystemException.h"
8 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
10 // Constructor.
11 TAO_DII_Deferred_Reply_Dispatcher::TAO_DII_Deferred_Reply_Dispatcher (
12 CORBA::Request_ptr req,
13 TAO_ORB_Core *orb_core)
14 : TAO_Asynch_Reply_Dispatcher_Base (orb_core)
15 , req_ (CORBA::Request::_duplicate (req))
19 // Dispatch the reply.
20 int
21 TAO_DII_Deferred_Reply_Dispatcher::dispatch_reply (
22 TAO_Pluggable_Reply_Params &params)
24 if (params.input_cdr_ == 0)
25 return -1;
27 this->reply_status_ = params.reply_status ();
28 this->locate_reply_status_ = params.locate_reply_status ();
30 // Transfer the <params.input_cdr_>'s content to this->reply_cdr_
31 ACE_Data_Block *db = this->reply_cdr_.clone_from (*params.input_cdr_);
33 if (db == 0)
35 if (TAO_debug_level > 2)
37 TAOLIB_ERROR ((
38 LM_ERROR,
39 "TAO (%P|%t) - DII_Deferred_Reply_Dispatcher::dispatch_reply "
40 "clone_from failed\n"));
42 return -1;
45 // See whether we need to delete the data block by checking the
46 // flags. We cannot be happy that we initially allocated the
47 // datablocks of the stack. If this method is called twice, as is in
48 // some cases where the same invocation object is used to make two
49 // invocations like forwarding, the release becomes essential.
50 if (ACE_BIT_DISABLED (db->flags (), ACE_Message_Block::DONT_DELETE))
52 db->release ();
55 // Steal the buffer, that way we don't do any unnecessary copies of
56 // this data.
57 CORBA::ULong const max = params.svc_ctx_.maximum ();
58 CORBA::ULong const len = params.svc_ctx_.length ();
59 IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (1);
60 this->reply_service_info_.replace (max, len, context_list, 1);
62 if (TAO_debug_level >= 4)
64 TAOLIB_DEBUG ((LM_DEBUG,
65 ACE_TEXT ("TAO (%P|%t) - DII_Deferred_Reply_Dispatcher::dispatch_reply, id [%d]\n"), params.request_id_));
68 try
70 // Call the Request back and send the reply data.
71 this->req_->handle_response (this->reply_cdr_, this->reply_status_);
73 catch (const ::CORBA::Exception& ex)
75 if (TAO_debug_level >= 4)
77 ex._tao_print_exception ("DII_Deferred_Reply_Dispatcher::dispatch_reply, exception during reply handler");
81 // This was dynamically allocated. Now the job is done.
82 this->intrusive_remove_ref (this);
84 return 1;
87 void
88 TAO_DII_Deferred_Reply_Dispatcher::connection_closed ()
90 try
92 // Generate a fake exception....
93 CORBA::COMM_FAILURE comm_failure (0, CORBA::COMPLETED_MAYBE);
95 TAO_OutputCDR out_cdr;
97 comm_failure._tao_encode (out_cdr);
99 // Turn into an output CDR
100 TAO_InputCDR cdr (out_cdr);
102 this->req_->handle_response (cdr, GIOP::SYSTEM_EXCEPTION);
104 catch (const ::CORBA::Exception& ex)
106 if (TAO_debug_level >= 4)
108 ex._tao_print_exception ("DII_Deferred_Reply_Dispacher::connection_closed");
112 this->intrusive_remove_ref (this);
115 TAO_DII_Asynch_Reply_Dispatcher::TAO_DII_Asynch_Reply_Dispatcher (
116 const Messaging::ReplyHandler_ptr callback,
117 TAO_ORB_Core *orb_core)
118 : TAO_Asynch_Reply_Dispatcher_Base (orb_core),
119 db_ (sizeof buf_,
120 ACE_Message_Block::MB_DATA,
121 this->buf_,
122 orb_core->input_cdr_buffer_allocator (),
123 orb_core->locking_strategy (),
124 ACE_Message_Block::DONT_DELETE,
125 orb_core->input_cdr_dblock_allocator ()),
126 reply_cdr_ (&db_,
127 ACE_Message_Block::DONT_DELETE,
128 TAO_ENCAP_BYTE_ORDER,
129 TAO_DEF_GIOP_MAJOR,
130 TAO_DEF_GIOP_MINOR,
131 orb_core),
132 callback_ (callback)
136 TAO_DII_Asynch_Reply_Dispatcher::~TAO_DII_Asynch_Reply_Dispatcher ()
138 // this was handed to us by the caller.
139 CORBA::release(callback_);
143 TAO_DII_Asynch_Reply_Dispatcher::dispatch_reply (
144 TAO_Pluggable_Reply_Params &params)
146 this->reply_status_ = params.reply_status ();
147 this->locate_reply_status_ = params.locate_reply_status ();
149 // Transfer the <params.input_cdr_>'s content to this->reply_cdr_
150 ACE_Data_Block *db = this->reply_cdr_.clone_from (*params.input_cdr_);
152 // See whether we need to delete the data block by checking the
153 // flags. We cannot be happy that we initally allocated the
154 // datablocks of the stack. If this method is called twice, as is in
155 // some cases where the same invocation object is used to make two
156 // invocations like forwarding, the release becomes essential.
157 if (ACE_BIT_DISABLED (db->flags (), ACE_Message_Block::DONT_DELETE))
159 db->release ();
162 // Steal the buffer, that way we don't do any unnecessary copies of
163 // this data.
164 CORBA::ULong const max = params.svc_ctx_.maximum ();
165 CORBA::ULong const len = params.svc_ctx_.length ();
166 IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (1);
167 this->reply_service_info_.replace (max, len, context_list, 1);
169 if (TAO_debug_level >= 4)
171 TAOLIB_DEBUG ((LM_DEBUG,
172 ACE_TEXT ("TAO (%P|%t) - TAO_DII_Asynch_Reply_Dispatcher::dispatch_reply: status = %d\n"),
173 this->reply_status_));
178 // Call the handler with the reply data.
179 CORBA::Request::_tao_reply_stub (this->reply_cdr_,
180 this->callback_,
181 this->reply_status_);
183 catch (const CORBA::Exception& ex)
185 if (TAO_debug_level >= 4)
187 ex._tao_print_exception ("TAO_DII_Asynch_Reply_Dispatcher::dispatch_reply, exception during reply handler");
190 // This was dynamically allocated. Now the job is done.
191 this->intrusive_remove_ref (this);
193 return 1;
196 void
197 TAO_DII_Asynch_Reply_Dispatcher::connection_closed ()
201 // Generate a fake exception....
202 CORBA::COMM_FAILURE comm_failure (0, CORBA::COMPLETED_MAYBE);
204 TAO_OutputCDR out_cdr;
206 comm_failure._tao_encode (out_cdr);
208 // Turn into an output CDR
209 TAO_InputCDR cdr (out_cdr);
210 CORBA::Request::_tao_reply_stub (
211 this->reply_cdr_,
212 this->callback_,
213 GIOP::SYSTEM_EXCEPTION);
215 catch (const CORBA::Exception& ex)
217 if (TAO_debug_level >= 4)
219 ex._tao_print_exception ("DII_Asynch_Reply_Dispacher::connection_closed");
223 this->intrusive_remove_ref (this);
225 TAO_END_VERSIONED_NAMESPACE_DECL