Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Local_Name_Space_T.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Local_Name_Space_T.h
00006  *
00007  *  $Id: Local_Name_Space_T.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Prashant Jain <pjain@cs.wustl.edu>
00010  *  @author Irfan Pyarali <irfan@wuerl.wustl.edu> and
00011  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00012  */
00013 //=============================================================================
00014 
00015 #ifndef ACE_LOCAL_NAME_SPACE_T_H
00016 #define ACE_LOCAL_NAME_SPACE_T_H
00017 #include "ace/pre.h"
00018 
00019 #include "ace/Name_Space.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "ace/Naming_Context.h"
00026 #include "ace/SString.h"
00027 #include "ace/Local_Name_Space.h"
00028 
00029 /// A short-hand name for our set of name/value/type tuples passed back
00030 /// to callers.
00031 typedef ACE_Unbounded_Set<ACE_NS_WString> ACE_WSTRING_SET;
00032 
00033 // Simplify later usage by defining typedefs.
00034 #if (1)
00035 #include "ace/Hash_Map_Manager.h"
00036 typedef ACE_Hash_Map_Manager<ACE_NS_String, ACE_NS_Internal, ACE_Null_Mutex> MAP_MANAGER;
00037 typedef ACE_Hash_Map_Iterator<ACE_NS_String, ACE_NS_Internal, ACE_Null_Mutex> MAP_ITERATOR;
00038 typedef ACE_Hash_Map_Entry <ACE_NS_String, ACE_NS_Internal> MAP_ENTRY;
00039 #else
00040 #include "ace/Map_Manager.h"
00041 typedef ACE_Map_Manager<ACE_NS_String, ACE_NS_Internal, ACE_Null_Mutex> MAP_MANAGER;
00042 typedef ACE_Map_Iterator<ACE_NS_String, ACE_NS_Internal, ACE_Null_Mutex> MAP_ITERATOR;
00043 typedef ACE_Map_Entry <ACE_NS_String, ACE_NS_Internal> MAP_ENTRY;
00044 #endif /* 0 */
00045 
00046 /**
00047  * @class ACE_Name_Space_Map
00048  *
00049  * @brief This class serves as a Proxy that ensures our process always
00050  * has the appropriate allocator in place for every operation
00051  * that accesses or updates the Map Manager.
00052  *
00053  * We need this class because otherwise the ALLOCATOR
00054  * pointer will be stored in the Map_Manager that resides within
00055  * shared memory.  Naturally, this will cause horrible problems
00056  * since only the first process to set that pointer will be
00057  * guaranteed the address of the ALLOCATOR is meaningful!
00058  */
00059 template <class ALLOCATOR>
00060 class ACE_Name_Space_Map : public MAP_MANAGER
00061 {
00062 public:
00063   /// Constructor.
00064   ACE_Name_Space_Map (ALLOCATOR *alloc);
00065 
00066   // = The following methods are Proxies to the underlying methods
00067   // provided by ACE_Hash_Map_Manager.  When they are called, they
00068   // acquire the lock, set the allocator to the one specific to this
00069   // process, and then call down to perform the intended operation.
00070   int bind (const ACE_NS_String &,
00071             const ACE_NS_Internal &,
00072             ALLOCATOR *alloc);
00073 
00074   int unbind (const ACE_NS_String &,
00075               ACE_NS_Internal &,
00076               ALLOCATOR *alloc);
00077 
00078   int rebind (const ACE_NS_String &,
00079               const ACE_NS_Internal &,
00080               ACE_NS_String &,
00081               ACE_NS_Internal &,
00082               ALLOCATOR *alloc);
00083 
00084   int find (const ACE_NS_String &,
00085             ACE_NS_Internal &,
00086             ALLOCATOR *alloc);
00087 
00088   int close (ALLOCATOR *alloc);
00089 };
00090 
00091 /**
00092  * @class ACE_Local_Name_Space
00093  *
00094  * @brief Maintaining accesses Local Name Server Database.  Allows to
00095  * add NameBindings, change them, remove them and resolve
00096  * NameBindings.
00097  *
00098  * Manages a Naming Service for a local name space which
00099  * includes bindings for node_local and host_local naming
00100  * contexts.  All strings are stored in wide character format.
00101  * A Name Binding consists of a name (that's the key), a value
00102  * string and an optional type string (no wide chars).
00103  */
00104 template <ACE_MEM_POOL_1, class ACE_LOCK>
00105 class ACE_Local_Name_Space : public ACE_Name_Space
00106 {
00107 public:
00108   // = Initialization and termination methods.
00109   /// "Do-nothing" constructor.
00110   ACE_Local_Name_Space (void);
00111 
00112   /**
00113    * Specifies the scope of this namespace, opens and memory-maps the
00114    * associated file (if accessible) or contacts the dedicated name
00115    * server process for NET_LOCAL namespace.
00116    */
00117   ACE_Local_Name_Space (ACE_Naming_Context::Context_Scope_Type scope_in,
00118                         ACE_Name_Options *name_options);
00119 
00120   /**
00121    * Specifies the scope of this namespace, opens and memory-maps the
00122    * associated file (if accessible) or contacts the dedicated name
00123    * server process for NET_LOCAL namespace.
00124    */
00125   int open (ACE_Naming_Context::Context_Scope_Type scope_in);
00126 
00127   /// Destructor, do some cleanup :TBD: last dtor should "compress"
00128   /// file
00129   ~ACE_Local_Name_Space (void);
00130 
00131   /// Bind a new name to a naming context (Wide character strings).
00132   virtual int bind (const ACE_NS_WString &name,
00133                     const ACE_NS_WString &value,
00134                     const char *type = "");
00135 
00136   /**
00137    * Overwrite the value or type of an existing name in a
00138    * ACE_Local_Name_Space or bind a new name to the context, if it
00139    * didn't exist yet. (Wide charcter strings interface).
00140    */
00141   virtual int rebind (const ACE_NS_WString &name,
00142                       const ACE_NS_WString &value,
00143                       const char *type = "");
00144 
00145   /// Delete a name from a ACE_Local_Name_Space (Wide charcter strings
00146   /// Interface).
00147   virtual int unbind (const ACE_NS_WString &name);
00148   virtual int unbind_i (const ACE_NS_WString &name);
00149 
00150   /// Get value and type of a given name binding (Wide chars).  The
00151   /// caller is responsible for deleting @a type!
00152   virtual int resolve (const ACE_NS_WString &name,
00153                        ACE_NS_WString &value,
00154                        char *&type);
00155   virtual int resolve_i (const ACE_NS_WString &name,
00156                          ACE_NS_WString &value,
00157                          char *&type);
00158 
00159   /// Get a set of names matching a specified pattern (wchars). Matching
00160   /// means the names must begin with the pattern string.
00161   virtual int list_names (ACE_WSTRING_SET &set,
00162                           const ACE_NS_WString &pattern);
00163   virtual int list_names_i (ACE_WSTRING_SET &set,
00164                           const ACE_NS_WString &pattern);
00165 
00166   /// Get a set of values matching a specified pattern (wchars). Matching
00167   /// means the values must begin with the pattern string.
00168   virtual int list_values (ACE_WSTRING_SET &set,
00169                            const ACE_NS_WString &pattern);
00170   virtual int list_values_i (ACE_WSTRING_SET &set,
00171                              const ACE_NS_WString &pattern);
00172 
00173   /// Get a set of types matching a specified pattern (wchars). Matching
00174   /// means the types must begin with the pattern string.
00175   virtual int list_types (ACE_WSTRING_SET &set,
00176                           const ACE_NS_WString &pattern);
00177   virtual int list_types_i (ACE_WSTRING_SET &set,
00178                             const ACE_NS_WString &pattern);
00179 
00180   /**
00181    * Get a set of names matching a specified pattern (wchars). Matching
00182    * means the names must begin with the pattern string. Returns the
00183    * complete binding associated each pattern match.
00184    */
00185   virtual int list_name_entries (ACE_BINDING_SET &set,
00186                                  const ACE_NS_WString &pattern);
00187   virtual int list_name_entries_i (ACE_BINDING_SET &set,
00188                                    const ACE_NS_WString &pattern);
00189 
00190   /**
00191    * Get a set of values matching a specified pattern (wchars). Matching
00192    * means the values must begin with the pattern string. Returns the
00193    * complete binding associated each pattern match.
00194    */
00195   virtual int list_value_entries (ACE_BINDING_SET &set,
00196                                   const ACE_NS_WString &pattern);
00197   virtual int list_value_entries_i (ACE_BINDING_SET &set,
00198                                     const ACE_NS_WString &pattern);
00199 
00200   /**
00201    * Get a set of types matching a specified pattern (wchars). Matching
00202    * means the types must begin with the pattern string. Returns the
00203    * complete binding associated each pattern match.
00204    */
00205   virtual int list_type_entries (ACE_BINDING_SET &set,
00206                                  const ACE_NS_WString &pattern);
00207   virtual int list_type_entries_i (ACE_BINDING_SET &set,
00208                                    const ACE_NS_WString &pattern);
00209 
00210   /// Dump the state of the object
00211   virtual void dump (void) const;
00212   virtual void dump_i (void) const;
00213 
00214   // = I just know this is going to cause problems on some platform...
00215   typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_MEM_POOL_2, ACE_LOCK> >
00216           ALLOCATOR;
00217 
00218 private:
00219 #if defined (ACE_WIN32)
00220   /// Remap the backing store
00221   int remap (EXCEPTION_POINTERS *ep);
00222 #endif /* ACE_WIN32 */
00223 
00224   /// Factor out code from bind() and rebind().
00225   int shared_bind (const ACE_NS_WString &name,
00226                    const ACE_NS_WString &value,
00227                    const char *type, int rebind);
00228   int shared_bind_i (const ACE_NS_WString &name,
00229                      const ACE_NS_WString &value,
00230                      const char *type, int rebind);
00231 
00232   /// Allocate the appropriate type of map manager that stores the
00233   /// key/value binding.
00234   int create_manager (void);
00235   int create_manager_i (void);
00236 
00237   /// Pointer to the allocator
00238   ALLOCATOR *allocator_;
00239 
00240   /// Pointer to the allocated map manager.
00241   ACE_Name_Space_Map <ALLOCATOR> *name_space_map_;
00242 
00243   /// Scope of this naming context (e.g., PROC_LOCAL, NODE_LOCAL, or
00244   /// NET_LOCAL).
00245   ACE_Naming_Context::Context_Scope_Type ns_scope_;
00246 
00247   /// Keep track of the options such as database name etc
00248   ACE_Name_Options *name_options_;
00249 
00250   /// Name of the file used as the backing store.
00251   ACE_TCHAR context_file_[MAXPATHLEN + MAXNAMELEN];
00252 
00253   /// Synchronization variable.
00254   ACE_LOCK *lock_;
00255 };
00256 
00257 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00258 #include "ace/Local_Name_Space_T.cpp"
00259 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00260 
00261 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00262 #pragma implementation ("Local_Name_Space_T.cpp")
00263 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00264 
00265 #include "ace/post.h"
00266 #endif /* ACE_LOCAL_NAME_SPACE_T_H */

Generated on Mon Jun 16 11:19:56 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002