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 80586 2008-02-07 10:39:04Z vzykov $")
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 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00055 ACE_Time_Value const &dynamic_thread_time)
00056 : priority_mapping_type_ (priority_mapping_type),
00057 network_priority_mapping_type_ (network_priority_mapping_type),
00058 ace_sched_policy_ (ace_sched_policy),
00059 sched_policy_ (sched_policy),
00060 scope_policy_ (scope_policy),
00061 lifespan_ (lifespan),
00062 dynamic_thread_time_ (dynamic_thread_time)
00063 {
00064 }
00065
00066 void
00067 TAO_RT_ORBInitializer::pre_init (PortableInterceptor::ORBInitInfo_ptr info)
00068 {
00069
00070
00071
00072
00073
00074
00075 TAO_ORBInitInfo_var tao_info = TAO_ORBInitInfo::_narrow (info);
00076
00077 if (CORBA::is_nil (tao_info.in ()))
00078 {
00079 if (TAO_debug_level > 0)
00080 ACE_ERROR ((LM_ERROR,
00081 "(%P|%t) TAO_RT_ORBInitializer::pre_init:\n"
00082 "(%P|%t) Unable to narrow "
00083 "\"PortableInterceptor::ORBInitInfo_ptr\" to\n"
00084 "(%P|%t) \"TAO_ORBInitInfo *.\"\n"));
00085
00086 throw ::CORBA::INTERNAL ();
00087 }
00088
00089
00090 tao_info->orb_core ()->orb_params ()->protocols_hooks_name ("RT_Protocols_Hooks");
00091 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Protocols_Hooks);
00092
00093
00094 tao_info->orb_core ()->orb_params ()->stub_factory_name ("RT_Stub_Factory");
00095 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Stub_Factory);
00096
00097
00098 tao_info->orb_core ()->orb_params ()->endpoint_selector_factory_name ("RT_Endpoint_Selector_Factory");
00099 ACE_Service_Config::process_directive (ace_svc_desc_RT_Endpoint_Selector_Factory);
00100
00101
00102 tao_info->orb_core ()->orb_params ()->thread_lane_resources_manager_factory_name ("RT_Thread_Lane_Resources_Manager_Factory");
00103 ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Thread_Lane_Resources_Manager_Factory);
00104
00105
00106 tao_info->orb_core ()->orb_params ()->poa_factory_name (rt_poa_factory_name);
00107 tao_info->orb_core ()->orb_params ()->poa_factory_directive (ACE_TEXT_ALWAYS_CHAR (rt_poa_factory_directive));
00108
00109
00110 TAO_Priority_Mapping *pm = 0;
00111 switch (this->priority_mapping_type_)
00112 {
00113 case TAO_PRIORITY_MAPPING_CONTINUOUS:
00114 ACE_NEW (pm,
00115 TAO_Continuous_Priority_Mapping (this->ace_sched_policy_));
00116 break;
00117 case TAO_PRIORITY_MAPPING_LINEAR:
00118 ACE_NEW (pm,
00119 TAO_Linear_Priority_Mapping (this->ace_sched_policy_));
00120 break;
00121 default:
00122 case TAO_PRIORITY_MAPPING_DIRECT:
00123 ACE_NEW (pm,
00124 TAO_Direct_Priority_Mapping (this->ace_sched_policy_));
00125 break;
00126 }
00127
00128
00129 TAO_Priority_Mapping_Manager *manager = 0;
00130
00131 ACE_NEW_THROW_EX (manager,
00132 TAO_Priority_Mapping_Manager (pm),
00133 CORBA::NO_MEMORY (
00134 CORBA::SystemException::_tao_minor_code (
00135 TAO::VMCID,
00136 ENOMEM),
00137 CORBA::COMPLETED_NO));
00138
00139 TAO_Priority_Mapping_Manager_var safe_manager = manager;
00140
00141 info->register_initial_reference ("PriorityMappingManager", manager);
00142
00143
00144 TAO_Network_Priority_Mapping *npm = 0;
00145 switch (this->network_priority_mapping_type_)
00146 {
00147 default:
00148 case TAO_NETWORK_PRIORITY_MAPPING_LINEAR:
00149 ACE_NEW (npm,
00150 TAO_Linear_Network_Priority_Mapping (this->ace_sched_policy_));
00151 break;
00152 }
00153
00154
00155 TAO_Network_Priority_Mapping_Manager * network_manager = 0;
00156
00157
00158
00159
00160
00161
00162 ACE_NEW_THROW_EX (network_manager,
00163 TAO_Network_Priority_Mapping_Manager (npm),
00164 CORBA::NO_MEMORY (
00165 CORBA::SystemException::_tao_minor_code (
00166 TAO::VMCID,
00167 ENOMEM),
00168 CORBA::COMPLETED_NO));
00169
00170 TAO_Network_Priority_Mapping_Manager_var safe_network_manager =
00171 network_manager;
00172
00173 info->register_initial_reference ("NetworkPriorityMappingManager",
00174 network_manager);
00175
00176
00177 CORBA::Object_ptr rt_orb = CORBA::Object::_nil ();
00178 ACE_NEW_THROW_EX (rt_orb,
00179 TAO_RT_ORB (tao_info->orb_core (),
00180 lifespan_,
00181 dynamic_thread_time_),
00182 CORBA::NO_MEMORY (
00183 CORBA::SystemException::_tao_minor_code (
00184 TAO::VMCID,
00185 ENOMEM),
00186 CORBA::COMPLETED_NO));
00187 CORBA::Object_var safe_rt_orb = rt_orb;
00188
00189 info->register_initial_reference (TAO_OBJID_RTORB, rt_orb);
00190
00191
00192 CORBA::Object_ptr current = CORBA::Object::_nil ();
00193 ACE_NEW_THROW_EX (current,
00194 TAO_RT_Current (tao_info->orb_core ()),
00195 CORBA::NO_MEMORY (
00196 CORBA::SystemException::_tao_minor_code (
00197 TAO::VMCID,
00198 ENOMEM),
00199 CORBA::COMPLETED_NO));
00200 CORBA::Object_var safe_rt_current = current;
00201
00202 info->register_initial_reference (TAO_OBJID_RTCURRENT, current);
00203
00204 tao_info->orb_core ()->orb_params ()->scope_policy (this->scope_policy_);
00205 tao_info->orb_core ()->orb_params ()->sched_policy (this->sched_policy_);
00206 tao_info->orb_core ()->orb_params ()->ace_sched_policy (this->ace_sched_policy_);
00207 }
00208
00209 void
00210 TAO_RT_ORBInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
00211 {
00212 this->register_policy_factories (info);
00213 }
00214
00215 void
00216 TAO_RT_ORBInitializer::register_policy_factories (
00217 PortableInterceptor::ORBInitInfo_ptr info)
00218 {
00219
00220
00221 if (CORBA::is_nil (this->policy_factory_.in ()))
00222 {
00223 PortableInterceptor::PolicyFactory_ptr policy_factory;
00224 ACE_NEW_THROW_EX (policy_factory,
00225 TAO_RT_PolicyFactory,
00226 CORBA::NO_MEMORY (
00227 CORBA::SystemException::_tao_minor_code (
00228 TAO::VMCID,
00229 ENOMEM),
00230 CORBA::COMPLETED_NO));
00231
00232 this->policy_factory_ = policy_factory;
00233 }
00234
00235
00236
00237
00238 static CORBA::PolicyType const type[] = {
00239 RTCORBA::PRIORITY_MODEL_POLICY_TYPE,
00240 RTCORBA::THREADPOOL_POLICY_TYPE,
00241 RTCORBA::SERVER_PROTOCOL_POLICY_TYPE,
00242 RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE,
00243 RTCORBA::PRIVATE_CONNECTION_POLICY_TYPE,
00244 RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE
00245 };
00246
00247 const CORBA::PolicyType *end =
00248 type + sizeof (type) / sizeof (type[0]);
00249
00250 for (CORBA::PolicyType const * i = type;
00251 i != end;
00252 ++i)
00253 {
00254 try
00255 {
00256 info->register_policy_factory (*i, this->policy_factory_.in ());
00257 }
00258 catch (const ::CORBA::BAD_INV_ORDER& ex)
00259 {
00260 if (ex.minor () == (CORBA::OMGVMCID | 16))
00261 {
00262
00263
00264
00265
00266
00267 return;
00268 }
00269 throw;
00270 }
00271 }
00272 }
00273
00274 TAO_END_VERSIONED_NAMESPACE_DECL
00275
00276 #endif