params.cpp

Go to the documentation of this file.
00001 // params.cpp,v 1.85 2006/04/27 03:08:23 mesnier_p Exp
00002 
00003 #include "tao/params.h"
00004 #include "tao/orbconf.h"
00005 
00006 #if !defined (__ACE_INLINE__)
00007 # include "tao/params.i"
00008 #endif /* __ACE_INLINE__ */
00009 
00010 #include "ace/OS_NS_Thread.h"
00011 
00012 
00013 ACE_RCSID (tao,
00014            params,
00015            "params.cpp,v 1.85 2006/04/27 03:08:23 mesnier_p Exp")
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_lite_protocol_ (0)
00031   , use_dotted_decimal_addresses_ (0)
00032   , cache_incoming_by_dotted_decimal_address_ (0)
00033   , linger_ (-1)
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 #endif /* ACE_HAS_IPV6 */
00049   , negotiate_codesets_ (true)
00050 {
00051   for (int i = 0; i != TAO_NO_OF_MCAST_SERVICES; ++i)
00052     {
00053       this->service_port_[i] = 0;
00054     }
00055 }
00056 
00057 void
00058 TAO_ORB_Parameters::get_endpoint_set (const ACE_CString &lane,
00059                                       TAO_EndpointSet &endpoint_set)
00060 {
00061   // Look for the lane in the endpoints map.
00062   endpoints_map_type::iterator const endpoints =
00063     this->endpoints_map_.find (lane);
00064 
00065   // If lane is not in the map, <endpoint_set> remains empty
00066   if (endpoints == this->endpoints_map_.end ())
00067     return;
00068 
00069   // At this point, the parsing should not fail since they have been
00070   // parsed successfully before.
00071   int const result =
00072     this->parse_and_add_endpoints ((*endpoints).second,
00073                                    endpoint_set);
00074 
00075   ACE_ASSERT (result == 0);
00076   ACE_UNUSED_ARG (result);
00077 }
00078 
00079 int
00080 TAO_ORB_Parameters::add_endpoints (const ACE_CString &lane,
00081                                    const ACE_CString &additional_endpoints)
00082 {
00083   TAO_EndpointSet endpoint_set;
00084 
00085   // Parse the additional endpoints.
00086   int const result =
00087     this->parse_and_add_endpoints (additional_endpoints,
00088                                    endpoint_set);
00089 
00090   // Parse failure.
00091   if (result != 0)
00092     return result;
00093 
00094   // Look for the lane in the endpoints map.
00095   //
00096   // Return reference to endpoints string corresponding to lane
00097   // string.  If none, a default constructed string is inserted into
00098   // the map and returned.
00099   ACE_CString & existing_endpoints = this->endpoints_map_[lane];
00100 
00101   // Create the resulting endpoints string.
00102   if (existing_endpoints.length () != 0)
00103     {
00104       existing_endpoints += ";";
00105     }
00106 
00107   existing_endpoints += additional_endpoints;
00108 
00109   return 0;
00110 }
00111 
00112 int
00113 TAO_ORB_Parameters::parse_and_add_endpoints (const ACE_CString &endpoints,
00114                                              TAO_EndpointSet &endpoint_set)
00115 {
00116   // Parse the string into seperate endpoints, where `endpoints' is of
00117   // the form:
00118   //
00119   //    protocol1://V,v@addr1,...,addrN;protocol2://addr1,...,W.w@addrN;...
00120   //
00121   // A single endpoint, instead of several, can be added just as well.
00122 
00123   static char const endpoints_delimiter = ';';
00124 
00125   size_t const length = endpoints.length ();
00126 
00127   if (endpoints[0] == endpoints_delimiter ||
00128       endpoints[length - 1] == endpoints_delimiter)
00129     {
00130       return -1;
00131       // Failure: endpoints string has an empty endpoint at the
00132       // beginning or the end of the string
00133       // (e.g. ";uiop://foo;iiop://1.3@bar")
00134     }
00135 
00136   int status = 0;
00137   // Return code:  0 = success,  -1 = failure
00138 
00139   if (length > 0)
00140     {
00141       int endpoints_count = 1;
00142 
00143       for (size_t j = 0; j != length; ++j)
00144         {
00145           if (endpoints[j] == endpoints_delimiter)
00146             {
00147               ++endpoints_count;
00148             }
00149         }
00150 
00151       ssize_t begin = 0;
00152       ssize_t end = endpoints.find (endpoints_delimiter);
00153 
00154       for (int i = 0; i < endpoints_count; ++i)
00155         {
00156           if (end == 0)
00157             {
00158               // Handle case where two consecutive endpoints `;;'
00159               // delimiters are found within the endpoints set.
00160               //
00161               // Is it enough to just skip over it or should we return an
00162               // error?
00163               continue;
00164             }
00165 
00166           ACE_CString const endpt =
00167             endpoints.substring (begin, end - begin);
00168           // The substring call will work even if `end' is equal to
00169           // ACE_CString::npos since that will just extract the substring
00170           // from the offset `begin' to the end of the string.
00171 
00172           // Check for a valid URL style endpoint set
00173           ssize_t const check_offset = endpt.find ("://");
00174 
00175           if (check_offset > 0 &&
00176               check_offset != endpt.npos)
00177             {
00178               endpoint_set.enqueue_tail (endpt);
00179               // Insert endpoint into list
00180             }
00181           else
00182             {
00183               status = -1;  // Error: invalid URL style endpoint set
00184             }
00185 
00186           begin = end + 1;
00187           end = endpoints.find (endpoints_delimiter, begin);
00188         }
00189     }
00190   else
00191     {
00192       status = -1;
00193       // Failure:  Empty string
00194     }
00195 
00196   return status;
00197 }
00198 
00199 bool
00200 TAO_ORB_Parameters::preferred_interfaces (const char *s)
00201 {
00202   // Validates that s contains one or more comma separated
00203   // interfaces each consisting of a string with a single
00204   // assignment separator ('=' or ':')
00205   // Any other char is legal, although '*' and '?' will be
00206   // treated as wildcards.
00207   const char* p = s;
00208   bool expect_assign = false;
00209   bool expect_comma = false;
00210   bool expect_char = true;
00211   bool expect_wild = true;
00212   bool found_remote = false;
00213   while (*p != 0)
00214   {
00215     switch (*p)
00216     {
00217 #if !defined (ACE_HAS_IPV6)
00218     // Can't use this as assignment operator when IPv6 decimal
00219     // addresses may be involved.
00220     case ':':
00221 #endif /* ACE_HAS_IPV6 */
00222     case '=':
00223       if (! expect_assign)
00224         return false;
00225       found_remote = true;
00226       expect_assign = false;
00227       expect_char = true;
00228       expect_comma = false;
00229       expect_wild = true;
00230       break;
00231     case ',':
00232       if (! expect_comma)
00233         return false;
00234       found_remote = false;
00235       expect_assign = false;
00236       expect_char = true;
00237       expect_comma = false;
00238       expect_wild = true;
00239       break;
00240     case '*':
00241     case '?':
00242       if (! expect_wild)
00243         return false;
00244       expect_assign = ! found_remote;
00245       expect_char = true;
00246       expect_comma = found_remote;
00247       expect_wild = false;
00248       break;
00249     default:
00250       if (! expect_char)
00251         return false;
00252       expect_assign = ! found_remote;
00253       expect_char = true;
00254       expect_comma = found_remote;
00255       expect_wild = true;
00256       break;
00257     }
00258     ++p;
00259     }
00260   if (!expect_comma || expect_assign)
00261     return false;
00262 
00263   this->pref_network_ = s;
00264 
00265   return true;
00266 }
00267 
00268 const char *
00269 TAO_ORB_Parameters::preferred_interfaces (void) const
00270 {
00271   return this->pref_network_.c_str ();
00272 }
00273 
00274 void
00275 TAO_ORB_Parameters::enforce_pref_interfaces (bool p)
00276 {
00277   this->enforce_preferred_interfaces_ = p;
00278 }
00279 
00280 bool
00281 TAO_ORB_Parameters::enforce_pref_interfaces (void) const
00282 {
00283   return this->enforce_preferred_interfaces_;
00284 }
00285 
00286 #if defined (ACE_HAS_IPV6)
00287 void
00288 TAO_ORB_Parameters::prefer_ipv6_interfaces (bool p)
00289 {
00290   this->prefer_ipv6_interfaces_ = p;
00291 }
00292 
00293 bool
00294 TAO_ORB_Parameters::prefer_ipv6_interfaces (void) const
00295 {
00296   return this->prefer_ipv6_interfaces_;
00297 }
00298 
00299 void
00300 TAO_ORB_Parameters::connect_ipv6_only (bool p)
00301 {
00302   this->connect_ipv6_only_ = p;
00303 }
00304 
00305 bool
00306 TAO_ORB_Parameters::connect_ipv6_only (void) const
00307 {
00308   return this->connect_ipv6_only_;
00309 }
00310 #endif /* ACE_HAS_IPV6 */
00311 
00312 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:19 2006 for TAO by doxygen 1.3.6