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