00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file IIOP_Acceptor.h 00006 * 00007 * $Id: IIOP_Acceptor.h 81470 2008-04-28 12:40:23Z elliott_c $ 00008 * 00009 * IIOP specific acceptor processing 00010 * 00011 * 00012 * @author Fred Kuhns <fredk@cs.wustl.edu> 00013 * @author Ossama Othman <ossama@uci.edu> 00014 */ 00015 //============================================================================= 00016 00017 00018 #ifndef TAO_IIOP_ACCEPTOR_H 00019 #define TAO_IIOP_ACCEPTOR_H 00020 00021 #include /**/ "ace/pre.h" 00022 00023 #include "tao/orbconf.h" 00024 00025 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00026 # pragma once 00027 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00028 00029 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0) 00030 00031 #include "tao/Transport_Acceptor.h" 00032 #include "tao/IIOP_Connection_Handler.h" 00033 #include "tao/Acceptor_Impl.h" 00034 #include "tao/GIOP_Message_Version.h" 00035 00036 #include "ace/SOCK_Acceptor.h" 00037 #include "ace/Acceptor.h" 00038 00039 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00040 00041 /** 00042 * @class TAO_IIOP_Acceptor 00043 * 00044 * @brief TAO_IIOP_Acceptor 00045 * 00046 * The IIOP-specific bridge class for the concrete acceptor. 00047 */ 00048 class TAO_Export TAO_IIOP_Acceptor : public TAO_Acceptor 00049 { 00050 public: 00051 00052 /* 00053 * Hook that marks begining of all concrete i.e. non virtual 00054 * methods implemented in IIOP_Acceptor class. 00055 */ 00056 //@@ TAO_ACCEPTOR_SPL_CONCRETE_METHODS_COPY_HOOK_START 00057 00058 /// Constructor. 00059 TAO_IIOP_Acceptor (void); 00060 00061 /// Destructor. 00062 ~TAO_IIOP_Acceptor (void); 00063 00064 /// @@ Helper method for the implementation repository, should go 00065 /// away 00066 const ACE_INET_Addr& address (void) const; 00067 00068 /// Returns the array of endpoints in this acceptor 00069 const ACE_INET_Addr *endpoints (void); 00070 00071 /// Returns address for default endpoint 00072 const ACE_INET_Addr& default_address (void) const; 00073 00074 /// Set address for default endpoint 00075 void set_default_address (const ACE_INET_Addr& addr); 00076 00077 typedef TAO_Strategy_Acceptor<TAO_IIOP_Connection_Handler, ACE_SOCK_ACCEPTOR> BASE_ACCEPTOR; 00078 typedef TAO_Creation_Strategy<TAO_IIOP_Connection_Handler> CREATION_STRATEGY; 00079 typedef TAO_Concurrency_Strategy<TAO_IIOP_Connection_Handler> CONCURRENCY_STRATEGY; 00080 typedef TAO_Accept_Strategy<TAO_IIOP_Connection_Handler, ACE_SOCK_ACCEPTOR> ACCEPT_STRATEGY; 00081 00082 //@@ TAO_ACCEPTOR_SPL_CONCRETE_METHODS_COPY_HOOK_END 00083 00084 /** 00085 * The TAO_Acceptor methods, check the documentation in 00086 * Transport_Acceptor.h for details. 00087 */ 00088 virtual int open (TAO_ORB_Core *orb_core, 00089 ACE_Reactor *reactor, 00090 int version_major, 00091 int version_minor, 00092 const char *address, 00093 const char *options = 0); 00094 virtual int open_default (TAO_ORB_Core *orb_core, 00095 ACE_Reactor *reactor, 00096 int version_major, 00097 int version_minor, 00098 const char *options = 0); 00099 virtual int close (void); 00100 virtual int create_profile (const TAO::ObjectKey &object_key, 00101 TAO_MProfile &mprofile, 00102 CORBA::Short priority); 00103 virtual int is_collocated (const TAO_Endpoint *endpoint); 00104 virtual CORBA::ULong endpoint_count (void); 00105 00106 virtual int object_key (IOP::TaggedProfile &profile, 00107 TAO::ObjectKey &key); 00108 00109 //@@ TAO_ACCEPTOR_SPL_CONCRETE_METHODS_COPY_HOOK_START 00110 /** 00111 * Set the host name for the given addr. 00112 * A hostname may be forced by using specified_hostname. This 00113 * is useful if the given address corresponds to more than one 00114 * hostname and the desired one cannot be determined in any 00115 * other way. 00116 * This method is used both when constructing IOR endpoints and LPL 00117 * (listen point lists). 00118 * 00119 * The algorithm used is: 00120 * - If hostname_in_ior_ has been set, it is used "as is"; 00121 * - else if use_dotted_decimal_addresses_ is set, the text representaion 00122 * of the IP is used; 00123 * - else if specified_hostname is given, it used "as is"; 00124 * - else a reverse (address to name) lookup is used to obtain the 00125 * hostname or the IP if no reverse mapping exists. 00126 */ 00127 virtual int hostname (TAO_ORB_Core *orb_core, 00128 ACE_INET_Addr &addr, 00129 char *&host, 00130 const char *specified_hostname = 0); 00131 00132 protected: 00133 00134 /** 00135 * Helper method 00136 * Clear out 'addr' & 'specified_hostname' and initialize them based 00137 * upon 'address'. If a non-zero pointer is passed in for def_type, 00138 * this will be set to AF_INET6 if IPv6 support is enabled and 00139 * supplied hostname is either [] or [::]. It will be set to AF_INET 00140 * if the hostname is 0.0.0.0, otherwise it is set to 00141 * AF_UNSPEC. This value is then passed to probe_interfaces by open. 00142 */ 00143 int 00144 parse_address (const char *address, 00145 ACE_INET_Addr &addr, 00146 ACE_CString &specified_hostname, 00147 int *def_type = 0); 00148 00149 /** 00150 * Set the host name for the given address using the dotted decimal 00151 * format. 00152 */ 00153 int dotted_decimal_address (ACE_INET_Addr &addr, 00154 char *&host); 00155 00156 /** 00157 * Implement the common part of the open*() methods. This method is 00158 * virtual to allow a derived class implementation to be invoked 00159 * instead. 00160 */ 00161 virtual int open_i (const ACE_INET_Addr &addr, 00162 ACE_Reactor *reactor); 00163 00164 /** 00165 * Probe the system for available network interfaces, and initialize 00166 * the <addrs_> array with an ACE_INET_Addr for each network 00167 * interface. The port for each initialized ACE_INET_Addr will be 00168 * set in the open_i() method. This method only gets invoked when 00169 * no explicit hostname is provided in the specified endpoint. 00170 * 00171 * The optional argument def_type is used to constrain the resulting 00172 * list of interfaces to be either only IPv6 or IPv4, or both, when 00173 * ACE_HAS_IPV6 is enabled and the source endpoint was an explicitly 00174 * declared wildcard. 00175 */ 00176 int probe_interfaces (TAO_ORB_Core *orb_core, int def_type = AF_UNSPEC); 00177 00178 /** 00179 * Parse protocol specific options. 00180 * 00181 * Currently supported: 00182 * portspan -- specifies the range of ports over which the acceptor 00183 * should scan looking for a free port (this is convenient 00184 * for situations where you might normally use an ephemeral 00185 * port but can't because you're behind a firewall and don't 00186 * want to permit passage on all ephemeral ports) 00187 */ 00188 int parse_options (const char *options); 00189 00190 /** 00191 * Parse options splits the options list in to an argv array. This 00192 * allows manipulation of the list in a manner similar to 00193 * orb_init. By moving the consumed args to the tail of the list and 00194 * reducing the argc count, the base parse_options_i can be called 00195 * by derived parse_options_i. Method returns -1 if an ill-formed or 00196 * otherwise bogus arg is encountered. The only strictly bogus arg 00197 * was priority, which was a holdover from the early RT IIOP 00198 * implementations. an ill-formed option is one which is missing an 00199 * equal sign or something to the left of it. 00200 */ 00201 virtual int parse_options_i (int &argc, ACE_CString ** argv); 00202 00203 /// Helper method to add a new profile to the mprofile for 00204 /// each endpoint. 00205 int create_new_profile (const TAO::ObjectKey &object_key, 00206 TAO_MProfile &mprofile, 00207 CORBA::Short priority); 00208 00209 /// Helper method to create a profile that contains all of 00210 /// our endpoints. 00211 int create_shared_profile (const TAO::ObjectKey &object_key, 00212 TAO_MProfile &mprofile, 00213 CORBA::Short priority); 00214 //@@ TAO_ACCEPTOR_SPL_CONCRETE_METHODS_COPY_HOOK_END 00215 00216 //@@ TAO_ACCEPTOR_SPL_DATA_MEMBERS_COPY_HOOK_START 00217 protected: 00218 00219 /// Array of ACE_INET_Addr instances, each one corresponding to a 00220 /// given network interface. 00221 ACE_INET_Addr *addrs_; 00222 00223 /** 00224 * The number of ports over which the acceptor should search (starting 00225 * at the port specified in each element of addrs_) for an available 00226 * port. This is specified via the "portspan=" option to the endpoint. 00227 */ 00228 unsigned short port_span_; 00229 00230 /** 00231 * Cache the information about the endpoints serviced by this 00232 * acceptor. 00233 * There may in fact be multiple hostnames for this endpoint. For 00234 * example, if the IP address is INADDR_ANY (0.0.0.0) then there 00235 * will be possibly a different hostname for each interface. 00236 */ 00237 char **hosts_; 00238 00239 /** 00240 * Override the hostname used in the ORBEndPoint. 00241 */ 00242 char *hostname_in_ior_; 00243 00244 /// The number of host names cached in the hosts_ array (equivalent 00245 /// to the number of endpoints opened by this Acceptor). 00246 CORBA::ULong endpoint_count_; 00247 00248 /** 00249 * The GIOP version for this endpoint 00250 * @@ Theoretically they shouldn't be here!! We need to look at a 00251 * way to move this out 00252 */ 00253 TAO_GIOP_Message_Version version_; 00254 00255 /// ORB Core. 00256 TAO_ORB_Core *orb_core_; 00257 00258 /// Enable socket option SO_REUSEADDR to be set 00259 int reuse_addr_; 00260 00261 /// Address for default endpoint 00262 ACE_INET_Addr default_address_; 00263 00264 private: 00265 00266 /// The concrete acceptor, as a pointer to it's base class. 00267 BASE_ACCEPTOR base_acceptor_; 00268 00269 /// Acceptor strategies. 00270 CREATION_STRATEGY *creation_strategy_; 00271 CONCURRENCY_STRATEGY *concurrency_strategy_; 00272 ACCEPT_STRATEGY *accept_strategy_; 00273 00274 //@@ TAO_ACCEPTOR_SPL_DATA_MEMBERS_COPY_HOOK_END 00275 }; 00276 00277 TAO_END_VERSIONED_NAMESPACE_DECL 00278 00279 #if defined(__ACE_INLINE__) 00280 #include "tao/IIOP_Acceptor.inl" 00281 #endif /* __ACE_INLINE__ */ 00282 00283 #endif /* TAO_HAS_IIOP && TAO_HAS_IIOP != 0 */ 00284 00285 #include /**/ "ace/post.h" 00286 #endif /* TAO_IIOP_ACCEPTOR_H */