00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Naming_Server.h 00006 * 00007 * $Id: Naming_Server.h 81142 2008-03-28 14:36:30Z elliott_c $ 00008 * 00009 * Implement wrappers useful to Naming Service servers. 00010 * 00011 * 00012 * @author Nagarajan Surendran (naga@cs.wustl.edu) 00013 * @author Matt Braun <mjb2@cs.wustl.edu> 00014 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>. 00015 */ 00016 //============================================================================= 00017 00018 00019 #ifndef TAO_NAMING_SERVER_H 00020 #define TAO_NAMING_SERVER_H 00021 #include /**/ "ace/pre.h" 00022 00023 #include "tao/ORB.h" 00024 #include "orbsvcs/CosNamingC.h" 00025 #include "orbsvcs/IOR_Multicast.h" 00026 #include "orbsvcs/Naming/Naming_Context_Interface.h" 00027 #include "orbsvcs/Naming/nsconf.h" 00028 00029 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00030 00031 #if !defined (CORBA_E_MICRO) 00032 // Forward decl; 00033 class TAO_Persistent_Context_Index; 00034 class TAO_Storable_Naming_Context_Activator; 00035 #endif /* !CORBA_E_MICRO */ 00036 00037 /** 00038 * @class TAO_Naming_Server 00039 * 00040 * @brief Defines a wrapper class that holds the root Naming Context. 00041 * 00042 * This class either finds an existing Naming Service (if the 00043 * <resolve_for_existing_naming_service> flag is set) or creates 00044 * one (if <resolve_for_existing_naming_service> flag isn't set or 00045 * Naming Service was not found). This class also defines the 00046 * operator-> so that <NamingContext> functions like <bind>, 00047 * <unbind> .. can be called directly on a <TAO_Naming_Server> 00048 * object, and be forwareded to the root Naming Context. 00049 * This class is intended to simplify 00050 * programs that want to play the role of a Naming Service 00051 * server. To simplify programs that want to play the role of 00052 * Naming Service clients, use <TAO_Naming_Client>. 00053 * If a Naming Service is created locally, a TAO_IOR_Multicast 00054 * event handler is created and installed on the ORB's reactor. 00055 * This event handler allows other clients on the network to 00056 * discover and use this Naming Service. 00057 * Event handler listens on a multicast port for messages from 00058 * clients looking for a Naming Service, and sends back the ior 00059 * of the root Naming Context. For more information on how this 00060 * bootstraping through a multicast process works, check out 00061 * orbsvcs/orbsvcs/TAO_IOR_Multicast.*, implementation of 00062 * <resolve_initial_references>, and orbsvcs/Naming/README. 00063 */ 00064 class TAO_Naming_Serv_Export TAO_Naming_Server 00065 { 00066 public: 00067 /// Default constructor. 00068 TAO_Naming_Server (void); 00069 00070 /** 00071 * Constructor. Attempts to find an existing Naming Service if 00072 * <resolve_for_existing_naming_service> is set to true. If it is 00073 * false, or no Naming Service was found during a <timeout> period, 00074 * create the Naming Service in this process. If creating the 00075 * Naming Service locally, make the root context of size 00076 * <context_size>, register it under the <poa>, and make the Naming 00077 * Service persistent if <persistence_location> is not 0. 00078 * (<persistence_location> specifies name of the file to use for 00079 * persistent storage, <base_addr> specifies the address used for 00080 * memory mapping <persistent_location> file). 00081 * If <enable_multicast> is not zero then the service will respond 00082 * to multicast location queries. 00083 */ 00084 TAO_Naming_Server (CORBA::ORB_ptr orb, 00085 PortableServer::POA_ptr poa, 00086 size_t context_size = ACE_DEFAULT_MAP_SIZE, 00087 ACE_Time_Value *timeout = 0, 00088 int resolve_for_existing_naming_service = 1, 00089 const ACE_TCHAR *persistence_location = 0, 00090 void *base_addr = TAO_NAMING_BASE_ADDR, 00091 int enable_multicast = 1, 00092 int use_storable_context = 0, 00093 int round_trip_timeout = 0, 00094 int use_round_trip_timeout = 0); 00095 00096 /** 00097 * Initializer. Attempts to find an existing Naming Service if 00098 * <resolve_for_existing_naming_service> is set to true. If it is 00099 * false, or no Naming Service was found during a <timeout> period, 00100 * create the Naming Service in this process. If creating the 00101 * Naming Service locally, make the root context of size 00102 * <context_size>, register it under the <poa>, and make the Naming 00103 * Service persistent if <persistence_location> is not 0. 00104 * (<persistence_location> specifies name of the file to use for 00105 * persistent storage, <base_addr> specifies the address used for 00106 * memory mapping <persistent_location> file). 00107 * If <enable_multicast> is not zero then the service will respond 00108 * to multicast location queries. 00109 */ 00110 int init (CORBA::ORB_ptr orb, 00111 PortableServer::POA_ptr poa, 00112 size_t context_size = ACE_DEFAULT_MAP_SIZE, 00113 ACE_Time_Value *timeout = 0, 00114 int resolve_for_existing_naming_service = 1, 00115 const ACE_TCHAR *persistence_location = 0, 00116 void *base_addr = TAO_NAMING_BASE_ADDR, 00117 int enable_multicast = 1, 00118 int use_storable_context = 0, 00119 int round_trip_timeout = 0, 00120 int use_round_trip_timeout = 0); 00121 00122 /// Initialize the Naming Service with the command line arguments and 00123 /// the ORB. 00124 int init_with_orb (int argc, ACE_TCHAR *argv [], CORBA::ORB_ptr orb); 00125 00126 /// Destroy the child POA created in <init_with_orb> 00127 int fini (void); 00128 00129 /// Destructor. 00130 ~TAO_Naming_Server (void); 00131 00132 /// Returns the IOR of the naming service. 00133 char * naming_service_ior (void); 00134 00135 /// Returns a <NamingContext_ptr> for the root Naming Context. 00136 CosNaming::NamingContext_ptr operator-> (void) const; 00137 00138 protected: 00139 /** 00140 * Helper method: create Naming Service locally. 00141 * Make the root context of size 00142 * <context_size>, register it under the <root_poa>, and make the Naming 00143 * Service persistent if <persistence_location> is not 0. 00144 * (<persistence_location> specifies name of the file to use for 00145 * persistent storage). 00146 * If <enable_multicast> is not zero then the service will respond 00147 * to multicast location queries. 00148 */ 00149 int init_new_naming (CORBA::ORB_ptr orb, 00150 PortableServer::POA_ptr root_poa, 00151 const ACE_TCHAR *persistence_location, 00152 void *base_addr, 00153 size_t context_size, 00154 int enable_multicast, 00155 int use_storable_context, 00156 int round_trip_timeout = 0, 00157 int use_round_trip_timeout = 0); 00158 00159 /// parses the arguments. 00160 int parse_args (int argc, ACE_TCHAR *argv[]); 00161 00162 /// Root NamingContext_ptr. 00163 CosNaming::NamingContext_var naming_context_; 00164 00165 /// The ior_multicast event handler. 00166 TAO_IOR_Multicast *ior_multicast_; 00167 00168 /// The IOR string of the root naming context. 00169 CORBA::String_var naming_service_ior_; 00170 00171 /// The ORB 00172 CORBA::ORB_var orb_; 00173 00174 /// The Root POA. 00175 PortableServer::POA_var root_poa_; 00176 00177 /// The Naming Service POA. 00178 PortableServer::POA_var ns_poa_; 00179 00180 /// File to output the Naming Service IOR. 00181 const ACE_TCHAR *ior_file_name_; 00182 00183 /// File to output the process id. 00184 const ACE_TCHAR *pid_file_name_; 00185 00186 /** 00187 * Size of the hash_table allocated upon the creation of the Naming 00188 * Service context (if one is created). Note: all the contexts 00189 * created under the given context will use the same size for their 00190 * initial hash table allocations. 00191 */ 00192 size_t context_size_; 00193 00194 /// If not zero multicast is enabled. 00195 int multicast_; 00196 00197 #if !defined (CORBA_E_MICRO) 00198 /** 00199 * Pointer to the object used to create/initialize 00200 * the Naming Service when local persistent Naming Service is 00201 * desired. 00202 */ 00203 TAO_Persistent_Context_Index *context_index_; 00204 00205 /// Path to the file to be used to store/read in Naming Service 00206 /// persistent state. 00207 const ACE_TCHAR *persistence_file_name_; 00208 00209 /// Address to be used for memory mapping Naming Service state file, 00210 /// identified by the <persistence_file_name_>. 00211 void *base_address_; 00212 00213 /// If not zero use flat file persistence 00214 int use_storable_context_; 00215 00216 /** 00217 * If not zero use servant activator that uses flat file persistence. 00218 */ 00219 int use_servant_activator_; 00220 00221 /** 00222 * Need to retain the servant activator between calls to 00223 * init_with_orb() and init_new_naming(). 00224 */ 00225 TAO_Storable_Naming_Context_Activator *servant_activator_; 00226 #endif /* !CORBA_E_MICRO */ 00227 00228 /** 00229 * If not zero support redundant naming servers. 00230 */ 00231 int use_redundancy_; 00232 00233 // If not zero use round trip timeout policy set to value specified 00234 int round_trip_timeout_; 00235 int use_round_trip_timeout_; 00236 }; 00237 00238 TAO_END_VERSIONED_NAMESPACE_DECL 00239 00240 #include /**/ "ace/post.h" 00241 #endif /* TAO_NAMING_SERVER_H */