Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / params.cpp
blob10382be69ed94eb4b120d258ef73e39921f410eb
1 #include "tao/params.h"
2 #include "tao/orbconf.h"
3 #include "tao/Version.h"
5 #if !defined (__ACE_INLINE__)
6 # include "tao/params.inl"
7 #endif /* __ACE_INLINE__ */
9 #include "ace/OS_NS_Thread.h"
10 #include "ace/Service_Config.h"
11 #include "tao/Invocation_Utils.h"
13 #if !defined (TAO_ALLOW_ZIOP_NO_SERVER_POLICIES_DEFAULT)
14 # define TAO_ALLOW_ZIOP_NO_SERVER_POLICIES_DEFAULT false
15 #endif /* !TAO_ALLOW_ZIOP_NO_SERVER_POLICIES_DEFAULT */
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 TAO_ORB_Parameters::TAO_ORB_Parameters ()
20 : endpoints_map_ (10)
21 , mcast_discovery_endpoint_ ()
22 , default_init_ref_ (TAO_DEFAULT_INIT_REFERENCE_INITIALIZER)
23 , sock_rcvbuf_size_ (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
24 , sock_sndbuf_size_ (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
25 , nodelay_ (1)
26 , sock_keepalive_ (0)
27 , sock_dontroute_ (0)
28 , ip_hoplimit_ (-1)
29 , ip_multicastloop_ (true)
30 , iiop_client_port_base_ (0)
31 , iiop_client_port_span_ (0)
32 , cdr_memcpy_tradeoff_ (ACE_DEFAULT_CDR_MEMCPY_TRADEOFF)
33 , max_message_size_ (0) // Disable outgoing GIOP fragments by default
34 , use_dotted_decimal_addresses_ (0)
35 , cache_incoming_by_dotted_decimal_address_ (0)
36 , linger_ (-1)
37 , accept_error_delay_ (0)
38 , std_profile_components_ (1)
39 , ace_sched_policy_ (ACE_SCHED_OTHER)
40 , sched_policy_ (THR_SCHED_DEFAULT)
41 , scope_policy_ (THR_SCOPE_PROCESS)
42 , single_read_optimization_ (1)
43 , shared_profile_ (0)
44 , use_parallel_connects_ (false)
45 , parallel_connect_delay_ (0)
46 , pref_network_ ()
47 , disable_rt_collocation_resolver_ (false)
48 , enforce_preferred_interfaces_ (false)
49 #if defined (ACE_HAS_IPV6)
50 , prefer_ipv6_interfaces_ (false)
51 , connect_ipv6_only_ (false)
52 , use_ipv6_link_local_ (false)
53 #endif /* ACE_HAS_IPV6 */
54 , negotiate_codesets_ (true)
55 , ami_collication_ (true)
56 , protocols_hooks_name_ ("Protocols_Hooks")
57 , stub_factory_name_ ("Default_Stub_Factory")
58 , endpoint_selector_factory_name_ ("Default_Endpoint_Selector_Factory")
59 , thread_lane_resources_manager_factory_name_ ("Default_Thread_Lane_Resources_Manager_Factory")
60 , dynamic_thread_pool_config_name_ ()
61 , poa_factory_name_ ("TAO_Object_Adapter_Factory")
62 , poa_factory_directive_
63 (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("TAO_Object_Adapter_Factory",
64 "TAO_PortableServer",
65 TAO_VERSION,
66 "_make_TAO_Object_Adapter_Factory",
67 ""))
68 , forward_invocation_on_object_not_exist_ (false)
69 , forward_once_exception_ (0)
70 , collocation_resolver_name_ ("Default_Collocation_Resolver")
71 , allow_ziop_no_server_policies_ (!!TAO_ALLOW_ZIOP_NO_SERVER_POLICIES_DEFAULT)
73 for (int i = 0; i != TAO_NO_OF_MCAST_SERVICES; ++i)
75 this->service_port_[i] = 0;
79 void
80 TAO_ORB_Parameters::get_endpoint_set (const ACE_CString &lane,
81 TAO_EndpointSet &endpoint_set)
83 // Look for the lane in the endpoints map.
84 endpoints_map_type::iterator const endpoints =
85 this->endpoints_map_.find (lane);
87 // If lane is not in the map, endpoint_set remains empty
88 if (endpoints == this->endpoints_map_.end ())
89 return;
91 // At this point, the parsing should not fail since they have been
92 // parsed successfully before.
93 int const result =
94 this->parse_and_add_endpoints ((*endpoints).second, endpoint_set);
96 ACE_ASSERT (result == 0);
97 ACE_UNUSED_ARG (result);
101 TAO_ORB_Parameters::add_endpoints (const ACE_CString &lane,
102 const ACE_CString &additional_endpoints)
104 TAO_EndpointSet endpoint_set;
106 // Parse the additional endpoints.
107 int const result =
108 this->parse_and_add_endpoints (additional_endpoints, endpoint_set);
110 // Parse failure.
111 if (result != 0)
112 return result;
114 // Look for the lane in the endpoints map.
116 // Return reference to endpoints string corresponding to lane
117 // string. If none, a default constructed string is inserted into
118 // the map and returned.
119 ACE_CString & existing_endpoints = this->endpoints_map_[lane];
121 // Create the resulting endpoints string.
122 if (existing_endpoints.length () != 0)
124 existing_endpoints += ";";
127 existing_endpoints += additional_endpoints;
129 return 0;
133 TAO_ORB_Parameters::parse_and_add_endpoints (const ACE_CString &endpoints,
134 TAO_EndpointSet &endpoint_set)
136 // Parse the string into separate endpoints, where `endpoints' is of
137 // the form:
139 // protocol1://V,v@addr1,...,addrN;protocol2://addr1,...,W.w@addrN;...
141 // A single endpoint, instead of several, can be added just as well.
143 static char const endpoints_delimiter = ';';
145 size_t const length = endpoints.length ();
147 if (endpoints[0] == endpoints_delimiter ||
148 endpoints[length - 1] == endpoints_delimiter)
150 return -1;
151 // Failure: endpoints string has an empty endpoint at the
152 // beginning or the end of the string
153 // (e.g. ";uiop://foo;iiop://1.3@bar")
156 int status = 0;
157 // Return code: 0 = success, -1 = failure
159 if (length > 0)
161 int endpoints_count = 1;
163 for (size_t j = 0; j != length; ++j)
165 if (endpoints[j] == endpoints_delimiter)
167 ++endpoints_count;
171 ssize_t begin = 0;
172 ssize_t end = endpoints.find (endpoints_delimiter);
174 for (int i = 0; i < endpoints_count; ++i)
176 if (end == 0)
178 // Handle case where two consecutive endpoints `;;'
179 // delimiters are found within the endpoints set.
181 // Is it enough to just skip over it or should we return an
182 // error?
183 continue;
186 ACE_CString const endpt =
187 endpoints.substring (begin, end - begin);
188 // The substring call will work even if `end' is equal to
189 // ACE_CString::npos since that will just extract the substring
190 // from the offset `begin' to the end of the string.
192 // Check for a valid URL style endpoint set
193 ACE_CString::size_type const check_offset = endpt.find ("://");
195 if (check_offset > 0 &&
196 check_offset != endpt.npos)
198 endpoint_set.enqueue_tail (endpt);
199 // Insert endpoint into list
201 else
203 status = -1; // Error: invalid URL style endpoint set
206 begin = end + 1;
207 end = endpoints.find (endpoints_delimiter, begin);
210 else
212 status = -1;
213 // Failure: Empty string
216 return status;
219 bool
220 TAO_ORB_Parameters::check_preferred_interfaces_string (const char *s)
222 // Validates that s contains one or more comma separated
223 // interfaces each consisting of a string with a single
224 // assignment separator ('=' or ':')
225 // Any other char is legal, although '*' and '?' will be
226 // treated as wildcards.
227 bool expect_assign = false;
228 bool expect_comma = false;
229 bool expect_wild = true;
230 bool found_remote = false;
232 for (const char *p = s; *p; ++p) switch (*p)
234 #if !defined (ACE_HAS_IPV6)
235 // Can't use this as assignment operator when IPv6 decimal
236 // addresses may be involved.
237 case ':':
238 #endif /* ACE_HAS_IPV6 */
239 case '=':
240 if (!expect_assign)
241 return false;
242 found_remote = true;
243 expect_assign = false;
244 expect_comma = false;
245 expect_wild = true;
246 break;
248 case ',':
249 if (!expect_comma)
250 return false;
251 found_remote = false;
252 expect_assign = false;
253 expect_comma = false;
254 expect_wild = true;
255 break;
257 case '*':
258 case '?':
259 if (!expect_wild)
260 return false;
261 expect_assign = !found_remote;
262 expect_comma = found_remote;
263 expect_wild = false;
264 break;
266 default:
267 expect_assign = !found_remote;
268 expect_comma = found_remote;
269 expect_wild = true;
270 break;
273 return expect_comma && !expect_assign;
276 bool
277 TAO_ORB_Parameters::preferred_interfaces (const char *s)
279 const bool valid= check_preferred_interfaces_string (s);
280 if (valid)
282 // Append any valid string to those already specified
283 // (by other -ORBPreferredInterfaces options that have been
284 // seen previously)
285 if (this->pref_network_.length ())
286 this->pref_network_+= ',';
287 this->pref_network_+= s;
290 return valid;
293 const char *
294 TAO_ORB_Parameters::preferred_interfaces () const
296 return this->pref_network_.c_str ();
299 void
300 TAO_ORB_Parameters::enforce_pref_interfaces (bool p)
302 this->enforce_preferred_interfaces_ = p;
305 bool
306 TAO_ORB_Parameters::enforce_pref_interfaces () const
308 return this->enforce_preferred_interfaces_;
311 #if defined (ACE_HAS_IPV6)
312 void
313 TAO_ORB_Parameters::prefer_ipv6_interfaces (bool p)
315 this->prefer_ipv6_interfaces_ = p;
318 bool
319 TAO_ORB_Parameters::prefer_ipv6_interfaces () const
321 return this->prefer_ipv6_interfaces_;
324 void
325 TAO_ORB_Parameters::connect_ipv6_only (bool p)
327 this->connect_ipv6_only_ = p;
330 bool
331 TAO_ORB_Parameters::connect_ipv6_only () const
333 return this->connect_ipv6_only_;
336 void
337 TAO_ORB_Parameters::use_ipv6_link_local (bool p)
339 this->use_ipv6_link_local_ = p;
342 bool
343 TAO_ORB_Parameters::use_ipv6_link_local () const
345 return this->use_ipv6_link_local_;
347 #endif /* ACE_HAS_IPV6 */
349 void
350 TAO_ORB_Parameters::protocols_hooks_name (const char *s)
352 this->protocols_hooks_name_ = s;
355 const char *
356 TAO_ORB_Parameters::protocols_hooks_name () const
358 return this->protocols_hooks_name_.c_str ();
361 void
362 TAO_ORB_Parameters::thread_lane_resources_manager_factory_name (const char *s)
364 this->thread_lane_resources_manager_factory_name_ = s;
367 const char *
368 TAO_ORB_Parameters::thread_lane_resources_manager_factory_name () const
370 return this->thread_lane_resources_manager_factory_name_.c_str ();
373 void
374 TAO_ORB_Parameters::dynamic_thread_pool_config_name (const char *s)
376 this->dynamic_thread_pool_config_name_ = s;
379 const char *
380 TAO_ORB_Parameters::dynamic_thread_pool_config_name () const
382 return this->dynamic_thread_pool_config_name_.c_str ();
385 void
386 TAO_ORB_Parameters::stub_factory_name (const char *s)
388 this->stub_factory_name_ = s;
391 const char *
392 TAO_ORB_Parameters::stub_factory_name () const
394 return this->stub_factory_name_.c_str ();
397 void
398 TAO_ORB_Parameters::poa_factory_name (const char *s)
400 this->poa_factory_name_ = s;
403 const char *
404 TAO_ORB_Parameters::poa_factory_name () const
406 return this->poa_factory_name_.c_str ();
409 void
410 TAO_ORB_Parameters::poa_factory_directive (const ACE_TCHAR *s)
412 this->poa_factory_directive_ = s;
415 const ACE_TCHAR *
416 TAO_ORB_Parameters::poa_factory_directive () const
418 return this->poa_factory_directive_.c_str ();
421 void
422 TAO_ORB_Parameters::endpoint_selector_factory_name (const char *s)
424 this->endpoint_selector_factory_name_ = s;
427 const char *
428 TAO_ORB_Parameters::endpoint_selector_factory_name () const
430 return this->endpoint_selector_factory_name_.c_str ();
433 const TAO::Invocation_Retry_Params &
434 TAO_ORB_Parameters::invocation_retry_params () const
436 return this->invocation_retry_params_;
439 TAO::Invocation_Retry_Params &
440 TAO_ORB_Parameters::invocation_retry_params ()
442 return this->invocation_retry_params_;
445 void
446 TAO_ORB_Parameters::forward_on_exception_limit (const int ef, const int limit)
448 this->invocation_retry_params_.forward_on_exception_limit_[ef] = limit;
451 void
452 TAO_ORB_Parameters::forward_on_exception_delay (const ACE_Time_Value &delay)
454 this->invocation_retry_params_.init_retry_delay_ = delay;
457 TAO_END_VERSIONED_NAMESPACE_DECL