00001 #include "tao/RTCORBA/RT_ORBInitializer.h"
00002
00003 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00004
00005 ACE_RCSID (RTCORBA,
00006 RT_ORBInitializer,
00007 "$Id: RT_ORBInitializer.cpp 84860 2009-03-17 10:17:38Z johnnyw $")
00008
00009
00010 #define TAO_RTCORBA_SAFE_INCLUDE
00011 #include "tao/RTCORBA/RTCORBAC.h"
00012 #undef TAO_RTCORBA_SAFE_INCLUDE
00013
00014 #include "tao/RTCORBA/RT_Policy_i.h"
00015 #include "tao/RTCORBA/RT_PolicyFactory.h"
00016 #include "tao/RTCORBA/RT_Protocols_Hooks.h"
00017 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
00018 #include "tao/RTCORBA/Network_Priority_Mapping_Manager.h"
00019 #include "tao/RTCORBA/RT_ORB_Loader.h"
00020 #include "tao/RTCORBA/RT_Stub_Factory.h"
00021 #include "tao/RTCORBA/RT_Endpoint_Selector_Factory.h"
00022 #include "tao/RTCORBA/Continuous_Priority_Mapping.h"
00023 #include "tao/RTCORBA/Linear_Priority_Mapping.h"
00024 #include "tao/RTCORBA/Direct_Priority_Mapping.h"
00025 #include "tao/RTCORBA/Linear_Network_Priority_Mapping.h"
00026 #include "tao/RTCORBA/RT_ORB.h"
00027 #include "tao/RTCORBA/RT_Current.h"
00028 #include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h"
00029 #include "tao/RTCORBA/RT_Service_Context_Handler.h"
00030
00031 #include "tao/Exception.h"
00032 #include "tao/ORB_Core.h"
00033 #include "tao/PI/ORBInitInfo.h"
00034 #include "tao/debug.h"
00035
00036 #include "ace/Service_Repository.h"
00037 #include "ace/Svc_Conf.h"
00038 #include "ace/Sched_Params.h"
00039
00040 static const char rt_poa_factory_name[] = "TAO_RT_Object_Adapter_Factory";
00041 static const ACE_TCHAR rt_poa_factory_directive[] =
00042 ACE_DYNAMIC_SERVICE_DIRECTIVE(
00043 "TAO_RT_Object_Adapter_Factory",
00044 "TAO_RTPortableServer",
00045 "_make_TAO_RT_Object_Adapter_Factory",
00046 "");
00047
00048 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00049
00050 TAO_RT_ORBInitializer::TAO_RT_ORBInitializer (int priority_mapping_type,
00051 int network_priority_mapping_type,
00052 int ace_sched_policy,
00053 long sched_policy,
00054 long scope_policy,
00055 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00056 ACE_Time_Value const &dynamic_thread_time)
00057 : priority_mapping_type_ (priority_mapping_type),
00058 network_priority_mapping_type_ (network_priority_mapping_type),
00059 ace_sched_policy_ (ace_sched_policy),
00060 sched_policy_ (sched_policy),
00061 scope_policy_ (scope_policy),
00062 lifespan_ (lifespan),
00063 dynamic_thread_time_ (dynamic_thread_time)
00064 {
00065 }
00066
00067 void
00068 TAO_RT_ORBInitializer::pre_init (PortableInterceptor::ORBInitInfo_ptr info)
00069 {
00070
00071
00072
00073
00074
00075
00076 TAO_ORBInitInfo_var tao_info = TAO_ORBInitInfo::_narrow (info);
00077
00078 if (CORBA::is_nil (tao_info.in ()))
00079 {
00080 if (TAO_debug_level > 0)
00081 ACE_ERROR ((LM_ERROR,
00082 "(%P|%t) TAO_RT_ORBInitializer::pre_init:\n"
00083 "(%P|%t) Unable to narrow "
00084 "\"PortableInterceptor::ORBInitInfo_ptr\" to\n"
00085 "(%P|%t) \"TAO_ORBInitInfo *.\"\n"));
00086
00087 throw ::CORBA::INTERNAL ();
00088 }
00089
00090
00091 TAO_RT_Service_Context_Handler* h = 0;
00092 ACE_NEW (h,
00093 TAO_RT_Service_Context_Handler());
00094 tao_info->orb_core ()->service_context_registry ().bind (IOP::RTCorbaPriority, h);
00095
00096
00097 tao_info->orb_core ()->orb_params ()->protocols_hooks_name ("RT_Protocols_Hooks");
00098 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Protocols_Hooks);
00099
00100
00101 tao_info->orb_core ()->orb_params ()->stub_factory_name ("RT_Stub_Factory");
00102 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Stub_Factory);
00103
00104
00105 tao_info->orb_core ()->orb_params ()->endpoint_selector_factory_name ("RT_Endpoint_Selector_Factory");
00106 ACE_Service_Config::process_directive (ace_svc_desc_RT_Endpoint_Selector_Factory);
00107
00108
00109 tao_info->orb_core ()->orb_params ()->thread_lane_resources_manager_factory_name ("RT_Thread_Lane_Resources_Manager_Factory");
00110 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Thread_Lane_Resources_Manager_Factory);
00111
00112
00113 tao_info->orb_core ()->orb_params ()->poa_factory_name (rt_poa_factory_name);
00114 tao_info->orb_core ()->orb_params ()->poa_factory_directive (rt_poa_factory_directive);
00115
00116
00117 TAO_Priority_Mapping *pm = 0;
00118 switch (this->priority_mapping_type_)
00119 {
00120 case TAO_PRIORITY_MAPPING_CONTINUOUS:
00121 ACE_NEW (pm,
00122 TAO_Continuous_Priority_Mapping (this->ace_sched_policy_));
00123 break;
00124 case TAO_PRIORITY_MAPPING_LINEAR:
00125 ACE_NEW (pm,
00126 TAO_Linear_Priority_Mapping (this->ace_sched_policy_));
00127 break;
00128 default:
00129 case TAO_PRIORITY_MAPPING_DIRECT:
00130 ACE_NEW (pm,
00131 TAO_Direct_Priority_Mapping (this->ace_sched_policy_));
00132 break;
00133 }
00134
00135
00136 TAO_Priority_Mapping_Manager *manager = 0;
00137
00138 ACE_NEW_THROW_EX (manager,
00139 TAO_Priority_Mapping_Manager (pm),
00140 CORBA::NO_MEMORY (
00141 CORBA::SystemException::_tao_minor_code (
00142 TAO::VMCID,
00143 ENOMEM),
00144 CORBA::COMPLETED_NO));
00145
00146 TAO_Priority_Mapping_Manager_var safe_manager = manager;
00147
00148 info->register_initial_reference ("PriorityMappingManager", manager);
00149
00150
00151 TAO_Network_Priority_Mapping *npm = 0;
00152 switch (this->network_priority_mapping_type_)
00153 {
00154 default:
00155 case TAO_NETWORK_PRIORITY_MAPPING_LINEAR:
00156 ACE_NEW (npm,
00157 TAO_Linear_Network_Priority_Mapping (this->ace_sched_policy_));
00158 break;
00159 }
00160
00161
00162 TAO_Network_Priority_Mapping_Manager * network_manager = 0;
00163
00164
00165
00166
00167
00168
00169 ACE_NEW_THROW_EX (network_manager,
00170 TAO_Network_Priority_Mapping_Manager (npm),
00171 CORBA::NO_MEMORY (
00172 CORBA::SystemException::_tao_minor_code (
00173 TAO::VMCID,
00174 ENOMEM),
00175 CORBA::COMPLETED_NO));
00176
00177 TAO_Network_Priority_Mapping_Manager_var safe_network_manager =
00178 network_manager;
00179
00180 info->register_initial_reference ("NetworkPriorityMappingManager",
00181 network_manager);
00182
00183
00184 CORBA::Object_ptr rt_orb = CORBA::Object::_nil ();
00185 ACE_NEW_THROW_EX (rt_orb,
00186 TAO_RT_ORB (tao_info->orb_core (),
00187 lifespan_,
00188 dynamic_thread_time_),
00189 CORBA::NO_MEMORY (
00190 CORBA::SystemException::_tao_minor_code (
00191 TAO::VMCID,
00192 ENOMEM),
00193 CORBA::COMPLETED_NO));
00194 CORBA::Object_var safe_rt_orb = rt_orb;
00195
00196 info->register_initial_reference (TAO_OBJID_RTORB, rt_orb);
00197
00198
00199 CORBA::Object_ptr current = CORBA::Object::_nil ();
00200 ACE_NEW_THROW_EX (current,
00201 TAO_RT_Current (tao_info->orb_core ()),
00202 CORBA::NO_MEMORY (
00203 CORBA::SystemException::_tao_minor_code (
00204 TAO::VMCID,
00205 ENOMEM),
00206 CORBA::COMPLETED_NO));
00207 CORBA::Object_var safe_rt_current = current;
00208
00209 info->register_initial_reference (TAO_OBJID_RTCURRENT, current);
00210
00211 tao_info->orb_core ()->orb_params ()->scope_policy (this->scope_policy_);
00212 tao_info->orb_core ()->orb_params ()->sched_policy (this->sched_policy_);
00213 tao_info->orb_core ()->orb_params ()->ace_sched_policy (this->ace_sched_policy_);
00214 }
00215
00216 void
00217 TAO_RT_ORBInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
00218 {
00219 this->register_policy_factories (info);
00220 }
00221
00222 void
00223 TAO_RT_ORBInitializer::register_policy_factories (
00224 PortableInterceptor::ORBInitInfo_ptr info)
00225 {
00226
00227
00228 if (CORBA::is_nil (this->policy_factory_.in ()))
00229 {
00230 PortableInterceptor::PolicyFactory_ptr policy_factory;
00231 ACE_NEW_THROW_EX (policy_factory,
00232 TAO_RT_PolicyFactory,
00233 CORBA::NO_MEMORY (
00234 CORBA::SystemException::_tao_minor_code (
00235 TAO::VMCID,
00236 ENOMEM),
00237 CORBA::COMPLETED_NO));
00238
00239 this->policy_factory_ = policy_factory;
00240 }
00241
00242
00243
00244
00245 static CORBA::PolicyType const type[] = {
00246 RTCORBA::PRIORITY_MODEL_POLICY_TYPE,
00247 RTCORBA::THREADPOOL_POLICY_TYPE,
00248 RTCORBA::SERVER_PROTOCOL_POLICY_TYPE,
00249 RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE,
00250 RTCORBA::PRIVATE_CONNECTION_POLICY_TYPE,
00251 RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE
00252 };
00253
00254 const CORBA::PolicyType *end =
00255 type + sizeof (type) / sizeof (type[0]);
00256
00257 for (CORBA::PolicyType const * i = type;
00258 i != end;
00259 ++i)
00260 {
00261 try
00262 {
00263 info->register_policy_factory (*i, this->policy_factory_.in ());
00264 }
00265 catch (const ::CORBA::BAD_INV_ORDER& ex)
00266 {
00267 if (ex.minor () == (CORBA::OMGVMCID | 16))
00268 {
00269
00270
00271
00272
00273
00274 return;
00275 }
00276 throw;
00277 }
00278 }
00279 }
00280
00281 TAO_END_VERSIONED_NAMESPACE_DECL
00282
00283 #endif