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

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