params.cpp

Go to the documentation of this file.
00001 // $Id: params.cpp 81470 2008-04-28 12:40:23Z elliott_c $
00002 
00003 #include "tao/params.h"
00004 #include "tao/orbconf.h"
00005 
00006 #if !defined (__ACE_INLINE__)
00007 # include "tao/params.inl"
00008 #endif /* __ACE_INLINE__ */
00009 
00010 #include "ace/OS_NS_Thread.h"
00011 #include "ace/Service_Config.h"
00012 
00013 ACE_RCSID (tao,
00014            params,
00015            "$Id: params.cpp 81470 2008-04-28 12:40:23Z elliott_c $")
00016 
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018 
00019 TAO_ORB_Parameters::TAO_ORB_Parameters (void)
00020   : endpoints_map_ (10)
00021   , mcast_discovery_endpoint_ ()
00022   , default_init_ref_ (TAO_DEFAULT_INIT_REFERENCE_INITIALIZER)
00023   , sock_rcvbuf_size_ (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00024   , sock_sndbuf_size_ (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00025   , nodelay_ (1)
00026   , sock_keepalive_ (0)
00027   , sock_dontroute_ (0)
00028   , cdr_memcpy_tradeoff_ (ACE_DEFAULT_CDR_MEMCPY_TRADEOFF)
00029   , max_message_size_ (0) // Disable outgoing GIOP fragments by default
00030   , use_dotted_decimal_addresses_ (0)
00031   , cache_incoming_by_dotted_decimal_address_ (0)
00032   , linger_ (-1)
00033   , accept_error_delay_ (0)
00034   , std_profile_components_ (1)
00035   , ace_sched_policy_ (ACE_SCHED_OTHER)
00036   , sched_policy_ (THR_SCHED_DEFAULT)
00037   , scope_policy_ (THR_SCOPE_PROCESS)
00038   , single_read_optimization_ (1)
00039   , shared_profile_ (0)
00040   , use_parallel_connects_ (false)
00041   , parallel_connect_delay_ (0)
00042   , pref_network_ ()
00043   , disable_rt_collocation_resolver_ (false)
00044   , enforce_preferred_interfaces_ (false)
00045 #if defined (ACE_HAS_IPV6)
00046   , prefer_ipv6_interfaces_ (false)
00047   , connect_ipv6_only_ (false)
00048   , use_ipv6_link_local_ (false)
00049 #endif /* ACE_HAS_IPV6 */
00050   , negotiate_codesets_ (true)
00051   , ami_collication_ (true)
00052   , protocols_hooks_name_ ("Protocols_Hooks")
00053   , stub_factory_name_ ("Default_Stub_Factory")
00054   , endpoint_selector_factory_name_ ("Default_Endpoint_Selector_Factory")
00055   , thread_lane_resources_manager_factory_name_ ("Default_Thread_Lane_Resources_Manager_Factory")
00056   , poa_factory_name_ ("TAO_Object_Adapter_Factory")
00057   , poa_factory_directive_
00058       (ACE_TEXT_ALWAYS_CHAR
00059         (ACE_DYNAMIC_SERVICE_DIRECTIVE("TAO_Object_Adapter_Factory",
00060                                        "TAO_PortableServer",
00061                                        "_make_TAO_Object_Adapter_Factory",
00062                                        "")))
00063   , collocation_resolver_name_ ("Default_Collocation_Resolver")
00064 {
00065   for (int i = 0; i != TAO_NO_OF_MCAST_SERVICES; ++i)
00066     {
00067       this->service_port_[i] = 0;
00068     }
00069 }
00070 
00071 void
00072 TAO_ORB_Parameters::get_endpoint_set (const ACE_CString &lane,
00073                                       TAO_EndpointSet &endpoint_set)
00074 {
00075   // Look for the lane in the endpoints map.
00076   endpoints_map_type::iterator const endpoints =
00077     this->endpoints_map_.find (lane);
00078 
00079   // If lane is not in the map, endpoint_set remains empty
00080   if (endpoints == this->endpoints_map_.end ())
00081     return;
00082 
00083   // At this point, the parsing should not fail since they have been
00084   // parsed successfully before.
00085   int const result =
00086     this->parse_and_add_endpoints ((*endpoints).second, endpoint_set);
00087 
00088   ACE_ASSERT (result == 0);
00089   ACE_UNUSED_ARG (result);
00090 }
00091 
00092 int
00093 TAO_ORB_Parameters::add_endpoints (const ACE_CString &lane,
00094                                    const ACE_CString &additional_endpoints)
00095 {
00096   TAO_EndpointSet endpoint_set;
00097 
00098   // Parse the additional endpoints.
00099   int const result =
00100     this->parse_and_add_endpoints (additional_endpoints, endpoint_set);
00101 
00102   // Parse failure.
00103   if (result != 0)
00104     return result;
00105 
00106   // Look for the lane in the endpoints map.
00107   //
00108   // Return reference to endpoints string corresponding to lane
00109   // string.  If none, a default constructed string is inserted into
00110   // the map and returned.
00111   ACE_CString & existing_endpoints = this->endpoints_map_[lane];
00112 
00113   // Create the resulting endpoints string.
00114   if (existing_endpoints.length () != 0)
00115     {
00116       existing_endpoints += ";";
00117     }
00118 
00119   existing_endpoints += additional_endpoints;
00120 
00121   return 0;
00122 }
00123 
00124 int
00125 TAO_ORB_Parameters::parse_and_add_endpoints (const ACE_CString &endpoints,
00126                                              TAO_EndpointSet &endpoint_set)
00127 {
00128   // Parse the string into seperate endpoints, where `endpoints' is of
00129   // the form:
00130   //
00131   //    protocol1://V,v@addr1,...,addrN;protocol2://addr1,...,W.w@addrN;...
00132   //
00133   // A single endpoint, instead of several, can be added just as well.
00134 
00135   static char const endpoints_delimiter = ';';
00136 
00137   size_t const length = endpoints.length ();
00138 
00139   if (endpoints[0] == endpoints_delimiter ||
00140       endpoints[length - 1] == endpoints_delimiter)
00141     {
00142       return -1;
00143       // Failure: endpoints string has an empty endpoint at the
00144       // beginning or the end of the string
00145       // (e.g. ";uiop://foo;iiop://1.3@bar")
00146     }
00147 
00148   int status = 0;
00149   // Return code:  0 = success,  -1 = failure
00150 
00151   if (length > 0)
00152     {
00153       int endpoints_count = 1;
00154 
00155       for (size_t j = 0; j != length; ++j)
00156         {
00157           if (endpoints[j] == endpoints_delimiter)
00158             {
00159               ++endpoints_count;
00160             }
00161         }
00162 
00163       ssize_t begin = 0;
00164       ssize_t end = endpoints.find (endpoints_delimiter);
00165 
00166       for (int i = 0; i < endpoints_count; ++i)
00167         {
00168           if (end == 0)
00169             {
00170               // Handle case where two consecutive endpoints `;;'
00171               // delimiters are found within the endpoints set.
00172               //
00173               // Is it enough to just skip over it or should we return an
00174               // error?
00175               continue;
00176             }
00177 
00178           ACE_CString const endpt =
00179             endpoints.substring (begin, end - begin);
00180           // The substring call will work even if `end' is equal to
00181           // ACE_CString::npos since that will just extract the substring
00182           // from the offset `begin' to the end of the string.
00183 
00184           // Check for a valid URL style endpoint set
00185           ACE_CString::size_type const check_offset = endpt.find ("://");
00186 
00187           if (check_offset > 0 &&
00188               check_offset != endpt.npos)
00189             {
00190               endpoint_set.enqueue_tail (endpt);
00191               // Insert endpoint into list
00192             }
00193           else
00194             {
00195               status = -1;  // Error: invalid URL style endpoint set
00196             }
00197 
00198           begin = end + 1;
00199           end = endpoints.find (endpoints_delimiter, begin);
00200         }
00201     }
00202   else
00203     {
00204       status = -1;
00205       // Failure:  Empty string
00206     }
00207 
00208   return status;
00209 }
00210 
00211 bool
00212 TAO_ORB_Parameters::preferred_interfaces (const char *s)
00213 {
00214   // Validates that s contains one or more comma separated
00215   // interfaces each consisting of a string with a single
00216   // assignment separator ('=' or ':')
00217   // Any other char is legal, although '*' and '?' will be
00218   // treated as wildcards.
00219   const char* p = s;
00220   bool expect_assign = false;
00221   bool expect_comma = false;
00222   bool expect_char = true;
00223   bool expect_wild = true;
00224   bool found_remote = false;
00225   while (*p != 0)
00226   {
00227     switch (*p)
00228     {
00229 #if !defined (ACE_HAS_IPV6)
00230     // Can't use this as assignment operator when IPv6 decimal
00231     // addresses may be involved.
00232     case ':':
00233 #endif /* ACE_HAS_IPV6 */
00234     case '=':
00235       if (! expect_assign)
00236         return false;
00237       found_remote = true;
00238       expect_assign = false;
00239       expect_char = true;
00240       expect_comma = false;
00241       expect_wild = true;
00242       break;
00243     case ',':
00244       if (! expect_comma)
00245         return false;
00246       found_remote = false;
00247       expect_assign = false;
00248       expect_char = true;
00249       expect_comma = false;
00250       expect_wild = true;
00251       break;
00252     case '*':
00253     case '?':
00254       if (! expect_wild)
00255         return false;
00256       expect_assign = ! found_remote;
00257       expect_char = true;
00258       expect_comma = found_remote;
00259       expect_wild = false;
00260       break;
00261     default:
00262       if (! expect_char)
00263         return false;
00264       expect_assign = ! found_remote;
00265       expect_char = true;
00266       expect_comma = found_remote;
00267       expect_wild = true;
00268       break;
00269     }
00270     ++p;
00271     }
00272   if (!expect_comma || expect_assign)
00273     return false;
00274 
00275   this->pref_network_ = s;
00276 
00277   return true;
00278 }
00279 
00280 const char *
00281 TAO_ORB_Parameters::preferred_interfaces (void) const
00282 {
00283   return this->pref_network_.c_str ();
00284 }
00285 
00286 void
00287 TAO_ORB_Parameters::enforce_pref_interfaces (bool p)
00288 {
00289   this->enforce_preferred_interfaces_ = p;
00290 }
00291 
00292 bool
00293 TAO_ORB_Parameters::enforce_pref_interfaces (void) const
00294 {
00295   return this->enforce_preferred_interfaces_;
00296 }
00297 
00298 #if defined (ACE_HAS_IPV6)
00299 void
00300 TAO_ORB_Parameters::prefer_ipv6_interfaces (bool p)
00301 {
00302   this->prefer_ipv6_interfaces_ = p;
00303 }
00304 
00305 bool
00306 TAO_ORB_Parameters::prefer_ipv6_interfaces (void) const
00307 {
00308   return this->prefer_ipv6_interfaces_;
00309 }
00310 
00311 void
00312 TAO_ORB_Parameters::connect_ipv6_only (bool p)
00313 {
00314   this->connect_ipv6_only_ = p;
00315 }
00316 
00317 bool
00318 TAO_ORB_Parameters::connect_ipv6_only (void) const
00319 {
00320   return this->connect_ipv6_only_;
00321 }
00322 
00323 void
00324 TAO_ORB_Parameters::use_ipv6_link_local (bool p)
00325 {
00326   this->use_ipv6_link_local_ = p;
00327 }
00328 
00329 bool
00330 TAO_ORB_Parameters::use_ipv6_link_local (void) const
00331 {
00332   return this->use_ipv6_link_local_;
00333 }
00334 #endif /* ACE_HAS_IPV6 */
00335 
00336 void
00337 TAO_ORB_Parameters::protocols_hooks_name (const char *s)
00338 {
00339   this->protocols_hooks_name_ = s;
00340 }
00341 
00342 const char *
00343 TAO_ORB_Parameters::protocols_hooks_name (void) const
00344 {
00345   return this->protocols_hooks_name_.c_str ();
00346 }
00347 
00348 void
00349 TAO_ORB_Parameters::thread_lane_resources_manager_factory_name (const char *s)
00350 {
00351   this->thread_lane_resources_manager_factory_name_ = s;
00352 }
00353 
00354 const char *
00355 TAO_ORB_Parameters::thread_lane_resources_manager_factory_name (void) const
00356 {
00357   return this->thread_lane_resources_manager_factory_name_.c_str ();
00358 }
00359 
00360 void
00361 TAO_ORB_Parameters::stub_factory_name (const char *s)
00362 {
00363   this->stub_factory_name_ = s;
00364 }
00365 
00366 const char *
00367 TAO_ORB_Parameters::stub_factory_name (void) const
00368 {
00369   return this->stub_factory_name_.c_str ();
00370 }
00371 
00372 void
00373 TAO_ORB_Parameters::poa_factory_name (const char *s)
00374 {
00375   this->poa_factory_name_ = s;
00376 }
00377 
00378 const char *
00379 TAO_ORB_Parameters::poa_factory_name (void) const
00380 {
00381   return this->poa_factory_name_.c_str ();
00382 }
00383 
00384 void
00385 TAO_ORB_Parameters::poa_factory_directive (const char *s)
00386 {
00387   this->poa_factory_directive_ = s;
00388 }
00389 
00390 const char *
00391 TAO_ORB_Parameters::poa_factory_directive (void) const
00392 {
00393   return this->poa_factory_directive_.c_str ();
00394 }
00395 
00396 void
00397 TAO_ORB_Parameters::endpoint_selector_factory_name (const char *s)
00398 {
00399   this->endpoint_selector_factory_name_ = s;
00400 }
00401 
00402 const char *
00403 TAO_ORB_Parameters::endpoint_selector_factory_name (void) const
00404 {
00405   return this->endpoint_selector_factory_name_.c_str ();
00406 }
00407 
00408 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:37:52 2010 for TAO by  doxygen 1.4.7