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 "RT_ORBInitializer.cpp,v 1.27 2006/03/10 07:19:16 jtc Exp")
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
00030 #include "tao/Exception.h"
00031 #include "tao/ORB_Core.h"
00032 #include "tao/PI/ORBInitInfo.h"
00033 #include "tao/debug.h"
00034
00035 #include "ace/Service_Repository.h"
00036 #include "ace/Svc_Conf.h"
00037 #include "ace/Sched_Params.h"
00038
00039 static const char rt_poa_factory_name[] = "TAO_RT_Object_Adapter_Factory";
00040 static const ACE_TCHAR rt_poa_factory_directive[] =
00041 ACE_DYNAMIC_SERVICE_DIRECTIVE(
00042 "TAO_RT_Object_Adapter_Factory",
00043 "TAO_RTPortableServer",
00044 "_make_TAO_RT_Object_Adapter_Factory",
00045 "");
00046
00047 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00048
00049 TAO_RT_ORBInitializer::TAO_RT_ORBInitializer (int priority_mapping_type,
00050 int network_priority_mapping_type,
00051 int ace_sched_policy,
00052 long sched_policy,
00053 long scope_policy,
00054 ACE_Time_Value const &dynamic_thread_idle_timeout)
00055 : priority_mapping_type_ (priority_mapping_type),
00056 network_priority_mapping_type_ (network_priority_mapping_type),
00057 ace_sched_policy_ (ace_sched_policy),
00058 sched_policy_ (sched_policy),
00059 scope_policy_ (scope_policy),
00060 dynamic_thread_idle_timeout_ (dynamic_thread_idle_timeout)
00061 {
00062 }
00063
00064 void
00065 TAO_RT_ORBInitializer::pre_init (
00066 PortableInterceptor::ORBInitInfo_ptr info
00067 ACE_ENV_ARG_DECL)
00068 ACE_THROW_SPEC ((CORBA::SystemException))
00069 {
00070
00071
00072
00073
00074
00075 TAO_ORB_Core::set_protocols_hooks ("RT_Protocols_Hooks");
00076 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Protocols_Hooks);
00077
00078
00079 TAO_ORB_Core::set_stub_factory ("RT_Stub_Factory");
00080 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Stub_Factory);
00081
00082
00083 TAO_ORB_Core::set_endpoint_selector_factory ("RT_Endpoint_Selector_Factory");
00084 ACE_Service_Config::process_directive (ace_svc_desc_RT_Endpoint_Selector_Factory);
00085
00086
00087 TAO_ORB_Core::set_thread_lane_resources_manager_factory ("RT_Thread_Lane_Resources_Manager_Factory");
00088 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Thread_Lane_Resources_Manager_Factory);
00089
00090
00091 TAO_ORB_Core::set_poa_factory (rt_poa_factory_name,
00092 ACE_TEXT_ALWAYS_CHAR (rt_poa_factory_directive));
00093
00094
00095 TAO_Priority_Mapping *pm = 0;
00096 switch (this->priority_mapping_type_)
00097 {
00098 case TAO_PRIORITY_MAPPING_CONTINUOUS:
00099 ACE_NEW (pm,
00100 TAO_Continuous_Priority_Mapping (this->ace_sched_policy_));
00101 break;
00102 case TAO_PRIORITY_MAPPING_LINEAR:
00103 ACE_NEW (pm,
00104 TAO_Linear_Priority_Mapping (this->ace_sched_policy_));
00105 break;
00106 default:
00107 case TAO_PRIORITY_MAPPING_DIRECT:
00108 ACE_NEW (pm,
00109 TAO_Direct_Priority_Mapping (this->ace_sched_policy_));
00110 break;
00111 }
00112
00113
00114 TAO_Priority_Mapping_Manager *manager = 0;
00115
00116 ACE_NEW_THROW_EX (manager,
00117 TAO_Priority_Mapping_Manager (pm),
00118 CORBA::NO_MEMORY (
00119 CORBA::SystemException::_tao_minor_code (
00120 TAO::VMCID,
00121 ENOMEM),
00122 CORBA::COMPLETED_NO));
00123 ACE_CHECK;
00124
00125 TAO_Priority_Mapping_Manager_var safe_manager = manager;
00126
00127 info->register_initial_reference ("PriorityMappingManager",
00128 manager
00129 ACE_ENV_ARG_PARAMETER);
00130 ACE_CHECK;
00131
00132
00133 TAO_Network_Priority_Mapping *npm = 0;
00134 switch (this->network_priority_mapping_type_)
00135 {
00136 default:
00137 case TAO_NETWORK_PRIORITY_MAPPING_LINEAR:
00138 ACE_NEW (npm,
00139 TAO_Linear_Network_Priority_Mapping (this->ace_sched_policy_));
00140 break;
00141 }
00142
00143
00144 TAO_Network_Priority_Mapping_Manager * network_manager = 0;
00145
00146
00147
00148
00149
00150
00151 ACE_NEW_THROW_EX (network_manager,
00152 TAO_Network_Priority_Mapping_Manager (npm),
00153 CORBA::NO_MEMORY (
00154 CORBA::SystemException::_tao_minor_code (
00155 TAO::VMCID,
00156 ENOMEM),
00157 CORBA::COMPLETED_NO));
00158 ACE_CHECK;
00159
00160 TAO_Network_Priority_Mapping_Manager_var safe_network_manager =
00161 network_manager;
00162
00163 info->register_initial_reference ("NetworkPriorityMappingManager",
00164 network_manager
00165 ACE_ENV_ARG_PARAMETER);
00166 ACE_CHECK;
00167
00168
00169
00170 TAO_ORBInitInfo_var tao_info =
00171 TAO_ORBInitInfo::_narrow (info
00172 ACE_ENV_ARG_PARAMETER);
00173 ACE_CHECK;
00174
00175 if (CORBA::is_nil (tao_info.in ()))
00176 {
00177 if (TAO_debug_level > 0)
00178 ACE_ERROR ((LM_ERROR,
00179 "(%P|%t) TAO_RT_ORBInitializer::pre_init:\n"
00180 "(%P|%t) Unable to narrow "
00181 "\"PortableInterceptor::ORBInitInfo_ptr\" to\n"
00182 "(%P|%t) \"TAO_ORBInitInfo *.\"\n"));
00183
00184 ACE_THROW (CORBA::INTERNAL ());
00185 }
00186
00187
00188 CORBA::Object_ptr rt_orb = CORBA::Object::_nil ();
00189 ACE_NEW_THROW_EX (rt_orb,
00190 TAO_RT_ORB (tao_info->orb_core (),
00191 dynamic_thread_idle_timeout_),
00192 CORBA::NO_MEMORY (
00193 CORBA::SystemException::_tao_minor_code (
00194 TAO::VMCID,
00195 ENOMEM),
00196 CORBA::COMPLETED_NO));
00197 ACE_CHECK;
00198 CORBA::Object_var safe_rt_orb = rt_orb;
00199
00200 info->register_initial_reference (TAO_OBJID_RTORB,
00201 rt_orb
00202 ACE_ENV_ARG_PARAMETER);
00203 ACE_CHECK;
00204
00205
00206 CORBA::Object_ptr current = CORBA::Object::_nil ();
00207 ACE_NEW_THROW_EX (current,
00208 TAO_RT_Current (tao_info->orb_core ()),
00209 CORBA::NO_MEMORY (
00210 CORBA::SystemException::_tao_minor_code (
00211 TAO::VMCID,
00212 ENOMEM),
00213 CORBA::COMPLETED_NO));
00214 ACE_CHECK;
00215 CORBA::Object_var safe_rt_current = current;
00216
00217 info->register_initial_reference (TAO_OBJID_RTCURRENT,
00218 current
00219 ACE_ENV_ARG_PARAMETER);
00220 ACE_CHECK;
00221
00222 tao_info->orb_core ()->orb_params ()->scope_policy (this->scope_policy_);
00223 tao_info->orb_core ()->orb_params ()->sched_policy (this->sched_policy_);
00224 tao_info->orb_core ()->orb_params ()->ace_sched_policy (this->ace_sched_policy_);
00225 }
00226
00227 void
00228 TAO_RT_ORBInitializer::post_init (
00229 PortableInterceptor::ORBInitInfo_ptr info
00230 ACE_ENV_ARG_DECL)
00231 ACE_THROW_SPEC ((CORBA::SystemException))
00232 {
00233 this->register_policy_factories (info
00234 ACE_ENV_ARG_PARAMETER);
00235
00236 ACE_CHECK;
00237 }
00238
00239 void
00240 TAO_RT_ORBInitializer::register_policy_factories (
00241 PortableInterceptor::ORBInitInfo_ptr info
00242 ACE_ENV_ARG_DECL)
00243 {
00244
00245
00246 if (CORBA::is_nil (this->policy_factory_.in ()))
00247 {
00248 PortableInterceptor::PolicyFactory_ptr policy_factory;
00249 ACE_NEW_THROW_EX (policy_factory,
00250 TAO_RT_PolicyFactory,
00251 CORBA::NO_MEMORY (
00252 CORBA::SystemException::_tao_minor_code (
00253 TAO::VMCID,
00254 ENOMEM),
00255 CORBA::COMPLETED_NO));
00256 ACE_CHECK;
00257
00258 this->policy_factory_ = policy_factory;
00259 }
00260
00261
00262
00263
00264 static CORBA::PolicyType const type[] = {
00265 RTCORBA::PRIORITY_MODEL_POLICY_TYPE,
00266 RTCORBA::THREADPOOL_POLICY_TYPE,
00267 RTCORBA::SERVER_PROTOCOL_POLICY_TYPE,
00268 RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE,
00269 RTCORBA::PRIVATE_CONNECTION_POLICY_TYPE,
00270 RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE
00271 };
00272
00273 const CORBA::PolicyType *end =
00274 type + sizeof (type) / sizeof (type[0]);
00275
00276 for (CORBA::PolicyType const * i = type;
00277 i != end;
00278 ++i)
00279 {
00280 ACE_TRY
00281 {
00282 info->register_policy_factory (*i,
00283 this->policy_factory_.in ()
00284 ACE_ENV_ARG_PARAMETER);
00285 ACE_TRY_CHECK;
00286 }
00287 ACE_CATCH (CORBA::BAD_INV_ORDER, ex)
00288 {
00289 if (ex.minor () == (CORBA::OMGVMCID | 16))
00290 {
00291
00292
00293
00294
00295
00296 return;
00297 }
00298 ACE_RE_THROW;
00299 }
00300 ACE_CATCHANY
00301 {
00302
00303 ACE_RE_THROW;
00304 }
00305 ACE_ENDTRY;
00306 ACE_CHECK;
00307 }
00308 }
00309
00310 TAO_END_VERSIONED_NAMESPACE_DECL
00311
00312 #endif