00001 #include "tao/RTCORBA/RT_Protocols_Hooks.h"
00002
00003 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00004
00005 #include "tao/RTCORBA/RT_Policy_i.h"
00006 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
00007 #include "tao/RTCORBA/RT_Stub.h"
00008
00009 #include "tao/Stub.h"
00010 #include "tao/ORB_Core.h"
00011 #include "tao/MProfile.h"
00012 #include "tao/Service_Context.h"
00013 #include "tao/Acceptor_Registry.h"
00014 #include "tao/Thread_Lane_Resources.h"
00015 #include "tao/Protocol_Factory.h"
00016 #include "tao/Transport_Acceptor.h"
00017 #include "tao/Transport_Connector.h"
00018 #include "tao/Policy_Set.h"
00019 #include "tao/debug.h"
00020 #include "tao/CDR.h"
00021
00022 #include "ace/Dynamic_Service.h"
00023 #include "ace/OS_NS_string.h"
00024
00025 ACE_RCSID (RTCORBA,
00026 RT_Protocols_Hooks,
00027 "RT_Protocols_Hooks.cpp,v 1.42 2006/06/20 07:09:22 jwillemsen Exp")
00028
00029 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00030
00031 TAO_RT_Protocols_Hooks::TAO_RT_Protocols_Hooks (void)
00032 : orb_core_ (0)
00033 , current_ ()
00034 {
00035 }
00036
00037
00038 TAO_RT_Protocols_Hooks::~TAO_RT_Protocols_Hooks (void)
00039 {
00040 }
00041
00042 void
00043 TAO_RT_Protocols_Hooks::init_hooks (TAO_ORB_Core *orb_core
00044 ACE_ENV_ARG_DECL)
00045 {
00046 this->orb_core_ = orb_core;
00047
00048
00049 CORBA::Object_var obj =
00050 orb_core->object_ref_table ().resolve_initial_reference (
00051 TAO_OBJID_PRIORITYMAPPINGMANAGER);
00052
00053 this->mapping_manager_ =
00054 TAO_Priority_Mapping_Manager::_narrow (obj.in ()
00055 ACE_ENV_ARG_PARAMETER);
00056 ACE_CHECK;
00057
00058
00059 CORBA::Object_var object =
00060 orb_core->object_ref_table ().resolve_initial_reference (
00061 TAO_OBJID_NETWORKPRIORITYMAPPINGMANAGER);
00062
00063 this->network_mapping_manager_ =
00064 TAO_Network_Priority_Mapping_Manager::_narrow (object.in ()
00065 ACE_ENV_ARG_PARAMETER);
00066 ACE_CHECK;
00067
00068 object =
00069 this->orb_core_->object_ref_table ().resolve_initial_reference (
00070 TAO_OBJID_RTCURRENT);
00071
00072 this->current_ =
00073 RTCORBA::Current::_narrow (object.in ()
00074 ACE_ENV_ARG_PARAMETER);
00075 ACE_CHECK;
00076
00077 }
00078
00079 RTCORBA::ProtocolProperties_ptr
00080 TAO_RT_Protocols_Hooks::server_protocol_properties (IOP::ProfileId protocol_tag,
00081 CORBA::Policy_ptr policy
00082 ACE_ENV_ARG_DECL)
00083 {
00084 if (CORBA::is_nil (policy))
00085 return 0;
00086
00087 RTCORBA::ServerProtocolPolicy_var server_protocol_policy =
00088 RTCORBA::ServerProtocolPolicy::_narrow (policy
00089 ACE_ENV_ARG_PARAMETER);
00090 ACE_CHECK_RETURN (0);
00091
00092 if (CORBA::is_nil (server_protocol_policy.in ()))
00093 return 0;
00094
00095 TAO_ServerProtocolPolicy *server_protocols =
00096 dynamic_cast<TAO_ServerProtocolPolicy *> (server_protocol_policy.in ());
00097
00098 if (server_protocols == 0)
00099 return 0;
00100
00101
00102 RTCORBA::ProtocolList &protocols =
00103 server_protocols->protocols_rep ();
00104
00105 for (CORBA::ULong j = 0; j < protocols.length (); ++j)
00106 {
00107 if (protocols[j].protocol_type == protocol_tag)
00108 {
00109 return RTCORBA::ProtocolProperties::_duplicate (protocols[j].transport_protocol_properties.in ());
00110 }
00111 }
00112
00113 return 0;
00114 }
00115
00116 RTCORBA::ProtocolProperties_ptr
00117 TAO_RT_Protocols_Hooks::client_protocol_properties (IOP::ProfileId protocol_tag,
00118 CORBA::Policy_ptr policy
00119 ACE_ENV_ARG_DECL)
00120 {
00121 if (CORBA::is_nil (policy))
00122 return 0;
00123
00124 RTCORBA::ClientProtocolPolicy_var client_protocol_policy =
00125 RTCORBA::ClientProtocolPolicy::_narrow (policy
00126 ACE_ENV_ARG_PARAMETER);
00127 ACE_CHECK_RETURN (0);
00128
00129 if (CORBA::is_nil (client_protocol_policy.in ()))
00130 return 0;
00131
00132 TAO_ClientProtocolPolicy *client_protocols =
00133 dynamic_cast<TAO_ClientProtocolPolicy *> (client_protocol_policy.in ());
00134
00135 if (client_protocols == 0)
00136 return 0;
00137
00138
00139 RTCORBA::ProtocolList &protocols =
00140 client_protocols->protocols_rep ();
00141
00142 for (CORBA::ULong j = 0; j < protocols.length (); ++j)
00143 {
00144 if (protocols[j].protocol_type == protocol_tag)
00145 {
00146 return RTCORBA::ProtocolProperties::_duplicate (protocols[j].transport_protocol_properties.in ());
00147 }
00148 }
00149
00150 return 0;
00151 }
00152
00153 RTCORBA::ProtocolProperties_ptr
00154 TAO_RT_Protocols_Hooks::server_protocol_properties_at_orb_level (IOP::ProfileId protocol_tag
00155 ACE_ENV_ARG_DECL)
00156 {
00157 CORBA::Policy_var policy =
00158 this->orb_core_->get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL
00159 ACE_ENV_ARG_PARAMETER);
00160 ACE_CHECK_RETURN (0);
00161
00162 return this->server_protocol_properties (protocol_tag,
00163 policy.in ()
00164 ACE_ENV_ARG_PARAMETER);
00165 }
00166
00167 RTCORBA::ProtocolProperties_ptr
00168 TAO_RT_Protocols_Hooks::client_protocol_properties_at_orb_level (IOP::ProfileId protocol_tag
00169 ACE_ENV_ARG_DECL)
00170 {
00171 CORBA::Policy_var policy =
00172 this->orb_core_->get_cached_policy (TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL
00173 ACE_ENV_ARG_PARAMETER);
00174 ACE_CHECK_RETURN (0);
00175
00176 return this->client_protocol_properties (protocol_tag,
00177 policy.in ()
00178 ACE_ENV_ARG_PARAMETER);
00179 }
00180
00181 RTCORBA::ProtocolProperties_ptr
00182 TAO_RT_Protocols_Hooks::client_protocol_properties_at_object_level (IOP::ProfileId protocol_tag,
00183 TAO_Stub *stub
00184 ACE_ENV_ARG_DECL)
00185 {
00186 CORBA::Policy_var policy =
00187 stub->get_cached_policy (TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL
00188 ACE_ENV_ARG_PARAMETER);
00189 ACE_CHECK_RETURN (0);
00190
00191 return this->client_protocol_properties (protocol_tag,
00192 policy.in ()
00193 ACE_ENV_ARG_PARAMETER);
00194 }
00195
00196 void
00197 TAO_RT_Protocols_Hooks::extract_protocol_properties (TAO_IIOP_Protocol_Properties &to,
00198 RTCORBA::ProtocolProperties_ptr from
00199 ACE_ENV_ARG_DECL)
00200 {
00201 RTCORBA::TCPProtocolProperties_var protocol_properties =
00202 RTCORBA::TCPProtocolProperties::_narrow (from
00203 ACE_ENV_ARG_PARAMETER);
00204 ACE_CHECK;
00205
00206 to.send_buffer_size_ = protocol_properties->send_buffer_size ();
00207 to.recv_buffer_size_ = protocol_properties->recv_buffer_size ();
00208 to.keep_alive_ = protocol_properties->keep_alive ();
00209 to.dont_route_ = protocol_properties->dont_route ();
00210 to.no_delay_ = protocol_properties->no_delay ();
00211 to.enable_network_priority_ = protocol_properties->enable_network_priority ();
00212 }
00213
00214 void
00215 TAO_RT_Protocols_Hooks::server_protocol_properties_at_orb_level (TAO_IIOP_Protocol_Properties &to
00216 ACE_ENV_ARG_DECL)
00217 {
00218 RTCORBA::ProtocolProperties_var from =
00219 this->server_protocol_properties_at_orb_level (IOP::TAG_INTERNET_IOP
00220 ACE_ENV_ARG_PARAMETER);
00221 ACE_CHECK;
00222
00223 if (!CORBA::is_nil (from.in ()))
00224 this->extract_protocol_properties (to,
00225 from.in ()
00226 ACE_ENV_ARG_PARAMETER);
00227 ACE_CHECK;
00228 }
00229
00230 void
00231 TAO_RT_Protocols_Hooks::client_protocol_properties_at_orb_level (TAO_IIOP_Protocol_Properties &to
00232 ACE_ENV_ARG_DECL)
00233 {
00234 RTCORBA::ProtocolProperties_var from =
00235 this->client_protocol_properties_at_orb_level (IOP::TAG_INTERNET_IOP
00236 ACE_ENV_ARG_PARAMETER);
00237 ACE_CHECK;
00238
00239 if (!CORBA::is_nil (from.in ()))
00240 this->extract_protocol_properties (to,
00241 from.in ()
00242 ACE_ENV_ARG_PARAMETER);
00243 }
00244
00245 void
00246 TAO_RT_Protocols_Hooks::extract_protocol_properties (TAO_UIOP_Protocol_Properties &to,
00247 RTCORBA::ProtocolProperties_ptr from
00248 ACE_ENV_ARG_DECL)
00249 {
00250 RTCORBA::UnixDomainProtocolProperties_var protocol_properties =
00251 RTCORBA::UnixDomainProtocolProperties::_narrow (from
00252 ACE_ENV_ARG_PARAMETER);
00253 ACE_CHECK;
00254
00255 to.send_buffer_size_ = protocol_properties->send_buffer_size ();
00256 to.recv_buffer_size_ = protocol_properties->recv_buffer_size ();
00257 }
00258
00259 void
00260 TAO_RT_Protocols_Hooks::server_protocol_properties_at_orb_level (TAO_UIOP_Protocol_Properties &to
00261 ACE_ENV_ARG_DECL)
00262 {
00263 RTCORBA::ProtocolProperties_var from =
00264 this->server_protocol_properties_at_orb_level (TAO_TAG_UIOP_PROFILE
00265 ACE_ENV_ARG_PARAMETER);
00266 ACE_CHECK;
00267
00268 if (!CORBA::is_nil (from.in ()))
00269 this->extract_protocol_properties (to,
00270 from.in ()
00271 ACE_ENV_ARG_PARAMETER);
00272 ACE_CHECK;
00273 }
00274
00275 void
00276 TAO_RT_Protocols_Hooks::client_protocol_properties_at_orb_level (TAO_UIOP_Protocol_Properties &to
00277 ACE_ENV_ARG_DECL)
00278 {
00279 RTCORBA::ProtocolProperties_var from =
00280 this->client_protocol_properties_at_orb_level (TAO_TAG_UIOP_PROFILE
00281 ACE_ENV_ARG_PARAMETER);
00282 ACE_CHECK;
00283
00284 if (!CORBA::is_nil (from.in ()))
00285 this->extract_protocol_properties (to,
00286 from.in ()
00287 ACE_ENV_ARG_PARAMETER);
00288 }
00289
00290 void
00291 TAO_RT_Protocols_Hooks::extract_protocol_properties (TAO_SHMIOP_Protocol_Properties &to,
00292 RTCORBA::ProtocolProperties_ptr from
00293 ACE_ENV_ARG_DECL)
00294 {
00295 RTCORBA::SharedMemoryProtocolProperties_var protocol_properties =
00296 RTCORBA::SharedMemoryProtocolProperties::_narrow (from
00297 ACE_ENV_ARG_PARAMETER);
00298 ACE_CHECK;
00299
00300 to.preallocate_buffer_size_ = protocol_properties->preallocate_buffer_size ();
00301 to.mmap_filename_ = protocol_properties->mmap_filename ();
00302 to.mmap_lockname_ = protocol_properties->mmap_lockname ();
00303 }
00304
00305 void
00306 TAO_RT_Protocols_Hooks::server_protocol_properties_at_orb_level (TAO_SHMIOP_Protocol_Properties &to
00307 ACE_ENV_ARG_DECL)
00308 {
00309 RTCORBA::ProtocolProperties_var from =
00310 this->server_protocol_properties_at_orb_level (TAO_TAG_SHMEM_PROFILE
00311 ACE_ENV_ARG_PARAMETER);
00312 ACE_CHECK;
00313
00314 if (!CORBA::is_nil (from.in ()))
00315 this->extract_protocol_properties (to,
00316 from.in ()
00317 ACE_ENV_ARG_PARAMETER);
00318 ACE_CHECK;
00319 }
00320
00321 void
00322 TAO_RT_Protocols_Hooks::client_protocol_properties_at_orb_level (TAO_SHMIOP_Protocol_Properties &to
00323 ACE_ENV_ARG_DECL)
00324 {
00325 RTCORBA::ProtocolProperties_var from =
00326 this->client_protocol_properties_at_orb_level (TAO_TAG_SHMEM_PROFILE
00327 ACE_ENV_ARG_PARAMETER);
00328 ACE_CHECK;
00329
00330 if (!CORBA::is_nil (from.in ()))
00331 this->extract_protocol_properties (to,
00332 from.in ()
00333 ACE_ENV_ARG_PARAMETER);
00334 }
00335
00336 void
00337 TAO_RT_Protocols_Hooks::extract_protocol_properties (TAO_DIOP_Protocol_Properties &to,
00338 RTCORBA::ProtocolProperties_ptr from
00339 ACE_ENV_ARG_DECL)
00340 {
00341 RTCORBA::UserDatagramProtocolProperties_var protocol_properties =
00342 RTCORBA::UserDatagramProtocolProperties::_narrow (from
00343 ACE_ENV_ARG_PARAMETER);
00344 ACE_CHECK;
00345
00346 to.enable_network_priority_ = protocol_properties->enable_network_priority ();
00347 }
00348
00349 void
00350 TAO_RT_Protocols_Hooks::server_protocol_properties_at_orb_level (TAO_DIOP_Protocol_Properties &to
00351 ACE_ENV_ARG_DECL)
00352 {
00353 RTCORBA::ProtocolProperties_var from =
00354 this->server_protocol_properties_at_orb_level (TAO_TAG_DIOP_PROFILE
00355 ACE_ENV_ARG_PARAMETER);
00356 ACE_CHECK;
00357
00358 if (!CORBA::is_nil (from.in ()))
00359 this->extract_protocol_properties (to,
00360 from.in ()
00361 ACE_ENV_ARG_PARAMETER);
00362 ACE_CHECK;
00363 }
00364
00365 void
00366 TAO_RT_Protocols_Hooks::client_protocol_properties_at_orb_level (TAO_DIOP_Protocol_Properties &to
00367 ACE_ENV_ARG_DECL)
00368 {
00369 RTCORBA::ProtocolProperties_var from =
00370 this->client_protocol_properties_at_orb_level (TAO_TAG_DIOP_PROFILE
00371 ACE_ENV_ARG_PARAMETER);
00372 ACE_CHECK;
00373
00374 if (!CORBA::is_nil (from.in ()))
00375 this->extract_protocol_properties (to,
00376 from.in ()
00377 ACE_ENV_ARG_PARAMETER);
00378 }
00379
00380 void
00381 TAO_RT_Protocols_Hooks::extract_protocol_properties (TAO_SCIOP_Protocol_Properties &to,
00382 RTCORBA::ProtocolProperties_ptr from
00383 ACE_ENV_ARG_DECL)
00384 {
00385 RTCORBA::StreamControlProtocolProperties_var protocol_properties =
00386 RTCORBA::StreamControlProtocolProperties::_narrow (from
00387 ACE_ENV_ARG_PARAMETER);
00388 ACE_CHECK;
00389
00390 to.send_buffer_size_ = protocol_properties->send_buffer_size ();
00391 to.recv_buffer_size_ = protocol_properties->recv_buffer_size ();
00392 to.keep_alive_ = protocol_properties->keep_alive ();
00393 to.dont_route_ = protocol_properties->dont_route ();
00394 to.no_delay_ = protocol_properties->no_delay ();
00395 to.enable_network_priority_ = protocol_properties->enable_network_priority ();
00396 }
00397
00398 void
00399 TAO_RT_Protocols_Hooks::server_protocol_properties_at_orb_level (TAO_SCIOP_Protocol_Properties &to
00400 ACE_ENV_ARG_DECL)
00401 {
00402 RTCORBA::ProtocolProperties_var from =
00403 this->server_protocol_properties_at_orb_level (TAO_TAG_SCIOP_PROFILE
00404 ACE_ENV_ARG_PARAMETER);
00405 ACE_CHECK;
00406
00407 if (!CORBA::is_nil (from.in ()))
00408 this->extract_protocol_properties (to,
00409 from.in ()
00410 ACE_ENV_ARG_PARAMETER);
00411 ACE_CHECK;
00412 }
00413
00414 void
00415 TAO_RT_Protocols_Hooks::client_protocol_properties_at_orb_level (TAO_SCIOP_Protocol_Properties &to
00416 ACE_ENV_ARG_DECL)
00417 {
00418 RTCORBA::ProtocolProperties_var from =
00419 this->client_protocol_properties_at_orb_level (TAO_TAG_SCIOP_PROFILE
00420 ACE_ENV_ARG_PARAMETER);
00421 ACE_CHECK;
00422
00423 if (!CORBA::is_nil (from.in ()))
00424 this->extract_protocol_properties (to,
00425 from.in ()
00426 ACE_ENV_ARG_PARAMETER);
00427 }
00428
00429 CORBA::Boolean
00430 TAO_RT_Protocols_Hooks::set_network_priority (IOP::ProfileId protocol_tag,
00431 RTCORBA::ProtocolProperties_ptr protocol_properties
00432 ACE_ENV_ARG_DECL)
00433 {
00434 if (CORBA::is_nil (protocol_properties))
00435 return false;
00436
00437 if (protocol_tag == IOP::TAG_INTERNET_IOP)
00438 {
00439 RTCORBA::TCPProtocolProperties_var tcp_protocol_properties =
00440 RTCORBA::TCPProtocolProperties::_narrow (protocol_properties
00441 ACE_ENV_ARG_PARAMETER);
00442 ACE_CHECK_RETURN (false);
00443
00444 return tcp_protocol_properties->enable_network_priority ();
00445 }
00446
00447 if (protocol_tag == TAO_TAG_DIOP_PROFILE)
00448 {
00449 RTCORBA::UserDatagramProtocolProperties_var udp_protocol_properties =
00450 RTCORBA::UserDatagramProtocolProperties::_narrow (protocol_properties
00451 ACE_ENV_ARG_PARAMETER);
00452 ACE_CHECK_RETURN (false);
00453
00454 return udp_protocol_properties->enable_network_priority ();
00455 }
00456
00457 if (protocol_tag == TAO_TAG_SCIOP_PROFILE)
00458 {
00459 RTCORBA::StreamControlProtocolProperties_var sctp_protocol_properties =
00460 RTCORBA::StreamControlProtocolProperties::_narrow (protocol_properties
00461 ACE_ENV_ARG_PARAMETER);
00462 ACE_CHECK_RETURN (false);
00463
00464 return sctp_protocol_properties->enable_network_priority ();
00465 }
00466
00467 return false;
00468 }
00469
00470 CORBA::Boolean
00471 TAO_RT_Protocols_Hooks::set_client_network_priority (IOP::ProfileId protocol_tag,
00472 TAO_Stub *stub
00473 ACE_ENV_ARG_DECL)
00474 {
00475 if (protocol_tag != IOP::TAG_INTERNET_IOP &&
00476 protocol_tag != TAO_TAG_DIOP_PROFILE &&
00477 protocol_tag != TAO_TAG_SCIOP_PROFILE)
00478 return false;
00479
00480 RTCORBA::ProtocolProperties_var protocol_properties =
00481 this->client_protocol_properties_at_object_level (protocol_tag,
00482 stub
00483 ACE_ENV_ARG_PARAMETER);
00484 ACE_CHECK_RETURN (false);
00485
00486 return this->set_network_priority (protocol_tag,
00487 protocol_properties.in ()
00488 ACE_ENV_ARG_PARAMETER);
00489 }
00490
00491 CORBA::Boolean
00492 TAO_RT_Protocols_Hooks::set_server_network_priority (IOP::ProfileId protocol_tag,
00493 CORBA::Policy *policy
00494 ACE_ENV_ARG_DECL)
00495 {
00496 if (protocol_tag != IOP::TAG_INTERNET_IOP &&
00497 protocol_tag != TAO_TAG_DIOP_PROFILE &&
00498 protocol_tag != TAO_TAG_SCIOP_PROFILE)
00499 return false;
00500
00501 RTCORBA::ProtocolProperties_var protocol_properties =
00502 this->server_protocol_properties (protocol_tag,
00503 policy
00504 ACE_ENV_ARG_PARAMETER);
00505 ACE_CHECK_RETURN (false);
00506
00507 return this->set_network_priority (protocol_tag,
00508 protocol_properties.in ()
00509 ACE_ENV_ARG_PARAMETER);
00510 }
00511
00512 CORBA::Long
00513 TAO_RT_Protocols_Hooks::get_dscp_codepoint (void)
00514 {
00515 if (TAO_debug_level)
00516 ACE_DEBUG ((LM_DEBUG,
00517 "TAO_RT_Protocols_Hooks::get_dscp_codepoint\n"));
00518
00519 CORBA::Long codepoint = 0;
00520
00521 ACE_DECLARE_NEW_CORBA_ENV;
00522 ACE_TRY
00523 {
00524
00525
00526
00527 RTCORBA::NetworkPriorityMapping *pm =
00528 this->network_mapping_manager_->mapping ();
00529
00530 const CORBA::Short priority =
00531 this->current_->the_priority (ACE_ENV_SINGLE_ARG_PARAMETER);
00532 ACE_TRY_CHECK;
00533
00534 if (pm->to_network (priority, codepoint) == 0)
00535 {
00536 if (TAO_debug_level > 0)
00537 {
00538 ACE_ERROR ((LM_ERROR,
00539 "Cannot convert corba priority %d "
00540 "to network priority\n",
00541 priority));
00542 }
00543
00544 return -1;
00545 }
00546 }
00547 ACE_CATCHANY
00548 {
00549 if (TAO_debug_level > 0)
00550 {
00551 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00552 "TAO_RT_Protocols_Hooks::get_dscp_codepoint");
00553 }
00554
00555 return -1;
00556 }
00557 ACE_ENDTRY;
00558 ACE_CHECK_RETURN (-1);
00559
00560 return codepoint;
00561 }
00562
00563 void
00564 TAO_RT_Protocols_Hooks::rt_service_context (
00565 TAO_Stub *stub,
00566 TAO_Service_Context &service_context,
00567 CORBA::Boolean restart
00568 ACE_ENV_ARG_DECL
00569 )
00570 {
00571
00572
00573
00574 if (!restart)
00575 {
00576 TAO_RT_Stub *rt_stub =
00577 dynamic_cast<TAO_RT_Stub *> (stub);
00578
00579 CORBA::Policy_var priority_model_policy =
00580 rt_stub->get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL
00581 ACE_ENV_ARG_PARAMETER);
00582 ACE_CHECK;
00583
00584 if (!CORBA::is_nil (priority_model_policy.in ()))
00585 {
00586 CORBA::Short client_priority;
00587
00588 int status =
00589 this->get_thread_CORBA_priority (client_priority
00590 ACE_ENV_ARG_PARAMETER);
00591 ACE_CHECK;
00592
00593 if (status == -1)
00594 ACE_THROW (CORBA::DATA_CONVERSION (1, CORBA::COMPLETED_NO));
00595
00596 this->add_rt_service_context_hook (service_context,
00597 priority_model_policy.in (),
00598 client_priority
00599 ACE_ENV_ARG_PARAMETER);
00600 ACE_CHECK;
00601 }
00602 else
00603 {
00604
00605
00606 }
00607 }
00608 }
00609
00610 void
00611 TAO_RT_Protocols_Hooks::add_rt_service_context_hook (
00612 TAO_Service_Context &service_context,
00613 CORBA::Policy *model_policy,
00614 CORBA::Short &client_priority
00615 ACE_ENV_ARG_DECL
00616 )
00617 {
00618
00619 RTCORBA::PriorityModelPolicy_var model_policy_ptr =
00620 RTCORBA::PriorityModelPolicy::_narrow (model_policy
00621 ACE_ENV_ARG_PARAMETER);
00622 ACE_CHECK;
00623
00624 TAO_PriorityModelPolicy *priority_model =
00625 static_cast<TAO_PriorityModelPolicy *> (model_policy_ptr.in ());
00626
00627 if (priority_model->get_priority_model () == RTCORBA::CLIENT_PROPAGATED)
00628 {
00629
00630
00631 TAO_OutputCDR cdr;
00632 if ((cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER) == 0)
00633 || (cdr << client_priority) == 0)
00634 {
00635 ACE_THROW (CORBA::MARSHAL ());
00636 }
00637
00638 service_context.set_context (IOP::RTCorbaPriority, cdr);
00639 }
00640 }
00641
00642 void
00643 TAO_RT_Protocols_Hooks::get_selector_hook (
00644 CORBA::Policy *model_policy,
00645 CORBA::Boolean &is_client_propagated,
00646 CORBA::Short &server_priority
00647 )
00648 {
00649
00650 RTCORBA::PriorityModelPolicy_var model_policy_ptr =
00651 RTCORBA::PriorityModelPolicy::_narrow (model_policy);
00652
00653 TAO_PriorityModelPolicy *priority_model_policy =
00654 static_cast<TAO_PriorityModelPolicy *> (model_policy_ptr.in ());
00655
00656 if (priority_model_policy->get_priority_model ()
00657 == RTCORBA::CLIENT_PROPAGATED)
00658 {
00659 is_client_propagated = 1;
00660 }
00661
00662 if (!is_client_propagated)
00663 {
00664 server_priority = priority_model_policy->server_priority ();
00665 }
00666
00667 return;
00668 }
00669
00670 void
00671 TAO_RT_Protocols_Hooks::get_selector_bands_policy_hook (
00672 CORBA::Policy *bands_policy,
00673 CORBA::Short priority,
00674 CORBA::Short &min_priority,
00675 CORBA::Short &max_priority,
00676 int &in_range
00677 )
00678 {
00679 RTCORBA::PriorityBandedConnectionPolicy_var bands_policy_ptr =
00680 RTCORBA::PriorityBandedConnectionPolicy::_narrow (bands_policy);
00681
00682 TAO_PriorityBandedConnectionPolicy *priority_bands_policy =
00683 static_cast<TAO_PriorityBandedConnectionPolicy *> (bands_policy_ptr.in ());
00684
00685
00686 RTCORBA::PriorityBands &bands =
00687 priority_bands_policy->priority_bands_rep ();
00688
00689 for (CORBA::ULong i = 0; i < bands.length (); ++i)
00690 {
00691 if (bands[i].low <= priority && bands[i].high >= priority)
00692 {
00693 min_priority = bands[i].low;
00694 max_priority = bands[i].high;
00695
00696 in_range = 1;
00697 break;
00698 }
00699 }
00700 }
00701
00702 int
00703 TAO_RT_Protocols_Hooks::get_thread_CORBA_priority (CORBA::Short &priority
00704 ACE_ENV_ARG_DECL)
00705 {
00706 CORBA::Short native_priority = 0;
00707 int const result =
00708 this->get_thread_CORBA_and_native_priority (priority,
00709 native_priority
00710 ACE_ENV_ARG_PARAMETER);
00711 ACE_CHECK_RETURN (-1);
00712
00713 if (result == -1)
00714 {
00715 return result;
00716 }
00717
00718 return 0;
00719 }
00720
00721 int
00722 TAO_RT_Protocols_Hooks::get_thread_native_priority (
00723 CORBA::Short &native_priority
00724 ACE_ENV_ARG_DECL_NOT_USED
00725 )
00726 {
00727 ACE_hthread_t current;
00728 ACE_Thread::self (current);
00729
00730 int priority;
00731
00732 if (ACE_Thread::getprio (current, priority) == -1)
00733 {
00734 ACE_DEBUG ((LM_DEBUG,
00735 ACE_TEXT ("TAO (%P|%t) - ")
00736 ACE_TEXT ("RT_Protocols_Hooks::get_thread_priority: ")
00737 ACE_TEXT (" ACE_Thread::get_prio\n")));
00738
00739 return -1;
00740 }
00741
00742 native_priority = CORBA::Short (priority);
00743 return 0;
00744 }
00745
00746 int
00747 TAO_RT_Protocols_Hooks::get_thread_CORBA_and_native_priority (
00748 CORBA::Short &priority,
00749 CORBA::Short &native_priority
00750 ACE_ENV_ARG_DECL
00751 )
00752 {
00753 int result =
00754 this->get_thread_native_priority (native_priority
00755 ACE_ENV_ARG_PARAMETER);
00756 ACE_CHECK_RETURN (-1);
00757
00758 if (result == -1)
00759 {
00760 return result;
00761 }
00762
00763 TAO_Priority_Mapping *priority_mapping =
00764 this->mapping_manager_.in ()->mapping ();
00765
00766 if (priority_mapping->to_CORBA (native_priority, priority) == 0)
00767 {
00768 ACE_DEBUG ((LM_DEBUG,
00769 ACE_TEXT ("TAO (%P|%t) - ")
00770 ACE_TEXT ("RT_Protocols_Hooks::get_thread_priority: ")
00771 ACE_TEXT ("Priority_Mapping::to_CORBA\n")));
00772 return -1;
00773 }
00774
00775 return 0;
00776 }
00777
00778 int
00779 TAO_RT_Protocols_Hooks::set_thread_CORBA_priority (CORBA::Short priority
00780 ACE_ENV_ARG_DECL)
00781 {
00782 TAO_Priority_Mapping *priority_mapping =
00783 this->mapping_manager_.in ()->mapping ();
00784
00785 CORBA::Short native_priority;
00786
00787 if (priority_mapping->to_native (priority, native_priority) == 0)
00788 {
00789 return -1;
00790 }
00791
00792 return this->set_thread_native_priority (native_priority
00793 ACE_ENV_ARG_PARAMETER);
00794 }
00795
00796 int
00797 TAO_RT_Protocols_Hooks::set_thread_native_priority (
00798 CORBA::Short native_priority
00799 ACE_ENV_ARG_DECL_NOT_USED
00800 )
00801 {
00802 ACE_hthread_t current;
00803 ACE_Thread::self (current);
00804
00805 if (ACE_Thread::setprio (current, native_priority) == -1)
00806 {
00807 ACE_ERROR_RETURN ((LM_ERROR,
00808 ACE_TEXT ("(%N,%l) Error setting thread ")
00809 ACE_TEXT ("priority to %d, errno %d %m\n"),
00810 native_priority,
00811 errno ),
00812 -1);
00813 }
00814
00815 return 0;
00816 }
00817
00818 TAO_END_VERSIONED_NAMESPACE_DECL
00819
00820 ACE_STATIC_SVC_DEFINE (TAO_RT_Protocols_Hooks,
00821 ACE_TEXT ("RT_Protocols_Hooks"),
00822 ACE_SVC_OBJ_T,
00823 &ACE_SVC_NAME (TAO_RT_Protocols_Hooks),
00824 ACE_Service_Type::DELETE_THIS
00825 | ACE_Service_Type::DELETE_OBJ,
00826 0)
00827 ACE_FACTORY_DEFINE (TAO_RTCORBA, TAO_RT_Protocols_Hooks)
00828
00829 #endif