00001 // -*- C++ -*- 00002 00003 //========================================================================== 00004 /** 00005 * @file Naming_Context.h 00006 * 00007 * $Id: Naming_Context.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $ 00008 * 00009 * @author Gerhard Lenzer 00010 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00011 * @author and Prashant Jain <pjain@uci.edu> 00012 */ 00013 //========================================================================== 00014 00015 #ifndef ACE_NAMING_CONTEXT_H 00016 #define ACE_NAMING_CONTEXT_H 00017 #include "ace/pre.h" 00018 00019 #include "ace/ACE_export.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #include "ace/SString.h" 00026 #include "ace/Containers.h" 00027 #include "ace/Service_Object.h" 00028 #include "ace/Name_Proxy.h" 00029 #include "ace/Name_Space.h" 00030 00031 // Forward decl 00032 class ACE_Name_Options; 00033 00034 /** 00035 * @class ACE_Naming_Context 00036 * 00037 * @brief Maintaining accesses Name Server Databases. Allows to add 00038 * NameBindings, change them, remove them and resolve 00039 * NameBindings 00040 * 00041 * Manages a Naming Service . That represents a persistent 00042 * string to string mapping for different scopes. The scope of a 00043 * ACE_Naming_Context may be either local for the calling 00044 * process (Note : A process is hereby not identified by it's 00045 * pid, but by it's argv[0]. So different processes (in UNIX 00046 * syntax) may access the same NameBindings), global for all 00047 * processes running on one host or global for all processes on 00048 * the net (that know the address of the net name server 00049 * socket). Strings may be plain character strings or Wide 00050 * character strings. A Name Binding consists of a name string 00051 * (that's the key), a value string and an optional type string 00052 * (no wide chars). 00053 */ 00054 class ACE_Export ACE_Naming_Context : public ACE_Service_Object 00055 { 00056 public: 00057 enum Context_Scope_Type 00058 { 00059 /// Name lookup is local to the process. 00060 PROC_LOCAL, 00061 /// Name lookup is local to the node (host). 00062 NODE_LOCAL, 00063 /// Name lookup is local to the (sub)network. 00064 NET_LOCAL 00065 }; 00066 00067 // = Initialization and termination methods. 00068 /// "Do-nothing" constructor. 00069 ACE_Naming_Context (void); 00070 00071 /** 00072 * Specifies the scope of this namespace, opens and memory-maps the 00073 * associated file (if accessible) or contacts the dedicated name 00074 * server process for NET_LOCAL namespace. Note that <light> 00075 * specifies whether or not we want to use 00076 * ACE_Lite_MMap_Memory_Pool. By default we use ACE_MMap_Memory_Pool. 00077 */ 00078 ACE_Naming_Context (Context_Scope_Type scope_in, int light = 0); 00079 00080 /** 00081 * Specifies the scope of this namespace, opens and memory-maps the 00082 * associated file (if accessible) or contacts the dedicated name 00083 * server process for NET_LOCAL namespace. Note that <light> 00084 * specifies whether or not we want to use 00085 * ACE_Lite_MMap_Memory_Pool. By default we use ACE_MMap_Memory_Pool. 00086 */ 00087 int open (Context_Scope_Type scope_in = ACE_Naming_Context::PROC_LOCAL, 00088 int light = 0); 00089 00090 /// Deletes the instance of Name Space. Must be called before 00091 /// switching name spaces. 00092 int close (void); 00093 00094 /// Release all resources. Gets called by destructor and fini. 00095 int close_down (void); 00096 00097 /// destructor, do some cleanup :TBD: last dtor should "compress" 00098 /// file 00099 ~ACE_Naming_Context (void); 00100 00101 // = Dynamic initialization hooks. 00102 /// Initialize name options and naming context when dynamically 00103 /// linked. 00104 virtual int init (int argc, ACE_TCHAR *argv[]); 00105 00106 /// Close down the test when dynamically unlinked. 00107 virtual int fini (void); 00108 00109 /// Returns information about this context. 00110 virtual int info (ACE_TCHAR **strp, size_t length) const; 00111 00112 /// Returns the ACE_Name_Options associated with the Naming_Context 00113 ACE_Name_Options *name_options (void); 00114 00115 /// Bind a new name to a naming context (Wide character strings). 00116 int bind (const ACE_NS_WString &name_in, 00117 const ACE_NS_WString &value_in, 00118 const char *type_in = ""); 00119 00120 /// Bind a new name to a naming context ( character strings). 00121 int bind (const char *name_in, 00122 const char *value_in, 00123 const char *type_in = ""); 00124 00125 /** 00126 * Overwrite the value or type of an existing name in a 00127 * ACE_Naming_Context or bind a new name to the context, if it 00128 * didn't exist yet. (Wide charcter strings interface). 00129 */ 00130 int rebind (const ACE_NS_WString &name_in, 00131 const ACE_NS_WString &value_in, 00132 const char *type_in = ""); 00133 00134 /** 00135 * Overwrite the value or type of an existing name in a 00136 * ACE_Naming_Context or bind a new name to the context, if it 00137 * didn't exist yet. ( charcter strings interface) 00138 */ 00139 int rebind (const char *name_in, 00140 const char *value_in, 00141 const char *type_in = ""); 00142 00143 /// Delete a name from a ACE_Naming_Context (Wide charcter strings 00144 /// Interface). 00145 int unbind (const ACE_NS_WString &name_in); 00146 00147 /// Delete a name from a ACE_Naming_Context (character strings 00148 /// interface). 00149 int unbind (const char *name_in); 00150 00151 /// Get value and type of a given name binding (Wide chars). The 00152 /// caller is responsible for deleting both <value_out> and <type_out>! 00153 int resolve (const ACE_NS_WString &name_in, 00154 ACE_NS_WString &value_out, 00155 char *&type_out); 00156 00157 /** 00158 * Get value and type of a given name binding (Wide chars output). 00159 * The caller is responsible for deleting both <value_out> and 00160 * <type_out>! 00161 */ 00162 int resolve (const char *name_in, 00163 ACE_NS_WString &value_out, 00164 char *&type_out); 00165 00166 /// Get value and type of a given name binding ( chars ). The caller 00167 /// is responsible for deleting both <value_out> and <type_out>! 00168 int resolve (const char *name_in, 00169 char *&value_out, 00170 char *&type_out); 00171 00172 /// Get a set of names matching a specified pattern (wchars). Matching 00173 /// means the names must begin with the pattern string. 00174 int list_names (ACE_PWSTRING_SET &set_out, 00175 const ACE_NS_WString &pattern_in); 00176 00177 /// Get a set of names matching a specified pattern (chars). Matching 00178 /// means the names must begin with the pattern string. 00179 int list_names (ACE_PWSTRING_SET &set_out, 00180 const char *pattern_in); 00181 00182 /// Get a set of values matching a specified pattern (wchars). Matching 00183 /// means the values must begin with the pattern string. 00184 int list_values (ACE_PWSTRING_SET &set_out, 00185 const ACE_NS_WString &pattern_in); 00186 00187 /// Get a set of values matching a specified pattern (chars). Matching 00188 /// means the values must begin with the pattern string. 00189 int list_values (ACE_PWSTRING_SET &set_out, 00190 const char *pattern_in); 00191 00192 /// Get a set of types matching a specified pattern (wchars). Matching 00193 /// means the types must begin with the pattern string. 00194 int list_types (ACE_PWSTRING_SET &set_out, 00195 const ACE_NS_WString &pattern_in); 00196 00197 /// Get a set of types matching a specified pattern (chars). Matching 00198 /// means the types must begin with the pattern string. 00199 int list_types (ACE_PWSTRING_SET &set_out, 00200 const char *pattern_in); 00201 00202 /** 00203 * Get a set of names matching a specified pattern (wchars). Matching 00204 * means the names must begin with the pattern string. Returns the 00205 * complete binding associated each pattern match. 00206 */ 00207 virtual int list_name_entries (ACE_BINDING_SET &set_out, 00208 const ACE_NS_WString &pattern_in); 00209 00210 /** 00211 * Get a set of names matching a specified pattern (wchars). Matching 00212 * means the names must begin with the pattern string. Returns the 00213 * complete binding associated each pattern match. 00214 */ 00215 virtual int list_name_entries (ACE_BINDING_SET &set_out, 00216 const char *pattern_in); 00217 00218 /** 00219 * Get a set of values matching a specified pattern (wchars). Matching 00220 * means the values must begin with the pattern string. Returns the 00221 * complete binding associated each pattern match. 00222 */ 00223 virtual int list_value_entries (ACE_BINDING_SET &set_out, 00224 const ACE_NS_WString &pattern_in); 00225 00226 /** 00227 * Get a set of values matching a specified pattern (wchars). Matching 00228 * means the values must begin with the pattern string. Returns the 00229 * complete binding associated each pattern match. 00230 */ 00231 virtual int list_value_entries (ACE_BINDING_SET &set_out, 00232 const char *pattern_in); 00233 00234 /** 00235 * Get a set of types matching a specified pattern (wchars). Matching 00236 * means the types must begin with the pattern string. Returns the 00237 * complete binding associated each pattern match. 00238 */ 00239 virtual int list_type_entries (ACE_BINDING_SET &set_out, 00240 const ACE_NS_WString &pattern_in); 00241 00242 /** 00243 * Get a set of types matching a specified pattern (wchars). Matching 00244 * means the types must begin with the pattern string. Returns the 00245 * complete binding associated each pattern match. 00246 */ 00247 virtual int list_type_entries (ACE_BINDING_SET &set_out, 00248 const char *pattern_in); 00249 00250 /// Dump the state of the object. 00251 void dump (void); 00252 00253 private: 00254 /// Keep track of the options such as database name etc per Naming Context 00255 ACE_Name_Options *name_options_; 00256 00257 /// Name space (can be either local or remote) dynamically bound. 00258 ACE_Name_Space *name_space_; 00259 00260 /// Holds the local hostname. 00261 ACE_TCHAR hostname_[MAXHOSTNAMELEN + 1]; 00262 00263 /// Holds name of net name server. 00264 const ACE_TCHAR *netnameserver_host_; 00265 00266 /// Holds port number of the net name server. 00267 int netnameserver_port_; 00268 00269 /// 1 if we're on the same local machine as the name server, else 0. 00270 int local (void); 00271 00272 }; 00273 00274 /** 00275 * @class ACE_Name_Options 00276 * 00277 * @brief Manages the options for the ACE Name_Server. 00278 */ 00279 class ACE_Export ACE_Name_Options 00280 { 00281 public: 00282 // = Initialization and termination methods. 00283 ACE_Name_Options (void); 00284 ~ACE_Name_Options (void); 00285 00286 /// Parse arguments. 00287 void parse_args (int argc, 00288 ACE_TCHAR *argv[]); 00289 00290 /// Set the port number 00291 void nameserver_port (int port); 00292 00293 /// Get the port number 00294 int nameserver_port (void); 00295 00296 /// Get the context 00297 ACE_Naming_Context::Context_Scope_Type context (void); 00298 00299 /// Set the context 00300 void context (ACE_Naming_Context::Context_Scope_Type); 00301 00302 /// Set the host name 00303 void nameserver_host (const ACE_TCHAR *host); 00304 00305 /// Get the host name 00306 const ACE_TCHAR *nameserver_host (void); 00307 00308 /// Set name space directory 00309 void namespace_dir (const ACE_TCHAR *dir); 00310 00311 /// Get name space directory 00312 const ACE_TCHAR *namespace_dir (void); 00313 00314 /// Set process name 00315 void process_name (const ACE_TCHAR *dir); 00316 00317 /// Get process name 00318 const ACE_TCHAR *process_name (void); 00319 00320 /// Set database name 00321 void database (const ACE_TCHAR *); 00322 00323 /// Get database name 00324 const ACE_TCHAR *database (void); 00325 00326 /// Set base address of the underlying allocator 00327 void base_address (char *address); 00328 00329 /// Get base address of the underlying allocator 00330 char *base_address (void); 00331 00332 /// Get use of registry in naming 00333 int use_registry (void); 00334 00335 /// Set use of registry in naming 00336 void use_registry (int); 00337 00338 /// Return debug status 00339 int debug (void); 00340 00341 /// Return verbose status 00342 int verbose (void); 00343 00344 private: 00345 /// Extra debugging info 00346 int debugging_; 00347 00348 /// Extra verbose messages 00349 int verbosity_; 00350 00351 /// Use Win32 Registry 00352 int use_registry_; 00353 00354 /// Port to connect to nameserver process. 00355 int nameserver_port_; 00356 00357 /// Hostname of nameserver. 00358 const ACE_TCHAR *nameserver_host_; 00359 00360 /// Directory to hold name_bindings. 00361 ACE_TCHAR *namespace_dir_; 00362 00363 /// Name of this process. 00364 const ACE_TCHAR *process_name_; 00365 00366 /// Name of the database that stores the name/value/type bindings. 00367 const ACE_TCHAR *database_; 00368 00369 /// Base address of the underlying allocator 00370 char *base_address_; 00371 00372 /// The context in which the naming database will be created. 00373 ACE_Naming_Context::Context_Scope_Type context_; 00374 }; 00375 00376 ACE_FACTORY_DECLARE (ACE, ACE_Naming_Context) 00377 ACE_STATIC_SVC_DECLARE_EXPORT (ACE,ACE_Naming_Context) 00378 00379 #include "ace/post.h" 00380 #endif /* ACE_NAMING_CONTEXT_H */
1.2.14 written by Dimitri van Heesch,
© 1997-2002