00001
00002 #include "tao/CSD_Framework/CSD_FW_Server_Request_Wrapper.h"
00003 #include "tao/debug.h"
00004 #include "tao/ORB_Constants.h"
00005 #include "tao/ORB_Core.h"
00006 #include "tao/Transport.h"
00007 #include "tao/CDR.h"
00008
00009
00010 ACE_RCSID (CSD_Framework,
00011 FW_Server_Request_Wrapper,
00012 "$Id: CSD_FW_Server_Request_Wrapper.cpp 81140 2008-03-28 09:19:19Z vzykov $")
00013
00014 #if !defined (__ACE_INLINE__)
00015 # include "tao/CSD_Framework/CSD_FW_Server_Request_Wrapper.inl"
00016 #endif
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 TAO::CSD::FW_Server_Request_Wrapper::~FW_Server_Request_Wrapper()
00021 {
00022
00023 if (this->is_clone_)
00024 {
00025
00026 if (this->request_->profile_.type_id_ != 0)
00027 CORBA::string_free (
00028 const_cast<char*> (this->request_->profile_.type_id_));
00029
00030
00031
00032
00033
00034
00035 delete this->request_->incoming_;
00036
00037
00038
00039 if (this->request_->outgoing_ != 0)
00040 {
00041 char* buffer = this->request_->outgoing_->begin ()->base ();
00042 delete [] buffer;
00043 delete this->request_->outgoing_;
00044 }
00045 if (this->request_->operation_details_ != 0)
00046 {
00047 char* opname =
00048 const_cast<char*> (this->request_->operation_details_->opname_);
00049 delete [] opname;
00050
00051 if (this->request_->operation_details_->num_args_ > 0)
00052 {
00053 for (CORBA::ULong i = 0;
00054 i < this->request_->operation_details_->num_args_; i++)
00055 {
00056 delete this->request_->operation_details_->args_[i];
00057 }
00058
00059 delete [] this->request_->operation_details_->args_;
00060 }
00061
00062 delete this->request_->operation_details_;
00063 }
00064
00065 if (this->request_->transport_ != 0)
00066 this->request_->transport_->remove_reference ();
00067
00068 delete this->request_;
00069 }
00070 }
00071
00072
00073
00074 void
00075 TAO::CSD::FW_Server_Request_Wrapper::dispatch
00076 (PortableServer::Servant servant)
00077 {
00078 try
00079 {
00080 servant->_dispatch(*this->request_, 0);
00081 }
00082
00083 catch (const ::CORBA::Exception& ex)
00084 {
00085 if (this->request_->collocated())
00086 {
00087
00088 throw;
00089 }
00090 else if (!this->request_->sync_with_server() &&
00091 this->request_->response_expected() &&
00092 !this->request_->deferred_reply())
00093 {
00094
00095 this->request_->tao_send_reply_exception(ex);
00096 }
00097 else if (TAO_debug_level > 0)
00098 {
00099
00100
00101
00102
00103
00104
00105 ACE_ERROR ((LM_ERROR,
00106 ACE_TEXT ("(%P|%t) exception thrown ")
00107 ACE_TEXT ("but client is not waiting a response\n")));
00108
00109 ex._tao_print_exception ("FW_Server_Request_Wrapper::dispatch ()");
00110 }
00111 }
00112 catch (...)
00113 {
00114
00115
00116
00117
00118
00119
00120
00121 CORBA::UNKNOWN exception (CORBA::SystemException::_tao_minor_code
00122 (TAO_UNHANDLED_SERVER_CXX_EXCEPTION, 0),
00123 CORBA::COMPLETED_MAYBE);
00124
00125 if (this->request_->collocated())
00126 {
00127
00128 throw;
00129 }
00130 else if (!this->request_->sync_with_server() &&
00131 this->request_->response_expected() &&
00132 !this->request_->deferred_reply())
00133 {
00134
00135 this->request_->tao_send_reply_exception(exception);
00136 }
00137 else if (TAO_debug_level > 0)
00138 {
00139
00140
00141
00142
00143
00144
00145 ACE_ERROR ((LM_ERROR,
00146 ACE_TEXT ("(%P|%t) exception thrown ")
00147 ACE_TEXT ("but client is not waiting a response\n")));
00148
00149 exception._tao_print_exception (
00150 "FW_Server_Request_Wrapper::dispatch ()");
00151 }
00152 }
00153
00154 }
00155
00156
00157 TAO_ServerRequest*
00158 TAO::CSD::FW_Server_Request_Wrapper::clone (TAO_ServerRequest*& request)
00159 {
00160
00161 TAO_ServerRequest* clone_obj = 0;
00162 ACE_NEW_RETURN (clone_obj,
00163 TAO_ServerRequest (),
00164 0);
00165
00166
00167
00168 clone_obj->mesg_base_ = request->mesg_base_;
00169
00170
00171
00172 clone_obj->operation (CORBA::string_dup (request->operation ()),
00173 request->operation_length (),
00174 1);
00175
00176
00177
00178 clone_obj->forward_location_ = request->forward_location_;
00179
00180
00181
00182 clone_obj->is_forwarded_ = request->is_forwarded_;
00183
00184
00185
00186 if (request->incoming_ != 0)
00187 {
00188 clone_obj->incoming_ = this->clone (request->incoming_);
00189 }
00190
00191
00192
00193 if (request->outgoing_ != 0)
00194 {
00195 clone_obj->outgoing_ = this->create_new_output_cdr ();
00196 }
00197
00198
00199
00200 clone_obj->transport_ = request->transport_;
00201 if (clone_obj->transport_ != 0)
00202 clone_obj->transport_->add_reference ();
00203
00204
00205
00206 clone_obj->response_expected_ = request->response_expected_;
00207
00208
00209
00210 clone_obj->deferred_reply_ = request->deferred_reply_;
00211
00212
00213
00214 clone_obj->sync_with_server_ = request->sync_with_server_;
00215
00216
00217
00218 clone_obj->is_dsi_ = request->is_dsi_;
00219
00220
00221
00222 clone_obj->reply_status_ = request->reply_status_;
00223
00224
00225
00226 clone_obj->orb_core_ = request->orb_core_;
00227
00228
00229
00230 this->clone (request->request_service_context_, clone_obj->request_service_context_);
00231
00232
00233
00234 this->clone (request->reply_service_context_, clone_obj->reply_service_context_);
00235
00236
00237
00238 clone_obj->request_id_ = request->request_id_;
00239
00240
00241
00242 this->clone (request->profile_, clone_obj->profile_);
00243
00244
00245
00246 clone_obj->requesting_principal_ = request->requesting_principal_;
00247
00248
00249
00250 clone_obj->dsi_nvlist_align_ = request->dsi_nvlist_align_;
00251
00252
00253
00254 if (request->operation_details_ != 0)
00255 {
00256 ACE_ASSERT (request->incoming_ == 0);
00257 if (this->clone (request->operation_details_,
00258 clone_obj->operation_details_,
00259 clone_obj->incoming_) == false)
00260 {
00261 return 0;
00262 }
00263 }
00264
00265
00266
00267 clone_obj->argument_flag_ = request->argument_flag_;
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 if (clone_obj->transport_ != 0)
00291 {
00292 clone_obj->transport_->assign_translators(clone_obj->incoming_,
00293 clone_obj->outgoing_);
00294 }
00295 return clone_obj;
00296 }
00297
00298
00299 TAO_InputCDR*
00300 TAO::CSD::FW_Server_Request_Wrapper::clone (TAO_InputCDR*& from)
00301 {
00302 TAO_InputCDR* clone_ptr = 0;
00303 ACE_NEW_RETURN (clone_ptr,
00304 TAO_InputCDR(*from),
00305 0);
00306 return clone_ptr;
00307 }
00308
00309
00310 bool
00311 TAO::CSD::FW_Server_Request_Wrapper::clone (TAO_Operation_Details const *& from,
00312 TAO_Operation_Details const *& to,
00313 TAO_InputCDR*& cdr)
00314 {
00315 TAO_Operation_Details *& from_non_const
00316 = const_cast <TAO_Operation_Details *&>(from);
00317
00318 char* cloned_op_name = 0;
00319 ACE_NEW_RETURN (cloned_op_name,
00320 char[from_non_const->opname_len_ + 1],
00321 false);
00322 ACE_OS::strncpy(cloned_op_name, from_non_const->opname_, from_non_const->opname_len_);
00323 cloned_op_name[from_non_const->opname_len_] = '\0';
00324
00325
00326
00327
00328 TAO::Argument** cloned_args = 0;
00329 CORBA::ULong num_cloned_args = 0;
00330 if (from->num_args_ > 0)
00331 {
00332 TAO::Argument* retval = from->args_[0]->clone();
00333 if (retval != 0)
00334 {
00335 ACE_NEW_RETURN (cloned_args,
00336 TAO::Argument*[from->num_args_],
00337 false);
00338 cloned_args[0] = retval;
00339 for (CORBA::ULong i = 1; i < from->num_args_; i++)
00340 {
00341 cloned_args[i] = from->args_[i]->clone();
00342 }
00343 num_cloned_args = from->num_args_;
00344 }
00345 else
00346 {
00347 static const size_t mb_size = 2048;
00348 ACE_NEW_RETURN (cdr,
00349 TAO_InputCDR (mb_size),
00350 false);
00351
00352
00353
00354 ACE_Message_Block* mb = const_cast<ACE_Message_Block*> (cdr->start ());
00355 TAO_OutputCDR outcdr (mb);
00356
00357 if (! from_non_const->marshal_args (outcdr))
00358 {
00359 ACE_ERROR ((LM_ERROR,
00360 ACE_TEXT("(%P|%T) TAO::CSD::FW_Server_Request_Wrapper::")
00361 ACE_TEXT("clone TAO_Operation_Details failed\n")));
00362 return false;
00363 }
00364
00365
00366
00367
00368
00369 const ACE_Message_Block* begin = outcdr.begin ();
00370 if (begin == outcdr.current ())
00371 {
00372
00373
00374 mb->rd_ptr (begin->rd_ptr ());
00375 mb->wr_ptr (begin->wr_ptr ());
00376 }
00377 else
00378 {
00379
00380
00381
00382
00383 cdr->reset (begin, outcdr.byte_order ());
00384 }
00385 }
00386 }
00387
00388
00389
00390
00391 TAO_Operation_Details* to_non_const = 0;
00392 ACE_NEW_RETURN (to_non_const,
00393 TAO_Operation_Details(cloned_op_name,
00394 from_non_const->opname_len_,
00395 cloned_args,
00396 num_cloned_args,
00397 0,
00398 0),
00399 false);
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 to_non_const->request_id_ = from->request_id_;
00422 to_non_const->response_flags_ = from->response_flags_;
00423 to_non_const->addressing_mode_ = from->addressing_mode_;
00424
00425
00426
00427
00428
00429
00430 this->clone (from_non_const->request_service_info_, to_non_const->request_service_info_);
00431 this->clone (from_non_const->reply_service_info_, to_non_const->reply_service_info_);
00432
00433 to = to_non_const;
00434
00435 return true;
00436 }
00437
00438
00439 void
00440 TAO::CSD::FW_Server_Request_Wrapper::clone (TAO_Tagged_Profile& from,
00441 TAO_Tagged_Profile& to)
00442 {
00443 to.orb_core_ = from.orb_core_;
00444 to.discriminator_ = from.discriminator_;
00445 to.object_key_extracted_ = from.object_key_extracted_;
00446 to.object_key_ = from.object_key_;
00447 to.profile_ = from.profile_;
00448 to.profile_index_ = from.profile_index_;
00449 to.type_id_ = from.type_id_ == 0 ? 0 :
00450 CORBA::string_dup (from.type_id_);
00451 }
00452
00453
00454 void
00455 TAO::CSD::FW_Server_Request_Wrapper::clone (TAO_Service_Context& from,
00456 TAO_Service_Context& to)
00457 {
00458 to.service_context_ = from.service_context_;
00459 }
00460
00461 TAO_OutputCDR*
00462 TAO::CSD::FW_Server_Request_Wrapper::create_new_output_cdr ()
00463 {
00464 TAO_OutputCDR* cdr = 0;
00465
00466
00467 char* repbuf = 0;
00468 ACE_NEW_RETURN (repbuf,
00469 char[ACE_CDR::DEFAULT_BUFSIZE],
00470 0);
00471
00472 TAO_GIOP_Message_Version giop_version;
00473 this->request_->outgoing_->get_version (giop_version);
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 ACE_NEW_RETURN (cdr,
00486 TAO_OutputCDR (repbuf,
00487 ACE_CDR::DEFAULT_BUFSIZE,
00488 TAO_ENCAP_BYTE_ORDER,
00489 this->request_->orb_core_->input_cdr_buffer_allocator (),
00490 this->request_->orb_core_->input_cdr_dblock_allocator (),
00491 this->request_->orb_core_->input_cdr_msgblock_allocator (),
00492 this->request_->orb_core_->orb_params ()->cdr_memcpy_tradeoff (),
00493 giop_version.major,
00494 giop_version.minor),
00495 0);
00496
00497 return cdr;
00498 }
00499
00500 TAO_END_VERSIONED_NAMESPACE_DECL