Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / RTCORBA / RT_ORB_Loader.cpp
blobd42b9b2a339f1bd9c9ab50e26887300f5b756046
1 #include "tao/RTCORBA/RT_ORB_Loader.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/RTCORBA/RT_ORBInitializer.h"
7 #include "tao/debug.h"
8 #include "tao/ORB_Constants.h"
9 #include "tao/ORBInitializer_Registry.h"
10 #include "tao/SystemException.h"
11 #include "ace/OS_NS_strings.h"
12 #include "ace/Arg_Shifter.h"
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
16 TAO_RT_ORB_Loader::TAO_RT_ORB_Loader ()
17 : initialized_ (false)
21 TAO_RT_ORB_Loader::~TAO_RT_ORB_Loader ()
25 int
26 TAO_RT_ORB_Loader::init (int argc, ACE_TCHAR* argv[])
28 ACE_TRACE ("TAO_RT_ORB_Loader::init");
30 // Only allow initialization once.
31 if (this->initialized_)
32 return 0;
34 this->initialized_ = true;
36 ACE_Service_Gestalt *gestalt = ACE_Service_Config::current ();
38 ACE_Service_Object * const rt_loader =
39 ACE_Dynamic_Service<ACE_Service_Object>::instance (
40 gestalt,
41 "RT_ORB_Loader",
42 true);
44 if (rt_loader != 0 && rt_loader != this)
46 return rt_loader->init (argc, argv);
49 // Set defaults.
50 int priority_mapping_type =
51 TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_DIRECT;
52 int network_priority_mapping_type =
53 TAO_RT_ORBInitializer::TAO_NETWORK_PRIORITY_MAPPING_LINEAR;
54 int ace_sched_policy = ACE_SCHED_OTHER;
55 long sched_policy = THR_SCHED_DEFAULT;
56 long scope_policy = THR_SCOPE_PROCESS;
57 int curarg = 0;
58 ACE_Time_Value dynamic_thread_time;
59 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_INFINITIVE;
61 ACE_Arg_Shifter arg_shifter (argc, argv);
63 // Parse any service configurator parameters.
64 while (arg_shifter.is_anything_left ())
66 const ACE_TCHAR *current_arg = 0;
67 if (0 != (current_arg = arg_shifter.get_the_parameter
68 (ACE_TEXT("-ORBPriorityMapping"))))
70 const ACE_TCHAR *name = current_arg;
71 if (ACE_OS::strcasecmp (name,
72 ACE_TEXT("continuous")) == 0)
73 priority_mapping_type =
74 TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_CONTINUOUS;
75 else if (ACE_OS::strcasecmp (name,
76 ACE_TEXT("linear")) == 0)
77 priority_mapping_type =
78 TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_LINEAR;
79 else if (ACE_OS::strcasecmp (name,
80 ACE_TEXT("direct")) == 0)
81 priority_mapping_type =
82 TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_DIRECT;
83 else
84 TAOLIB_DEBUG ((LM_DEBUG,
85 ACE_TEXT("RT_ORB_Loader - unknown argument")
86 ACE_TEXT(" <%s> for -ORBPriorityMapping\n"),
87 name));
88 arg_shifter.consume_arg ();
90 else if (0 != (current_arg = arg_shifter.get_the_parameter
91 (ACE_TEXT("-ORBSchedPolicy"))))
93 const ACE_TCHAR *name = current_arg;
94 if (ACE_OS::strcasecmp (name,
95 ACE_TEXT("SCHED_OTHER")) == 0)
97 ace_sched_policy = ACE_SCHED_OTHER;
98 sched_policy = THR_SCHED_DEFAULT;
100 else if (ACE_OS::strcasecmp (name,
101 ACE_TEXT("SCHED_FIFO")) == 0)
103 ace_sched_policy = ACE_SCHED_FIFO;
104 sched_policy = THR_SCHED_FIFO;
106 else if (ACE_OS::strcasecmp (name,
107 ACE_TEXT("SCHED_RR")) == 0)
109 ace_sched_policy = ACE_SCHED_RR;
110 sched_policy = THR_SCHED_RR;
112 else
113 TAOLIB_DEBUG ((LM_DEBUG,
114 ACE_TEXT("RT_ORB_Loader - unknown argument")
115 ACE_TEXT(" <%s> for -ORBSchedPolicy\n"),
116 name));
117 arg_shifter.consume_arg ();
119 else if (0 != (current_arg = arg_shifter.get_the_parameter
120 (ACE_TEXT("-ORBScopePolicy"))))
122 const ACE_TCHAR *name = current_arg;
123 if (ACE_OS::strcasecmp (name,
124 ACE_TEXT("SYSTEM")) == 0)
125 scope_policy = THR_SCOPE_SYSTEM;
126 else if (ACE_OS::strcasecmp (name,
127 ACE_TEXT("PROCESS")) == 0)
128 scope_policy = THR_SCOPE_PROCESS;
129 else
130 TAOLIB_DEBUG ((LM_DEBUG,
131 ACE_TEXT("RT_ORB_Loader - unknown argument")
132 ACE_TEXT(" <%s> for -ORBScopePolicy\n"),
133 name));
134 arg_shifter.consume_arg ();
136 else if (0 != (current_arg = arg_shifter.get_the_parameter
137 (ACE_TEXT("-RTORBNetworkPriorityMapping"))))
139 const ACE_TCHAR *name = current_arg;
140 if (ACE_OS::strcasecmp (name,
141 ACE_TEXT("linear")) == 0)
142 network_priority_mapping_type =
143 TAO_RT_ORBInitializer::TAO_NETWORK_PRIORITY_MAPPING_LINEAR;
144 arg_shifter.consume_arg ();
146 else if (0 != (current_arg = arg_shifter.get_the_parameter
147 (ACE_TEXT("-RTORBDynamicThreadIdleTimeout"))))
149 const ACE_TCHAR *name = current_arg;
150 int const timeout = ACE_OS::atoi (name);
151 dynamic_thread_time = ACE_Time_Value (0, timeout);
152 lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_IDLE;
153 arg_shifter.consume_arg ();
155 else if (0 != (current_arg = arg_shifter.get_the_parameter
156 (ACE_TEXT("-RTORBDynamicThreadRunTime"))))
158 const ACE_TCHAR *name = current_arg;
159 int const timeout = ACE_OS::atoi (name);
160 dynamic_thread_time = ACE_Time_Value (0, timeout);
161 lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_FIXED;
162 arg_shifter.consume_arg ();
164 else
166 arg_shifter.ignore_arg ();
167 if (TAO_debug_level > 0)
169 TAOLIB_ERROR ((LM_ERROR,
170 ACE_TEXT("RT_ORB_Loader: Unknown option ")
171 ACE_TEXT("<%s>.\n"),
172 argv[curarg]));
177 // Register the ORB initializer.
180 PortableInterceptor::ORBInitializer_ptr temp_orb_initializer =
181 PortableInterceptor::ORBInitializer::_nil ();
183 /// Register the RTCORBA ORBInitializer.
184 ACE_NEW_THROW_EX (temp_orb_initializer,
185 TAO_RT_ORBInitializer (priority_mapping_type,
186 network_priority_mapping_type,
187 ace_sched_policy,
188 sched_policy,
189 scope_policy,
190 lifespan,
191 dynamic_thread_time),
192 CORBA::NO_MEMORY (
193 CORBA::SystemException::_tao_minor_code (
194 TAO::VMCID,
195 ENOMEM),
196 CORBA::COMPLETED_NO));
198 PortableInterceptor::ORBInitializer_var orb_initializer;
199 orb_initializer = temp_orb_initializer;
201 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
203 catch (const ::CORBA::Exception& ex)
205 ex._tao_print_exception (
206 "Unexpected exception caught while "
207 "initializing the RTORB");
208 return 1;
211 return 0;
215 /////////////////////////////////////////////////////////////////////
217 ACE_FACTORY_DEFINE (TAO_RTCORBA, TAO_RT_ORB_Loader)
218 ACE_STATIC_SVC_DEFINE (TAO_RT_ORB_Loader,
219 ACE_TEXT ("RT_ORB_Loader"),
220 ACE_SVC_OBJ_T,
221 &ACE_SVC_NAME (TAO_RT_ORB_Loader),
222 ACE_Service_Type::DELETE_THIS
223 | ACE_Service_Type::DELETE_OBJ,
225 TAO_END_VERSIONED_NAMESPACE_DECL
227 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */