Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / RTPortableServer / RT_POA.cpp
bloba15c7982a567c8a16eea8ea29de118921ff88045
1 #include "tao/RTPortableServer/RT_POA.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/RTPortableServer/RT_Acceptor_Filters.h"
7 #include "tao/ORB_Core.h"
8 #include "tao/ORB.h"
9 #include "tao/Server_Strategy_Factory.h"
10 #include "tao/Exception.h"
11 #include "tao/Stub.h"
12 #include "tao/Policy_Manager.h"
13 #include "tao/debug.h"
14 #include "tao/RTCORBA/Thread_Pool.h"
15 #include "tao/Thread_Lane_Resources.h"
16 #include "tao/Acceptor_Registry.h"
17 #include "tao/Thread_Lane_Resources.h"
18 #include "tao/Thread_Lane_Resources_Manager.h"
20 #include "tao/RTCORBA/RT_Policy_i.h"
22 #include "tao/PortableServer/Default_Acceptor_Filter.h"
23 #include "tao/RTPortableServer/RT_Policy_Validator.h"
25 #include <memory>
27 #if !defined (__ACE_INLINE__)
28 # include "tao/RTPortableServer/RT_POA.inl"
29 #endif /* ! __ACE_INLINE__ */
31 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
33 TAO_RT_POA::TAO_RT_POA (const TAO_Root_POA::String &name,
34 PortableServer::POAManager_ptr poa_manager,
35 const TAO_POA_Policy_Set &policies,
36 TAO_Root_POA *parent,
37 ACE_Lock &lock,
38 TAO_SYNCH_MUTEX &thread_lock,
39 TAO_ORB_Core &orb_core,
40 TAO_Object_Adapter *object_adapter)
41 : TAO_Regular_POA (name,
42 poa_manager,
43 policies,
44 parent,
45 lock,
46 thread_lock,
47 orb_core,
48 object_adapter)
50 // Parse the RT policies and update our policy cache.
51 this->parse_rt_policies (this->policies ());
54 TAO_Root_POA *
55 TAO_RT_POA::new_POA (const String &name,
56 PortableServer::POAManager_ptr poa_manager,
57 const TAO_POA_Policy_Set &policies,
58 TAO_Root_POA *parent,
59 ACE_Lock &lock,
60 TAO_SYNCH_MUTEX &thread_lock,
61 TAO_ORB_Core &orb_core,
62 TAO_Object_Adapter *object_adapter)
64 TAO_RT_POA *poa = 0;
66 ACE_NEW_THROW_EX (poa,
67 TAO_RT_POA (name,
68 poa_manager,
69 policies,
70 parent,
71 lock,
72 thread_lock,
73 orb_core,
74 object_adapter),
75 CORBA::NO_MEMORY ());
77 return poa;
80 void
81 TAO_RT_POA::parse_rt_policies (TAO_POA_Policy_Set &policies)
84 CORBA::Policy_var policy =
85 policies.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL);
87 RTCORBA::PriorityModelPolicy_var priority_model =
88 RTCORBA::PriorityModelPolicy::_narrow (policy.in ());
90 if (!CORBA::is_nil (priority_model.in ()))
92 RTCORBA::PriorityModel rt_priority_model =
93 priority_model->priority_model ();
95 this->cached_policies_.priority_model (
96 TAO::Portable_Server::Cached_Policies::PriorityModel (rt_priority_model));
98 RTCORBA::Priority priority =
99 priority_model->server_priority ();
101 this->cached_policies_.server_priority (priority);
105 this->thread_pool_ =
106 TAO_POA_RT_Policy_Validator::extract_thread_pool (this->orb_core_,
107 policies.policies ());
110 void
111 TAO_RT_POA::validate_priority (RTCORBA::Priority priority)
113 if (priority < RTCORBA::minPriority
114 // The line below will always be false unless the value of
115 // RTCORBA::maxPriority, which is now assigned the value of
116 // 32767, is changed in RTCORBA.pidl.
117 // || priority > RTCORBA::maxPriority
120 throw ::CORBA::BAD_PARAM ();
123 // If this POA is using a thread pool with lanes, make sure the
124 // priority matches one of the thread lanes. Note that in this
125 // case, bands do not matter since matching the lanes priority is a
126 // stricter condition than meeting the band ranges. In addition,
127 // when the POA was created, the bands had to match the lanes.
128 if (this->thread_pool_ != 0 && this->thread_pool_->with_lanes ())
130 TAO_Thread_Lane **lanes = this->thread_pool_->lanes ();
132 for (CORBA::ULong i = 0;
133 i != this->thread_pool_->number_of_lanes ();
134 ++i)
136 if (lanes[i]->lane_priority () == priority)
137 return;
140 throw ::CORBA::BAD_PARAM ();
142 else
143 // Else we are dealing with a thread pool without lanes.
145 // Check if we have bands.
146 CORBA::Policy_var bands =
147 this->policies ().get_cached_policy (
148 TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION);
150 RTCORBA::PriorityBandedConnectionPolicy_var priority_bands
151 = RTCORBA::PriorityBandedConnectionPolicy::_narrow (bands.in ());
153 TAO_PriorityBandedConnectionPolicy *priority_bands_i =
154 dynamic_cast <TAO_PriorityBandedConnectionPolicy *>
155 (priority_bands.in ());
157 if (priority_bands_i)
159 // If we do have bands, make sure that the priority is
160 // matching one of the bands.
161 RTCORBA::PriorityBands &bands =
162 priority_bands_i->priority_bands_rep ();
164 for (CORBA::ULong i = 0;
165 i < bands.length ();
166 ++i)
168 if (bands[i].low <= priority &&
169 bands[i].high >= priority)
170 return;
173 throw ::CORBA::BAD_PARAM ();
178 void
179 TAO_RT_POA::validate_policies ()
181 // For each of the above operations, if the POA supports the
182 // IMPLICIT_ACTIVATION option for the ImplicitActivationPolicy then
183 // the ORB shall raise a WrongPolicy user exception. This relieves
184 // an ORB implementation of the need to retrieve the target object's
185 // priority from "somewhere" when a request arrives for an inactive
186 // object.
187 if (this->cached_policies_.implicit_activation () ==
188 PortableServer::IMPLICIT_ACTIVATION)
190 throw PortableServer::POA::WrongPolicy ();
193 // For each of the above operations, if the POA does not support the
194 // SERVER_DECLARED option for the PriorityModelPolicy then the ORB
195 // shall raise a WrongPolicy user exception.
196 if (this->cached_policies_.priority_model () !=
197 TAO::Portable_Server::Cached_Policies::SERVER_DECLARED)
199 throw PortableServer::POA::WrongPolicy ();
202 // In all other respects the semantics of the corresponding
203 // (i.e. without the name extensions "_with_priority" and
204 // "_and_priority") PortableServer::POA operations shall be
205 // observed.
208 TAO_Stub *
209 TAO_RT_POA::key_to_stub_i (const TAO::ObjectKey &object_key,
210 const char *type_id,
211 CORBA::Short priority)
213 // Client exposed policies.
214 CORBA::PolicyList_var client_exposed_policies =
215 this->client_exposed_policies (priority);
217 // Server protocol policy.
218 CORBA::Policy_var protocol =
219 this->policies ().get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL);
221 RTCORBA::ServerProtocolPolicy_var server_protocol_policy =
222 RTCORBA::ServerProtocolPolicy::_narrow (protocol.in ());
224 TAO_ServerProtocolPolicy *server_protocol =
225 dynamic_cast <TAO_ServerProtocolPolicy *> (server_protocol_policy.in ());
227 // Filter for server protocol.
228 TAO_Server_Protocol_Acceptor_Filter filter (server_protocol->protocols_rep ());
230 // If this POA is using the default thread pool or a thread pool
231 // without lanes, create the IOR with the acceptors in the thread
232 // pool.
233 if (this->thread_pool_ == 0 ||
234 !this->thread_pool_->with_lanes ())
236 TAO_Acceptor_Registry *acceptor_registry = 0;
238 if (this->thread_pool_ == 0)
240 TAO_Thread_Lane_Resources_Manager &thread_lane_resources_manager =
241 this->orb_core_.thread_lane_resources_manager ();
243 TAO_Thread_Lane_Resources &resources =
244 thread_lane_resources_manager.default_lane_resources ();
246 acceptor_registry = &resources.acceptor_registry ();
248 else
250 TAO_Thread_Lane **lanes = this->thread_pool_->lanes ();
252 TAO_Thread_Lane_Resources &resources = lanes[0]->resources ();
254 acceptor_registry = &resources.acceptor_registry ();
257 return
258 this->TAO_Regular_POA::create_stub_object (object_key,
259 type_id,
260 client_exposed_policies._retn (),
261 &filter,
262 *acceptor_registry);
265 // If this POA has the SERVER_DECLARED policy, create the IOR with
266 // the acceptors in the only thread lane that matches the priority
267 // of the object.
268 if (this->cached_policies_.priority_model () ==
269 TAO::Portable_Server::Cached_Policies::SERVER_DECLARED)
271 TAO_Thread_Lane **lanes =
272 this->thread_pool_->lanes ();
274 for (CORBA::ULong i = 0;
275 i != this->thread_pool_->number_of_lanes ();
276 ++i)
278 if (lanes[i]->lane_priority () == priority)
279 return this->TAO_Regular_POA::create_stub_object (object_key,
280 type_id,
281 client_exposed_policies._retn (),
282 &filter,
283 lanes[i]->resources ().acceptor_registry ());
286 ACE_ASSERT (0);
289 // If this POA has the CLIENT_PROPAGATED policy, create the IOR with
290 // the acceptors in the thread lanes that matches the bands in this
291 // POA. If there are no bands, all the thread lanes are used.
292 CORBA::Policy_var bands =
293 this->policies ().get_cached_policy (
294 TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION);
296 RTCORBA::PriorityBandedConnectionPolicy_var priority_bands
297 = RTCORBA::PriorityBandedConnectionPolicy::_narrow (bands.in ());
299 TAO_PriorityBandedConnectionPolicy *priority_bands_i =
300 dynamic_cast <TAO_PriorityBandedConnectionPolicy *> (priority_bands.in ());
302 return this->create_stub_object (object_key,
303 type_id,
304 client_exposed_policies._retn (),
305 &filter,
306 priority_bands_i);
309 TAO_Stub *
310 TAO_RT_POA::create_stub_object (const TAO::ObjectKey &object_key,
311 const char *type_id,
312 CORBA::PolicyList *policy_list,
313 TAO_Acceptor_Filter *filter,
314 TAO_PriorityBandedConnectionPolicy *priority_bands)
316 bool error = false;
318 // Count the number of endpoints.
319 size_t const profile_count = this->endpoint_count ();
321 // Create a profile container and have acceptor registries populate
322 // it with profiles as appropriate.
323 TAO_MProfile mprofile (0);
325 // Allocate space for storing the profiles. There can never be more
326 // profiles than there are endpoints. In some cases, there can be
327 // less profiles than endpoints.
328 int result =
329 mprofile.set (static_cast <CORBA::ULong> (profile_count));
330 if (result == -1)
331 error = true;
333 TAO_Thread_Lane **lanes =
334 this->thread_pool_->lanes ();
336 // Leave it to the filter to decide which acceptors/in which order
337 // go into the mprofile.
338 for (CORBA::ULong i = 0;
339 i != this->thread_pool_->number_of_lanes () &&
340 !error;
341 ++i)
343 if (this->lane_required (lanes[i],
344 priority_bands))
346 TAO_Acceptor_Registry &acceptor_registry =
347 lanes[i]->resources ().acceptor_registry ();
349 result =
350 filter->fill_profile (object_key,
351 mprofile,
352 acceptor_registry.begin (),
353 acceptor_registry.end (),
354 lanes[i]->lane_priority ());
355 if (result == -1)
356 error = true;
360 if (!error)
361 result = filter->encode_endpoints (mprofile);
362 if (result == -1)
363 error = 1;
365 if (error)
366 throw ::CORBA::INTERNAL (
367 CORBA::SystemException::_tao_minor_code (
368 TAO_MPROFILE_CREATION_ERROR,
370 CORBA::COMPLETED_NO);
372 // Make sure we have at least one profile. <mp> may end up being
373 // empty if none of the acceptor endpoints have the right priority
374 // for this object, for example.
375 if (mprofile.profile_count () == 0)
376 throw ::CORBA::BAD_PARAM (
377 CORBA::SystemException::_tao_minor_code (
378 TAO_MPROFILE_CREATION_ERROR,
380 CORBA::COMPLETED_NO);
382 return
383 this->orb_core_.create_stub_object (mprofile, type_id, policy_list);
386 size_t
387 TAO_RT_POA::endpoint_count ()
389 size_t profile_count = 0;
391 TAO_Thread_Lane **lanes =
392 this->thread_pool_->lanes ();
394 for (CORBA::ULong i = 0;
395 i != this->thread_pool_->number_of_lanes ();
396 ++i)
397 profile_count +=
398 lanes[i]->resources ().acceptor_registry ().endpoint_count ();
400 return profile_count;
404 TAO_RT_POA::lane_required (TAO_Thread_Lane *lane,
405 TAO_PriorityBandedConnectionPolicy *priority_bands)
407 if (priority_bands == 0)
408 return 1;
410 RTCORBA::PriorityBands &bands =
411 priority_bands->priority_bands_rep ();
413 for (CORBA::ULong i = 0;
414 i < bands.length ();
415 ++i)
417 if (bands[i].low <= lane->lane_priority () &&
418 bands[i].high >= lane->lane_priority ())
419 return 1;
422 return 0;
425 CORBA::PolicyList *
426 TAO_RT_POA::client_exposed_policies (CORBA::Short object_priority)
428 CORBA::PolicyList *client_exposed_policies = 0;
429 ACE_NEW_THROW_EX (client_exposed_policies,
430 CORBA::PolicyList (),
431 CORBA::NO_MEMORY (TAO::VMCID,
432 CORBA::COMPLETED_NO));
434 CORBA::PolicyList_var safe_client_exposed_policies = client_exposed_policies;
436 // Add in all of the client exposed policies.
437 this->policies_.add_client_exposed_fixed_policies (client_exposed_policies);
439 // Check if the priority model policy has been set, and if so, let
440 // the client know about it.
441 CORBA::Short poa_priority =
442 this->cached_policies_.server_priority ();
444 if (poa_priority != TAO_INVALID_PRIORITY)
446 TAO::Portable_Server::Cached_Policies::PriorityModel priority_model =
447 this->cached_policies_.priority_model ();
449 // If the priority model is client propagated, let the client
450 // about the default server priority (the POA priority). If
451 // the priority model is server declared, tell the client the
452 // servant's priority.
453 CORBA::Short priority;
454 if (priority_model == TAO::Portable_Server::Cached_Policies::CLIENT_PROPAGATED)
455 priority = poa_priority;
456 else
457 priority = object_priority;
459 const CORBA::ULong current_length =
460 client_exposed_policies->length ();
461 client_exposed_policies->length (current_length + 1);
463 TAO_PriorityModelPolicy *priority_model_policy;
464 ACE_NEW_THROW_EX (priority_model_policy,
465 TAO_PriorityModelPolicy (RTCORBA::PriorityModel (priority_model),
466 priority),
467 CORBA::NO_MEMORY (TAO::VMCID,
468 CORBA::COMPLETED_NO));
470 (*client_exposed_policies)[current_length] = priority_model_policy;
473 return safe_client_exposed_policies._retn ();
477 // Standard POA interfaces
478 PortableServer::POA_ptr
479 TAO_RT_POA::create_POA (const char *adapter_name,
480 PortableServer::POAManager_ptr poa_manager,
481 const CORBA::PolicyList &policies)
483 return this->TAO_Regular_POA::create_POA (adapter_name, poa_manager, policies);
486 PortableServer::POA_ptr
487 TAO_RT_POA::find_POA (const char *adapter_name, CORBA::Boolean activate_it)
489 return this->TAO_Regular_POA::find_POA (adapter_name, activate_it);
492 void
493 TAO_RT_POA::destroy (CORBA::Boolean etherealize_objects,
494 CORBA::Boolean wait_for_completion)
496 this->TAO_Regular_POA::destroy (etherealize_objects, wait_for_completion);
500 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
502 PortableServer::ThreadPolicy_ptr
503 TAO_RT_POA::create_thread_policy (PortableServer::ThreadPolicyValue value)
505 return this->TAO_Regular_POA::create_thread_policy (value);
508 #endif /* TAO_HAS_MINIMUM_POA == 0 */
510 #if !defined (CORBA_E_MICRO)
511 PortableServer::LifespanPolicy_ptr
512 TAO_RT_POA::create_lifespan_policy (PortableServer::LifespanPolicyValue value)
514 return this->TAO_Regular_POA::create_lifespan_policy (value);
516 #endif
518 #if !defined (CORBA_E_MICRO)
519 PortableServer::IdUniquenessPolicy_ptr
520 TAO_RT_POA::create_id_uniqueness_policy (PortableServer::IdUniquenessPolicyValue value)
522 return this->TAO_Regular_POA::create_id_uniqueness_policy (value);
524 #endif
526 #if !defined (CORBA_E_MICRO)
527 PortableServer::IdAssignmentPolicy_ptr
528 TAO_RT_POA::create_id_assignment_policy (PortableServer::IdAssignmentPolicyValue value)
530 return this->TAO_Regular_POA::create_id_assignment_policy (value);
532 #endif
534 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
536 PortableServer::ImplicitActivationPolicy_ptr
537 TAO_RT_POA::create_implicit_activation_policy (
538 PortableServer::ImplicitActivationPolicyValue value)
540 return this->TAO_Regular_POA::create_implicit_activation_policy (value);
543 PortableServer::ServantRetentionPolicy_ptr
544 TAO_RT_POA::create_servant_retention_policy (
545 PortableServer::ServantRetentionPolicyValue value)
547 return this->TAO_Regular_POA::create_servant_retention_policy (value);
551 PortableServer::RequestProcessingPolicy_ptr
552 TAO_RT_POA::create_request_processing_policy (
553 PortableServer::RequestProcessingPolicyValue value)
555 return this->TAO_Regular_POA::create_request_processing_policy (value);
558 #endif /* TAO_HAS_MINIMUM_POA == 0 && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO) */
560 char *
561 TAO_RT_POA::the_name ()
563 return this->TAO_Regular_POA::the_name ();
566 PortableServer::POA_ptr
567 TAO_RT_POA::the_parent ()
569 return this->TAO_Regular_POA::the_parent ();
572 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
573 PortableServer::POAList *
574 TAO_RT_POA::the_children ()
576 return this->TAO_Regular_POA::the_children ();
578 #endif /* TAO_HAS_MINIMUM_POA == 0 */
580 PortableServer::POAManager_ptr
581 TAO_RT_POA::the_POAManager ()
583 return this->TAO_Regular_POA::the_POAManager ();
586 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
587 PortableServer::AdapterActivator_ptr
588 TAO_RT_POA::the_activator ()
590 return this->TAO_Regular_POA::the_activator ();
593 void
594 TAO_RT_POA::the_activator (PortableServer::AdapterActivator_ptr adapter_activator)
596 this->TAO_Regular_POA::the_activator (adapter_activator);
599 PortableServer::ServantManager_ptr
600 TAO_RT_POA::get_servant_manager ()
602 return this->TAO_Regular_POA::get_servant_manager ();
605 void
606 TAO_RT_POA::set_servant_manager (PortableServer::ServantManager_ptr imgr)
608 this->TAO_Regular_POA::set_servant_manager (imgr);
611 PortableServer::Servant
612 TAO_RT_POA::get_servant ()
614 return this->TAO_Regular_POA::get_servant ();
617 void
618 TAO_RT_POA::set_servant (PortableServer::Servant servant)
620 this->TAO_Regular_POA::set_servant (servant);
623 #endif /* TAO_HAS_MINIMUM_POA == 0 */
625 PortableServer::ObjectId *
626 TAO_RT_POA::activate_object (PortableServer::Servant p_servant)
628 return this->TAO_Regular_POA::activate_object (p_servant);
631 #if !defined (CORBA_E_MICRO)
632 void
633 TAO_RT_POA::activate_object_with_id (const PortableServer::ObjectId &id,
634 PortableServer::Servant p_servant)
636 this->TAO_Regular_POA::activate_object_with_id (id, p_servant);
638 #endif
640 void
641 TAO_RT_POA::deactivate_object (const PortableServer::ObjectId &oid)
643 this->TAO_Regular_POA::deactivate_object (oid);
646 CORBA::Object_ptr
647 TAO_RT_POA::create_reference (const char *intf)
649 return this->TAO_Regular_POA::create_reference (intf);
652 #if !defined (CORBA_E_MICRO)
653 CORBA::Object_ptr
654 TAO_RT_POA::create_reference_with_id (const PortableServer::ObjectId &oid,
655 const char *intf)
657 return this->TAO_Regular_POA::create_reference_with_id (oid, intf);
659 #endif
661 PortableServer::ObjectId *
662 TAO_RT_POA::servant_to_id (PortableServer::Servant p_servant)
664 return this->TAO_Regular_POA::servant_to_id (p_servant);
667 CORBA::Object_ptr
668 TAO_RT_POA::servant_to_reference (PortableServer::Servant p_servant)
670 return this->TAO_Regular_POA::servant_to_reference (p_servant);
673 PortableServer::Servant
674 TAO_RT_POA::reference_to_servant (CORBA::Object_ptr reference)
676 return this->TAO_Regular_POA::reference_to_servant (reference);
679 PortableServer::ObjectId *
680 TAO_RT_POA::reference_to_id (CORBA::Object_ptr reference)
682 return this->TAO_Regular_POA::reference_to_id (reference);
685 PortableServer::Servant
686 TAO_RT_POA::id_to_servant (const PortableServer::ObjectId &oid)
688 return this->TAO_Regular_POA::id_to_servant (oid);
691 CORBA::Object_ptr
692 TAO_RT_POA::id_to_reference (const PortableServer::ObjectId &oid)
694 return this->TAO_Regular_POA::id_to_reference (oid);
697 CORBA::OctetSeq *
698 TAO_RT_POA::id ()
700 return this->TAO_Regular_POA::id ();
703 TAO_END_VERSIONED_NAMESPACE_DECL
705 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */