Go to the documentation of this file.00001 #include "tao/RTCORBA/RT_ORB_Loader.h"
00002
00003 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00004
00005 #include "tao/RTCORBA/RT_ORBInitializer.h"
00006
00007 #include "tao/debug.h"
00008 #include "tao/ORB_Constants.h"
00009 #include "tao/ORBInitializer_Registry.h"
00010 #include "tao/SystemException.h"
00011 #include "ace/OS_NS_strings.h"
00012 #include "ace/Arg_Shifter.h"
00013
00014 ACE_RCSID (RTCORBA,
00015 RT_ORB_Loader,
00016 "$Id: RT_ORB_Loader.cpp 90353 2010-05-31 08:42:46Z vzykov $")
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 TAO_RT_ORB_Loader::TAO_RT_ORB_Loader (void)
00021 : initialized_ (false)
00022 {
00023 }
00024
00025 TAO_RT_ORB_Loader::~TAO_RT_ORB_Loader (void)
00026 {
00027 }
00028
00029 int
00030 TAO_RT_ORB_Loader::init (int argc, ACE_TCHAR* argv[])
00031 {
00032 ACE_TRACE ("TAO_RT_ORB_Loader::init");
00033
00034
00035 if (this->initialized_)
00036 return 0;
00037
00038 this->initialized_ = true;
00039
00040 ACE_Service_Gestalt *gestalt = ACE_Service_Config::current ();
00041
00042 ACE_Service_Object * const rt_loader =
00043 ACE_Dynamic_Service<ACE_Service_Object>::instance (
00044 gestalt,
00045 "RT_ORB_Loader",
00046 true);
00047
00048 if (rt_loader != 0 && rt_loader != this)
00049 {
00050 return rt_loader->init (argc, argv);
00051 }
00052
00053
00054 int priority_mapping_type =
00055 TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_DIRECT;
00056 int network_priority_mapping_type =
00057 TAO_RT_ORBInitializer::TAO_NETWORK_PRIORITY_MAPPING_LINEAR;
00058 int ace_sched_policy = ACE_SCHED_OTHER;
00059 long sched_policy = THR_SCHED_DEFAULT;
00060 long scope_policy = THR_SCOPE_PROCESS;
00061 int curarg = 0;
00062 ACE_Time_Value dynamic_thread_time;
00063 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_INFINITIVE;
00064
00065 ACE_Arg_Shifter arg_shifter (argc, argv);
00066
00067
00068 while (arg_shifter.is_anything_left ())
00069 {
00070 const ACE_TCHAR *current_arg = 0;
00071 if (0 != (current_arg = arg_shifter.get_the_parameter
00072 (ACE_TEXT("-ORBPriorityMapping"))))
00073 {
00074 const ACE_TCHAR *name = current_arg;
00075 if (ACE_OS::strcasecmp (name,
00076 ACE_TEXT("continuous")) == 0)
00077 priority_mapping_type =
00078 TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_CONTINUOUS;
00079 else if (ACE_OS::strcasecmp (name,
00080 ACE_TEXT("linear")) == 0)
00081 priority_mapping_type =
00082 TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_LINEAR;
00083 else if (ACE_OS::strcasecmp (name,
00084 ACE_TEXT("direct")) == 0)
00085 priority_mapping_type =
00086 TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_DIRECT;
00087 else
00088 ACE_DEBUG ((LM_DEBUG,
00089 ACE_TEXT("RT_ORB_Loader - unknown argument")
00090 ACE_TEXT(" <%s> for -ORBPriorityMapping\n"),
00091 name));
00092 arg_shifter.consume_arg ();
00093 }
00094 else if (0 != (current_arg = arg_shifter.get_the_parameter
00095 (ACE_TEXT("-ORBSchedPolicy"))))
00096 {
00097 const ACE_TCHAR *name = current_arg;
00098 if (ACE_OS::strcasecmp (name,
00099 ACE_TEXT("SCHED_OTHER")) == 0)
00100 {
00101 ace_sched_policy = ACE_SCHED_OTHER;
00102 sched_policy = THR_SCHED_DEFAULT;
00103 }
00104 else if (ACE_OS::strcasecmp (name,
00105 ACE_TEXT("SCHED_FIFO")) == 0)
00106 {
00107 ace_sched_policy = ACE_SCHED_FIFO;
00108 sched_policy = THR_SCHED_FIFO;
00109 }
00110 else if (ACE_OS::strcasecmp (name,
00111 ACE_TEXT("SCHED_RR")) == 0)
00112 {
00113 ace_sched_policy = ACE_SCHED_RR;
00114 sched_policy = THR_SCHED_RR;
00115 }
00116 else
00117 ACE_DEBUG ((LM_DEBUG,
00118 ACE_TEXT("RT_ORB_Loader - unknown argument")
00119 ACE_TEXT(" <%s> for -ORBSchedPolicy\n"),
00120 name));
00121 arg_shifter.consume_arg ();
00122 }
00123 else if (0 != (current_arg = arg_shifter.get_the_parameter
00124 (ACE_TEXT("-ORBScopePolicy"))))
00125 {
00126 const ACE_TCHAR *name = current_arg;
00127 if (ACE_OS::strcasecmp (name,
00128 ACE_TEXT("SYSTEM")) == 0)
00129 scope_policy = THR_SCOPE_SYSTEM;
00130 else if (ACE_OS::strcasecmp (name,
00131 ACE_TEXT("PROCESS")) == 0)
00132 scope_policy = THR_SCOPE_PROCESS;
00133 else
00134 ACE_DEBUG ((LM_DEBUG,
00135 ACE_TEXT("RT_ORB_Loader - unknown argument")
00136 ACE_TEXT(" <%s> for -ORBScopePolicy\n"),
00137 name));
00138 arg_shifter.consume_arg ();
00139 }
00140 else if (0 != (current_arg = arg_shifter.get_the_parameter
00141 (ACE_TEXT("-RTORBNetworkPriorityMapping"))))
00142 {
00143 const ACE_TCHAR *name = current_arg;
00144 if (ACE_OS::strcasecmp (name,
00145 ACE_TEXT("linear")) == 0)
00146 network_priority_mapping_type =
00147 TAO_RT_ORBInitializer::TAO_NETWORK_PRIORITY_MAPPING_LINEAR;
00148 arg_shifter.consume_arg ();
00149 }
00150 else if (0 != (current_arg = arg_shifter.get_the_parameter
00151 (ACE_TEXT("-RTORBDynamicThreadIdleTimeout"))))
00152 {
00153 const ACE_TCHAR *name = current_arg;
00154 int timeout = ACE_OS::atoi (name);
00155 dynamic_thread_time = ACE_Time_Value (0, timeout);
00156 lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_IDLE;
00157 arg_shifter.consume_arg ();
00158 }
00159 else if (0 != (current_arg = arg_shifter.get_the_parameter
00160 (ACE_TEXT("-RTORBDynamicThreadRunTime"))))
00161 {
00162 const ACE_TCHAR *name = current_arg;
00163 int timeout = ACE_OS::atoi (name);
00164 dynamic_thread_time = ACE_Time_Value (0, timeout);
00165 lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_FIXED;
00166 arg_shifter.consume_arg ();
00167 }
00168 else
00169 {
00170 arg_shifter.ignore_arg ();
00171 if (TAO_debug_level > 0)
00172 {
00173 ACE_ERROR ((LM_ERROR,
00174 ACE_TEXT("RT_ORB_Loader: Unknown option ")
00175 ACE_TEXT("<%s>.\n"),
00176 argv[curarg]));
00177 }
00178 }
00179 }
00180
00181
00182 try
00183 {
00184 PortableInterceptor::ORBInitializer_ptr temp_orb_initializer =
00185 PortableInterceptor::ORBInitializer::_nil ();
00186
00187
00188 ACE_NEW_THROW_EX (temp_orb_initializer,
00189 TAO_RT_ORBInitializer (priority_mapping_type,
00190 network_priority_mapping_type,
00191 ace_sched_policy,
00192 sched_policy,
00193 scope_policy,
00194 lifespan,
00195 dynamic_thread_time),
00196 CORBA::NO_MEMORY (
00197 CORBA::SystemException::_tao_minor_code (
00198 TAO::VMCID,
00199 ENOMEM),
00200 CORBA::COMPLETED_NO));
00201
00202 PortableInterceptor::ORBInitializer_var orb_initializer;
00203 orb_initializer = temp_orb_initializer;
00204
00205 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
00206 }
00207 catch (const ::CORBA::Exception& ex)
00208 {
00209 ex._tao_print_exception (
00210 "Unexpected exception caught while "
00211 "initializing the RTORB");
00212 return 1;
00213 }
00214
00215 return 0;
00216 }
00217
00218
00219
00220
00221 ACE_FACTORY_DEFINE (TAO_RTCORBA, TAO_RT_ORB_Loader)
00222 ACE_STATIC_SVC_DEFINE (TAO_RT_ORB_Loader,
00223 ACE_TEXT ("RT_ORB_Loader"),
00224 ACE_SVC_OBJ_T,
00225 &ACE_SVC_NAME (TAO_RT_ORB_Loader),
00226 ACE_Service_Type::DELETE_THIS
00227 | ACE_Service_Type::DELETE_OBJ,
00228 0)
00229 TAO_END_VERSIONED_NAMESPACE_DECL
00230
00231 #endif