00001
00002
00003 #include "tao/PI_Server/ServerRequestInfo.h"
00004
00005 #if (TAO_HAS_INTERCEPTORS == 1)
00006
00007 ACE_RCSID (PI_Server,
00008 ServerRequestInfo,
00009 "ServerRequestInfo.cpp,v 1.5 2006/04/19 09:25:28 jwillemsen Exp")
00010
00011 #include "tao/PortableServer/Root_POA.h"
00012 #include "tao/PortableServer/Servant_Upcall.h"
00013 #include "tao/PortableServer/Servant_Base.h"
00014
00015 #include "tao/TAO_Server_Request.h"
00016 #include "tao/ORB_Core.h"
00017 #include "tao/PolicyC.h"
00018 #include "tao/AnyTypeCode/DynamicC.h"
00019 #include "tao/ORB_Core.h"
00020 #include "tao/Service_Context.h"
00021 #include "tao/PI/RequestInfo_Util.h"
00022 #include "tao/PI/PICurrent.h"
00023 #include "tao/PI/PICurrent_Impl.h"
00024 #include "tao/AnyTypeCode/ExceptionA.h"
00025
00026 #include "ace/OS_NS_string.h"
00027
00028 # if !defined (__ACE_INLINE__)
00029 # include "tao/PI_Server/ServerRequestInfo.inl"
00030 # endif
00031
00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00033
00034 CORBA::ULong
00035 TAO::ServerRequestInfo::request_id (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00036 ACE_THROW_SPEC ((CORBA::SystemException))
00037 {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 CORBA::ULong id = 0;
00048
00049
00050
00051
00052
00053
00054 if (sizeof (this) == 4)
00055 id = static_cast <CORBA::ULong> (
00056 reinterpret_cast <ptrdiff_t>
00057 (&(this->server_request_)));
00058
00059 else if (sizeof (this) == 8)
00060 id = static_cast <CORBA::ULong> (
00061 reinterpret_cast <ptrdiff_t>
00062 (&(this->server_request_)) & 0xFFFFFFFFu);
00063
00064 else
00065
00066
00067
00068 id = this->server_request_.request_id ();
00069
00070 return id;
00071 }
00072
00073 char *
00074 TAO::ServerRequestInfo::operation (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00075 ACE_THROW_SPEC ((CORBA::SystemException))
00076 {
00077 return CORBA::string_dup (this->server_request_.operation ());
00078 }
00079
00080 Dynamic::ParameterList *
00081 TAO::ServerRequestInfo::arguments (ACE_ENV_SINGLE_ARG_DECL)
00082 ACE_THROW_SPEC ((CORBA::SystemException))
00083 {
00084 if (this->args_ == 0)
00085 {
00086 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00087 CORBA::COMPLETED_NO),
00088 0);
00089 }
00090
00091
00092 Dynamic::ParameterList * const parameter_list =
00093 TAO_RequestInfo_Util::make_parameter_list (ACE_ENV_SINGLE_ARG_PARAMETER);
00094 ACE_CHECK_RETURN (0);
00095
00096 Dynamic::ParameterList_var safe_parameter_list = parameter_list;
00097
00098
00099
00100
00101
00102 TAO::Argument * const * const begin = this->args_ + 1;
00103 TAO::Argument * const * const end = this->args_ + this->nargs_;
00104
00105 ACE_ASSERT (end - begin >= 0);
00106
00107 parameter_list->length (static_cast<CORBA::ULong> (end - begin));
00108
00109 CORBA::ULong p = 0;
00110 for (TAO::Argument * const * i = begin; i != end; ++i, ++p)
00111 {
00112
00113
00114 Dynamic::Parameter& parameter = (*parameter_list)[p];
00115 parameter.mode = (*i)->mode ();
00116 (*i)->interceptor_value (¶meter.argument);
00117 }
00118
00119 return safe_parameter_list._retn ();
00120 }
00121
00122 Dynamic::ExceptionList *
00123 TAO::ServerRequestInfo::exceptions (ACE_ENV_SINGLE_ARG_DECL)
00124 ACE_THROW_SPEC ((CORBA::SystemException))
00125 {
00126 if (this->args_ == 0)
00127 {
00128 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00129 CORBA::COMPLETED_NO),
00130 0);
00131 }
00132
00133
00134 Dynamic::ExceptionList * const exception_list =
00135 TAO_RequestInfo_Util::make_exception_list (ACE_ENV_SINGLE_ARG_PARAMETER);
00136 ACE_CHECK_RETURN (0);
00137
00138 Dynamic::ExceptionList_var safe_exception_list = exception_list;
00139
00140 exception_list->length (this->nexceptions_);
00141
00142 CORBA::TypeCode_ptr const * const begin = this->exceptions_;
00143 CORBA::TypeCode_ptr const * const end =
00144 this->exceptions_ + this->nexceptions_;
00145
00146 CORBA::ULong e = 0;
00147 for (CORBA::TypeCode_ptr const * i = begin; i != end; ++i, ++e)
00148 {
00149 CORBA::TypeCode_ptr tcp_object = *i;
00150 (*exception_list)[e] = tcp_object;
00151 }
00152
00153 return safe_exception_list._retn ();
00154 }
00155
00156 Dynamic::ContextList *
00157 TAO::ServerRequestInfo::contexts (ACE_ENV_SINGLE_ARG_DECL)
00158 ACE_THROW_SPEC ((CORBA::SystemException))
00159 {
00160 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00161 CORBA::COMPLETED_NO),
00162 0);
00163 }
00164
00165 Dynamic::RequestContext *
00166 TAO::ServerRequestInfo::operation_context (ACE_ENV_SINGLE_ARG_DECL)
00167 ACE_THROW_SPEC ((CORBA::SystemException))
00168 {
00169 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00170 CORBA::COMPLETED_NO),
00171 0);
00172 }
00173
00174 CORBA::Any *
00175 TAO::ServerRequestInfo::result (ACE_ENV_SINGLE_ARG_DECL)
00176 ACE_THROW_SPEC ((CORBA::SystemException))
00177 {
00178 if (this->args_ == 0)
00179 {
00180 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00181 CORBA::COMPLETED_NO),
00182 0);
00183 }
00184
00185
00186
00187 static CORBA::Boolean const tk_void_any = 1;
00188
00189 CORBA::Any * result_any =
00190 TAO_RequestInfo_Util::make_any (tk_void_any
00191 ACE_ENV_ARG_PARAMETER);
00192 ACE_CHECK_RETURN (0);
00193
00194 CORBA::Any_var safe_result_any = result_any;
00195
00196
00197 TAO::Argument * const r = this->args_[0];
00198
00199 r->interceptor_value (result_any);
00200
00201 return safe_result_any._retn ();
00202 }
00203
00204 CORBA::Boolean
00205 TAO::ServerRequestInfo::response_expected (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00206 ACE_THROW_SPEC ((CORBA::SystemException))
00207 {
00208 return this->server_request_.response_expected ();
00209 }
00210
00211 Messaging::SyncScope
00212 TAO::ServerRequestInfo::sync_scope (ACE_ENV_SINGLE_ARG_DECL)
00213 ACE_THROW_SPEC ((CORBA::SystemException))
00214 {
00215 if (this->server_request_.sync_with_server ())
00216 return Messaging::SYNC_WITH_SERVER;
00217
00218 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00219 CORBA::COMPLETED_NO),
00220 -1);
00221 }
00222
00223 PortableInterceptor::ReplyStatus
00224 TAO::ServerRequestInfo::reply_status (ACE_ENV_SINGLE_ARG_DECL)
00225 ACE_THROW_SPEC ((CORBA::SystemException))
00226 {
00227 if (this->server_request_.reply_status () == -1)
00228
00229 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00230 CORBA::COMPLETED_NO),
00231 -1);
00232
00233 return this->server_request_.reply_status ();
00234 }
00235
00236 CORBA::Object_ptr
00237 TAO::ServerRequestInfo::forward_reference (ACE_ENV_SINGLE_ARG_DECL)
00238 ACE_THROW_SPEC ((CORBA::SystemException))
00239 {
00240 if (this->server_request_.reply_status () != PortableInterceptor::LOCATION_FORWARD)
00241 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00242 CORBA::COMPLETED_NO),
00243 CORBA::Object::_nil ());
00244
00245
00246
00247 return this->server_request_.forward_location ();
00248 }
00249
00250 CORBA::Any *
00251 TAO::ServerRequestInfo::get_slot (PortableInterceptor::SlotId id
00252 ACE_ENV_ARG_DECL)
00253 ACE_THROW_SPEC ((CORBA::SystemException,
00254 PortableInterceptor::InvalidSlot))
00255 {
00256
00257
00258 CORBA::Object_ptr pi_current_obj =
00259 this->server_request_.orb_core ()->pi_current ();
00260
00261 TAO::PICurrent *pi_current =
00262 dynamic_cast <TAO::PICurrent*> (pi_current_obj);
00263
00264 if (pi_current == 0)
00265 ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
00266
00267 pi_current->check_validity (id ACE_ENV_ARG_PARAMETER);
00268 ACE_CHECK_RETURN (0);
00269
00270
00271 TAO::PICurrent_Impl *rsc = this->server_request_.rs_pi_current ();
00272
00273 return rsc->get_slot (id ACE_ENV_ARG_PARAMETER);
00274
00275 }
00276
00277 IOP::ServiceContext *
00278 TAO::ServerRequestInfo::get_request_service_context (
00279 IOP::ServiceId id
00280 ACE_ENV_ARG_DECL)
00281 ACE_THROW_SPEC ((CORBA::SystemException))
00282 {
00283 TAO_Service_Context &service_context_list =
00284 this->server_request_.request_service_context ();
00285
00286 return this->get_service_context_i (service_context_list,
00287 id
00288 ACE_ENV_ARG_PARAMETER);
00289 }
00290
00291 IOP::ServiceContext *
00292 TAO::ServerRequestInfo::get_reply_service_context (
00293 IOP::ServiceId id
00294 ACE_ENV_ARG_DECL)
00295 ACE_THROW_SPEC ((CORBA::SystemException))
00296 {
00297 TAO_Service_Context & service_context_list =
00298 this->server_request_.reply_service_context ();
00299
00300 return this->get_service_context_i (service_context_list,
00301 id
00302 ACE_ENV_ARG_PARAMETER);
00303 }
00304
00305 IOP::ServiceContext *
00306 TAO::ServerRequestInfo::get_service_context_i (
00307 TAO_Service_Context & service_context_list,
00308 IOP::ServiceId id
00309 ACE_ENV_ARG_DECL)
00310 ACE_THROW_SPEC ((CORBA::SystemException))
00311 {
00312 IOP::ServiceContext_var service_context;
00313
00314 if (service_context_list.get_context (id, service_context.out ()) != 0)
00315 {
00316
00317 return service_context._retn ();
00318 }
00319 else
00320 {
00321
00322 ACE_THROW_RETURN (CORBA::BAD_PARAM (CORBA::OMGVMCID | 26,
00323 CORBA::COMPLETED_NO),
00324 0);
00325 }
00326 }
00327
00328
00329
00330
00331 CORBA::Any *
00332 TAO::ServerRequestInfo::sending_exception (ACE_ENV_SINGLE_ARG_DECL)
00333 ACE_THROW_SPEC ((CORBA::SystemException))
00334 {
00335 if (this->server_request_.reply_status () != PortableInterceptor::SYSTEM_EXCEPTION
00336 && this->server_request_.reply_status () != PortableInterceptor::USER_EXCEPTION)
00337 {
00338 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00339 CORBA::COMPLETED_NO),
00340 0);
00341 }
00342
00343
00344
00345
00346
00347 CORBA::Any * temp = 0;
00348
00349 ACE_NEW_THROW_EX (temp,
00350 CORBA::Any,
00351 CORBA::NO_MEMORY (
00352 CORBA::SystemException::_tao_minor_code (
00353 TAO::VMCID,
00354 ENOMEM),
00355 CORBA::COMPLETED_NO));
00356 ACE_CHECK_RETURN (0);
00357
00358 CORBA::Any_var caught_exception_var = temp;
00359
00360 if (this->server_request_.caught_exception () != 0)
00361 (*temp) <<= *(this->server_request_.caught_exception ());
00362
00363 return caught_exception_var._retn ();
00364 }
00365
00366 char *
00367 TAO::ServerRequestInfo::server_id (ACE_ENV_SINGLE_ARG_DECL)
00368 ACE_THROW_SPEC ((CORBA::SystemException))
00369 {
00370 if (this->servant_upcall_ != 0)
00371 return
00372 CORBA::string_dup (this->server_request_.orb_core ()->server_id ());
00373
00374
00375 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00376 CORBA::COMPLETED_NO),
00377 0);
00378 }
00379
00380 char *
00381 TAO::ServerRequestInfo::orb_id (ACE_ENV_SINGLE_ARG_DECL)
00382 ACE_THROW_SPEC ((CORBA::SystemException))
00383 {
00384 if (this->servant_upcall_ != 0)
00385 return
00386 CORBA::string_dup (this->server_request_.orb_core ()->orbid ());
00387
00388 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00389 CORBA::COMPLETED_NO),
00390 0);
00391 }
00392
00393 PortableInterceptor::AdapterName *
00394 TAO::ServerRequestInfo::adapter_name (ACE_ENV_SINGLE_ARG_DECL)
00395 ACE_THROW_SPEC ((CORBA::SystemException))
00396 {
00397
00398
00399
00400
00401
00402 if (this->servant_upcall_ != 0)
00403 return
00404 this->servant_upcall_->poa ().adapter_name (
00405 ACE_ENV_SINGLE_ARG_PARAMETER);
00406
00407 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00408 CORBA::COMPLETED_NO),
00409 0);
00410 }
00411
00412 PortableInterceptor::ObjectId *
00413 TAO::ServerRequestInfo::object_id (ACE_ENV_SINGLE_ARG_DECL)
00414 ACE_THROW_SPEC ((CORBA::SystemException))
00415 {
00416 if (this->servant_upcall_ != 0)
00417 {
00418 const PortableServer::ObjectId &id =
00419 this->servant_upcall_->user_id ();
00420
00421 PortableInterceptor::ObjectId *tmp = 0;
00422
00423 ACE_NEW_THROW_EX (tmp,
00424 PortableInterceptor::ObjectId,
00425 CORBA::NO_MEMORY (
00426 CORBA::SystemException::_tao_minor_code (
00427 TAO::VMCID,
00428 ENOMEM),
00429 CORBA::COMPLETED_NO));
00430 ACE_CHECK_RETURN (0);
00431
00432 PortableInterceptor::ObjectId_var obj_id = tmp;
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442 const CORBA::ULong len = id.length ();
00443 obj_id->length (len);
00444 CORBA::Octet *buffer = obj_id->get_buffer ();
00445 ACE_OS::memcpy (buffer, id.get_buffer (), len);
00446
00447 return obj_id._retn ();
00448 }
00449
00450 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00451 CORBA::COMPLETED_NO),
00452 0);
00453 }
00454
00455 CORBA::OctetSeq *
00456 TAO::ServerRequestInfo::adapter_id (ACE_ENV_SINGLE_ARG_DECL)
00457 ACE_THROW_SPEC ((CORBA::SystemException))
00458 {
00459 if (this->servant_upcall_ != 0)
00460 return this->servant_upcall_->poa ().id (ACE_ENV_SINGLE_ARG_PARAMETER);
00461
00462 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00463 CORBA::COMPLETED_NO),
00464 0);
00465 }
00466
00467 char *
00468 TAO::ServerRequestInfo::target_most_derived_interface (
00469 ACE_ENV_SINGLE_ARG_DECL)
00470 ACE_THROW_SPEC ((CORBA::SystemException))
00471 {
00472 PortableServer::Servant const servant =
00473 (this->servant_upcall_ == 0
00474 ? 0
00475 : this->servant_upcall_->servant ());
00476
00477 if (servant == 0)
00478 {
00479 ACE_THROW_RETURN (CORBA::NO_RESOURCES (CORBA::OMGVMCID | 1,
00480 CORBA::COMPLETED_NO),
00481 0);
00482 }
00483
00484 return CORBA::string_dup (servant->_interface_repository_id ());
00485 }
00486
00487 CORBA::Policy_ptr
00488 TAO::ServerRequestInfo::get_server_policy (CORBA::PolicyType type
00489 ACE_ENV_ARG_DECL)
00490 ACE_THROW_SPEC ((CORBA::SystemException))
00491 {
00492 if (this->servant_upcall_ != 0)
00493 {
00494 CORBA::Policy_var policy =
00495 this->servant_upcall_->poa ().get_policy (type ACE_ENV_ARG_PARAMETER);
00496 ACE_CHECK_RETURN (CORBA::Policy::_nil ());
00497
00498 if (!CORBA::is_nil (policy.in ()))
00499 {
00500 return policy._retn ();
00501 }
00502 else
00503 {
00504
00505 ACE_THROW_RETURN (CORBA::INV_POLICY (CORBA::OMGVMCID | 3,
00506 CORBA::COMPLETED_NO),
00507 CORBA::Policy::_nil ());
00508 }
00509 }
00510
00511
00512
00513
00514 ACE_THROW_RETURN (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14,
00515 CORBA::COMPLETED_NO),
00516 CORBA::Policy::_nil ());
00517 }
00518
00519 void
00520 TAO::ServerRequestInfo::set_slot (PortableInterceptor::SlotId id,
00521 const CORBA::Any &data
00522 ACE_ENV_ARG_DECL)
00523 ACE_THROW_SPEC ((CORBA::SystemException,
00524 PortableInterceptor::InvalidSlot))
00525 {
00526
00527
00528 CORBA::Object_ptr pi_current_obj =
00529 this->server_request_.orb_core ()->pi_current ();
00530
00531 TAO::PICurrent *pi_current =
00532 dynamic_cast <TAO::PICurrent*> (pi_current_obj);
00533
00534 if (pi_current == 0)
00535 ACE_THROW (CORBA::INTERNAL ());
00536
00537 pi_current->check_validity (id ACE_ENV_ARG_PARAMETER);
00538 ACE_CHECK;
00539
00540
00541 TAO::PICurrent_Impl * rsc = this->server_request_.rs_pi_current ();
00542
00543 rsc->set_slot (id, data ACE_ENV_ARG_PARAMETER);
00544 ACE_CHECK;
00545 }
00546
00547 CORBA::Boolean
00548 TAO::ServerRequestInfo::target_is_a (const char * id
00549 ACE_ENV_ARG_DECL)
00550 ACE_THROW_SPEC ((CORBA::SystemException))
00551 {
00552
00553
00554 PortableServer::Servant const servant =
00555 (this->servant_upcall_ == 0
00556 ? 0
00557 : this->servant_upcall_->servant ());
00558
00559
00560 if (servant == 0)
00561 {
00562 ACE_THROW_RETURN (CORBA::NO_RESOURCES (CORBA::OMGVMCID | 1,
00563 CORBA::COMPLETED_NO),
00564 0);
00565 }
00566
00567 return servant->_is_a (id
00568 ACE_ENV_ARG_PARAMETER);
00569 }
00570
00571 void
00572 TAO::ServerRequestInfo::add_reply_service_context (
00573 const IOP::ServiceContext & service_context,
00574 CORBA::Boolean replace
00575 ACE_ENV_ARG_DECL)
00576 ACE_THROW_SPEC ((CORBA::SystemException))
00577 {
00578
00579 TAO_Service_Context &service_context_list =
00580 this->server_request_.reply_service_context ();
00581
00582 if (service_context_list.set_context (service_context, replace) == 0)
00583 {
00584 ACE_THROW (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 15,
00585 CORBA::COMPLETED_NO));
00586 }
00587 }
00588
00589 TAO_END_VERSIONED_NAMESPACE_DECL
00590
00591 #endif