Naming_Context.h

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

Generated on Thu Nov 9 09:41:57 2006 for ACE by doxygen 1.3.6