Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / tao / RTCORBA / RT_ORBInitializer.cpp
blob6e1c7c1f07415318ece48fb781cd1f2b0d20b52f
1 #include "tao/RTCORBA/RT_ORBInitializer.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #define TAO_RTCORBA_SAFE_INCLUDE
6 #include "tao/RTCORBA/RTCORBAC.h"
7 #undef TAO_RTCORBA_SAFE_INCLUDE
9 #include "tao/RTCORBA/RT_Policy_i.h"
10 #include "tao/RTCORBA/RT_PolicyFactory.h"
11 #include "tao/RTCORBA/RT_Protocols_Hooks.h"
12 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
13 #include "tao/RTCORBA/Network_Priority_Mapping_Manager.h"
14 #include "tao/RTCORBA/RT_ORB_Loader.h"
15 #include "tao/RTCORBA/RT_Stub_Factory.h"
16 #include "tao/RTCORBA/RT_Endpoint_Selector_Factory.h"
17 #include "tao/RTCORBA/Continuous_Priority_Mapping.h"
18 #include "tao/RTCORBA/Linear_Priority_Mapping.h"
19 #include "tao/RTCORBA/Direct_Priority_Mapping.h"
20 #include "tao/RTCORBA/Linear_Network_Priority_Mapping.h"
21 #include "tao/RTCORBA/RT_ORB.h"
22 #include "tao/RTCORBA/RT_Current.h"
23 #include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h"
24 #include "tao/RTCORBA/RT_Service_Context_Handler.h"
26 #include "tao/Exception.h"
27 #include "tao/ORB_Core.h"
28 #include "tao/PI/ORBInitInfo.h"
29 #include "tao/debug.h"
31 #include "ace/Service_Repository.h"
32 #include "ace/Svc_Conf.h"
33 #include "ace/Sched_Params.h"
35 static const char rt_poa_factory_name[] = "TAO_RT_Object_Adapter_Factory";
36 static const ACE_TCHAR rt_poa_factory_directive[] =
37 ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE(
38 "TAO_RT_Object_Adapter_Factory",
39 "TAO_RTPortableServer",
40 TAO_VERSION,
41 "_make_TAO_RT_Object_Adapter_Factory",
42 "");
44 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
46 TAO_RT_ORBInitializer::TAO_RT_ORBInitializer (int priority_mapping_type,
47 int network_priority_mapping_type,
48 int ace_sched_policy,
49 long sched_policy,
50 long scope_policy,
51 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
52 ACE_Time_Value const &dynamic_thread_time)
53 : priority_mapping_type_ (priority_mapping_type),
54 network_priority_mapping_type_ (network_priority_mapping_type),
55 ace_sched_policy_ (ace_sched_policy),
56 sched_policy_ (sched_policy),
57 scope_policy_ (scope_policy),
58 lifespan_ (lifespan),
59 dynamic_thread_time_ (dynamic_thread_time)
63 void
64 TAO_RT_ORBInitializer::pre_init (PortableInterceptor::ORBInitInfo_ptr info)
67 // Register all of the RT related services.
70 // Narrow to a TAO_ORBInitInfo object to get access to the
71 // orb_core() TAO extension.
72 TAO_ORBInitInfo_var tao_info = TAO_ORBInitInfo::_narrow (info);
74 if (CORBA::is_nil (tao_info.in ()))
76 if (TAO_debug_level > 0)
77 TAOLIB_ERROR ((LM_ERROR,
78 "(%P|%t) TAO_RT_ORBInitializer::pre_init:\n"
79 "(%P|%t) Unable to narrow "
80 "\"PortableInterceptor::ORBInitInfo_ptr\" to\n"
81 "(%P|%t) \"TAO_ORBInitInfo *.\"\n"));
83 throw ::CORBA::INTERNAL ();
86 // Bind the service context handler for RTCORBA
87 TAO_RT_Service_Context_Handler* h = 0;
88 ACE_NEW (h,
89 TAO_RT_Service_Context_Handler());
90 tao_info->orb_core ()->service_context_registry ().bind (IOP::RTCorbaPriority, h);
92 // Set the name of the Protocol_Hooks to be RT_Protocols_Hooks.
93 tao_info->orb_core ()->orb_params ()->protocols_hooks_name ("RT_Protocols_Hooks");
94 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Protocols_Hooks);
96 // Set the name of the stub factory to be RT_Stub_Factory.
97 tao_info->orb_core ()->orb_params ()->stub_factory_name ("RT_Stub_Factory");
98 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Stub_Factory);
100 // Set the name of the endpoint selector factory to be RT_Endpoint_Selector_Factory.
101 tao_info->orb_core ()->orb_params ()->endpoint_selector_factory_name ("RT_Endpoint_Selector_Factory");
102 ACE_Service_Config::process_directive (ace_svc_desc_RT_Endpoint_Selector_Factory);
104 // Set the name of the thread lane resources manager to be RT_Thread_Lane_Resources_Manager.
105 tao_info->orb_core ()->orb_params ()->thread_lane_resources_manager_factory_name ("RT_Thread_Lane_Resources_Manager_Factory");
106 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Thread_Lane_Resources_Manager_Factory);
108 // If the application resolves the root POA, make sure we load the RT POA.
109 tao_info->orb_core ()->orb_params ()->poa_factory_name (rt_poa_factory_name);
110 tao_info->orb_core ()->orb_params ()->poa_factory_directive (rt_poa_factory_directive);
112 // Create the initial priority mapping instance.
113 TAO_Priority_Mapping *pm = 0;
114 switch (this->priority_mapping_type_)
116 case TAO_PRIORITY_MAPPING_CONTINUOUS:
117 ACE_NEW (pm,
118 TAO_Continuous_Priority_Mapping (this->ace_sched_policy_));
119 break;
120 case TAO_PRIORITY_MAPPING_LINEAR:
121 ACE_NEW (pm,
122 TAO_Linear_Priority_Mapping (this->ace_sched_policy_));
123 break;
124 default:
125 case TAO_PRIORITY_MAPPING_DIRECT:
126 ACE_NEW (pm,
127 TAO_Direct_Priority_Mapping (this->ace_sched_policy_));
128 break;
131 // Set the Priority_Mapping_Manager
132 TAO_Priority_Mapping_Manager *manager = 0;
134 ACE_NEW_THROW_EX (manager,
135 TAO_Priority_Mapping_Manager (pm),
136 CORBA::NO_MEMORY (
137 CORBA::SystemException::_tao_minor_code (
138 TAO::VMCID,
139 ENOMEM),
140 CORBA::COMPLETED_NO));
142 TAO_Priority_Mapping_Manager_var safe_manager = manager;
144 info->register_initial_reference ("PriorityMappingManager", manager);
146 // Create the initial priority mapping instance.
147 TAO_Network_Priority_Mapping *npm = 0;
148 switch (this->network_priority_mapping_type_)
150 default:
151 case TAO_NETWORK_PRIORITY_MAPPING_LINEAR:
152 ACE_NEW (npm,
153 TAO_Linear_Network_Priority_Mapping (this->ace_sched_policy_));
154 break;
157 // Set the Priority_Mapping_Manager
158 TAO_Network_Priority_Mapping_Manager * network_manager = 0;
160 // @@ There is a potential memory leak here. If the new() below
161 // throws an exception, the memory for the network priority
162 // mapping allocated above will be leaked. Use an auto_ptr<> or
163 // the appropriate memory management tool.
165 ACE_NEW_THROW_EX (network_manager,
166 TAO_Network_Priority_Mapping_Manager (npm),
167 CORBA::NO_MEMORY (
168 CORBA::SystemException::_tao_minor_code (
169 TAO::VMCID,
170 ENOMEM),
171 CORBA::COMPLETED_NO));
173 TAO_Network_Priority_Mapping_Manager_var safe_network_manager =
174 network_manager;
176 info->register_initial_reference ("NetworkPriorityMappingManager",
177 network_manager);
179 // Create the RT_ORB.
180 CORBA::Object_ptr rt_orb = CORBA::Object::_nil ();
181 ACE_NEW_THROW_EX (rt_orb,
182 TAO_RT_ORB (tao_info->orb_core (),
183 lifespan_,
184 dynamic_thread_time_),
185 CORBA::NO_MEMORY (
186 CORBA::SystemException::_tao_minor_code (
187 TAO::VMCID,
188 ENOMEM),
189 CORBA::COMPLETED_NO));
190 CORBA::Object_var safe_rt_orb = rt_orb;
192 info->register_initial_reference (TAO_OBJID_RTORB, rt_orb);
194 // Create the RT_Current.
195 CORBA::Object_ptr current = CORBA::Object::_nil ();
196 ACE_NEW_THROW_EX (current,
197 TAO_RT_Current (tao_info->orb_core ()),
198 CORBA::NO_MEMORY (
199 CORBA::SystemException::_tao_minor_code (
200 TAO::VMCID,
201 ENOMEM),
202 CORBA::COMPLETED_NO));
203 CORBA::Object_var safe_rt_current = current;
205 info->register_initial_reference (TAO_OBJID_RTCURRENT, current);
207 tao_info->orb_core ()->orb_params ()->scope_policy (this->scope_policy_);
208 tao_info->orb_core ()->orb_params ()->sched_policy (this->sched_policy_);
209 tao_info->orb_core ()->orb_params ()->ace_sched_policy (this->ace_sched_policy_);
212 void
213 TAO_RT_ORBInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
215 this->register_policy_factories (info);
218 void
219 TAO_RT_ORBInitializer::register_policy_factories (
220 PortableInterceptor::ORBInitInfo_ptr info)
222 // The RTCorba policy factory is stateless and reentrant, so share a
223 // single instance between all ORBs.
224 if (CORBA::is_nil (this->policy_factory_.in ()))
226 PortableInterceptor::PolicyFactory_ptr policy_factory;
227 ACE_NEW_THROW_EX (policy_factory,
228 TAO_RT_PolicyFactory,
229 CORBA::NO_MEMORY (
230 CORBA::SystemException::_tao_minor_code (
231 TAO::VMCID,
232 ENOMEM),
233 CORBA::COMPLETED_NO));
235 this->policy_factory_ = policy_factory;
238 // Bind the same policy factory to all RTCORBA related policy
239 // types since a single policy factory is used to create each of
240 // the different types of RTCORBA policies.
241 static CORBA::PolicyType const type[] = {
242 RTCORBA::PRIORITY_MODEL_POLICY_TYPE,
243 RTCORBA::THREADPOOL_POLICY_TYPE,
244 RTCORBA::SERVER_PROTOCOL_POLICY_TYPE,
245 RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE,
246 RTCORBA::PRIVATE_CONNECTION_POLICY_TYPE,
247 RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE
250 const CORBA::PolicyType *end =
251 type + sizeof (type) / sizeof (type[0]);
253 for (CORBA::PolicyType const * i = type;
254 i != end;
255 ++i)
259 info->register_policy_factory (*i, this->policy_factory_.in ());
261 catch (const ::CORBA::BAD_INV_ORDER& ex)
263 if (ex.minor () == (CORBA::OMGVMCID | 16))
265 // The factory is already there, it happens because the
266 // magic initializer in PortableServer.cpp registers
267 // with the ORB multiple times. This is an indication
268 // that we should do no more work in this
269 // ORBInitializer.
270 return;
272 throw;
277 TAO_END_VERSIONED_NAMESPACE_DECL
279 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */