Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / Local_Name_Space_T.h
blob04dc0e5acd2cfc067c4d6685310d51f3b2508b6c
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Local_Name_Space_T.h
7 * @author Prashant Jain <pjain@cs.wustl.edu>
8 * @author Irfan Pyarali <irfan@wuerl.wustl.edu> and
9 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
11 //=============================================================================
13 #ifndef ACE_LOCAL_NAME_SPACE_T_H
14 #define ACE_LOCAL_NAME_SPACE_T_H
15 #include /**/ "ace/pre.h"
17 #include "ace/Name_Space.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/Naming_Context.h"
24 #include "ace/SString.h"
25 #include "ace/Local_Name_Space.h"
26 #include "ace/Null_Mutex.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 /// A short-hand name for our set of name/value/type tuples passed back
31 /// to callers.
32 typedef ACE_Unbounded_Set<ACE_NS_WString> ACE_WSTRING_SET;
34 ACE_END_VERSIONED_NAMESPACE_DECL
36 # include "ace/Hash_Map_Manager_T.h"
37 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
38 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;
39 ACE_END_VERSIONED_NAMESPACE_DECL
41 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
43 /**
44 * @class ACE_Name_Space_Map
46 * @brief This class serves as a Proxy that ensures our process always
47 * has the appropriate allocator in place for every operation
48 * that accesses or updates the Map Manager.
50 * We need this class because otherwise the ALLOCATOR
51 * pointer will be stored in the Map_Manager that resides within
52 * shared memory. Naturally, this will cause horrible problems
53 * since only the first process to set that pointer will be
54 * guaranteed the address of the ALLOCATOR is meaningful!
56 template <class ALLOCATOR>
57 class ACE_Name_Space_Map : public MAP_MANAGER
59 public:
60 /// Constructor.
61 ACE_Name_Space_Map (ALLOCATOR *alloc);
63 // = The following methods are Proxies to the underlying methods
64 // provided by ACE_Hash_Map_Manager. When they are called, they
65 // acquire the lock, set the allocator to the one specific to this
66 // process, and then call down to perform the intended operation.
67 int bind (const ACE_NS_String &,
68 const ACE_NS_Internal &,
69 ALLOCATOR *alloc);
71 int unbind (const ACE_NS_String &,
72 ACE_NS_Internal &,
73 ALLOCATOR *alloc);
75 int rebind (const ACE_NS_String &,
76 const ACE_NS_Internal &,
77 ACE_NS_String &,
78 ACE_NS_Internal &,
79 ALLOCATOR *alloc);
81 int find (const ACE_NS_String &,
82 ACE_NS_Internal &,
83 ALLOCATOR *alloc);
85 int close (ALLOCATOR *alloc);
88 /**
89 * @class ACE_Local_Name_Space
91 * @brief Maintaining accesses Local Name Server Database. Allows to
92 * add NameBindings, change them, remove them and resolve
93 * NameBindings.
95 * Manages a Naming Service for a local name space which
96 * includes bindings for node_local and host_local naming
97 * contexts. All strings are stored in wide character format.
98 * A Name Binding consists of a name (that's the key), a value
99 * string and an optional type string (no wide chars).
101 template <ACE_MEM_POOL_1, class ACE_LOCK>
102 class ACE_Local_Name_Space : public ACE_Name_Space
104 public:
105 /// "Do-nothing" constructor.
106 ACE_Local_Name_Space ();
109 * Specifies the scope of this namespace, opens and memory-maps the
110 * associated file (if accessible) or contacts the dedicated name
111 * server process for NET_LOCAL namespace.
113 ACE_Local_Name_Space (ACE_Naming_Context::Context_Scope_Type scope_in,
114 ACE_Name_Options *name_options);
117 * Specifies the scope of this namespace, opens and memory-maps the
118 * associated file (if accessible) or contacts the dedicated name
119 * server process for NET_LOCAL namespace.
121 int open (ACE_Naming_Context::Context_Scope_Type scope_in);
123 /// Destructor, do some cleanup :TBD: last dtor should "compress"
124 /// file
125 ~ACE_Local_Name_Space ();
127 /// Bind a new name to a naming context (Wide character strings).
128 virtual int bind (const ACE_NS_WString &name,
129 const ACE_NS_WString &value,
130 const char *type = "");
133 * Overwrite the value or type of an existing name in a
134 * ACE_Local_Name_Space or bind a new name to the context, if it
135 * didn't exist yet. (Wide character strings interface).
137 virtual int rebind (const ACE_NS_WString &name,
138 const ACE_NS_WString &value,
139 const char *type = "");
141 /// Delete a name from a ACE_Local_Name_Space (Wide character strings
142 /// Interface).
143 virtual int unbind (const ACE_NS_WString &name);
144 virtual int unbind_i (const ACE_NS_WString &name);
146 /// Get value and type of a given name binding (Wide chars). The
147 /// caller is responsible for deleting @a type!
148 virtual int resolve (const ACE_NS_WString &name,
149 ACE_NS_WString &value,
150 char *&type);
151 virtual int resolve_i (const ACE_NS_WString &name,
152 ACE_NS_WString &value,
153 char *&type);
155 /// Get a set of names matching a specified pattern (wchars). Matching
156 /// means the names must begin with the pattern string.
157 virtual int list_names (ACE_WSTRING_SET &set,
158 const ACE_NS_WString &pattern);
159 virtual int list_names_i (ACE_WSTRING_SET &set,
160 const ACE_NS_WString &pattern);
162 /// Get a set of values matching a specified pattern (wchars). Matching
163 /// means the values must begin with the pattern string.
164 virtual int list_values (ACE_WSTRING_SET &set,
165 const ACE_NS_WString &pattern);
166 virtual int list_values_i (ACE_WSTRING_SET &set,
167 const ACE_NS_WString &pattern);
169 /// Get a set of types matching a specified pattern (wchars). Matching
170 /// means the types must begin with the pattern string.
171 virtual int list_types (ACE_WSTRING_SET &set,
172 const ACE_NS_WString &pattern);
173 virtual int list_types_i (ACE_WSTRING_SET &set,
174 const ACE_NS_WString &pattern);
177 * Get a set of names matching a specified pattern (wchars). Matching
178 * means the names must begin with the pattern string. Returns the
179 * complete binding associated each pattern match.
181 virtual int list_name_entries (ACE_BINDING_SET &set,
182 const ACE_NS_WString &pattern);
183 virtual int list_name_entries_i (ACE_BINDING_SET &set,
184 const ACE_NS_WString &pattern);
187 * Get a set of values matching a specified pattern (wchars). Matching
188 * means the values must begin with the pattern string. Returns the
189 * complete binding associated each pattern match.
191 virtual int list_value_entries (ACE_BINDING_SET &set,
192 const ACE_NS_WString &pattern);
193 virtual int list_value_entries_i (ACE_BINDING_SET &set,
194 const ACE_NS_WString &pattern);
197 * Get a set of types matching a specified pattern (wchars). Matching
198 * means the types must begin with the pattern string. Returns the
199 * complete binding associated each pattern match.
201 virtual int list_type_entries (ACE_BINDING_SET &set,
202 const ACE_NS_WString &pattern);
203 virtual int list_type_entries_i (ACE_BINDING_SET &set,
204 const ACE_NS_WString &pattern);
206 /// Dump the state of the object
207 virtual void dump () const;
208 virtual void dump_i () const;
210 // = I just know this is going to cause problems on some platform...
211 typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_MEM_POOL_2, ACE_LOCK> >
212 ALLOCATOR;
214 ACE_ALLOC_HOOK_DECLARE;
216 private:
217 #if defined (ACE_WIN32)
218 /// Remap the backing store
219 int remap (EXCEPTION_POINTERS *ep);
220 #endif /* ACE_WIN32 */
222 /// Factor out code from bind() and rebind().
223 int shared_bind (const ACE_NS_WString &name,
224 const ACE_NS_WString &value,
225 const char *type, int rebind);
226 int shared_bind_i (const ACE_NS_WString &name,
227 const ACE_NS_WString &value,
228 const char *type, int rebind);
230 /// Allocate the appropriate type of map manager that stores the
231 /// key/value binding.
232 int create_manager ();
233 int create_manager_i ();
235 /// Pointer to the allocator
236 ALLOCATOR *allocator_;
238 /// Pointer to the allocated map manager.
239 ACE_Name_Space_Map <ALLOCATOR> *name_space_map_;
241 /// Scope of this naming context (e.g., PROC_LOCAL, NODE_LOCAL, or
242 /// NET_LOCAL).
243 ACE_Naming_Context::Context_Scope_Type ns_scope_;
245 /// Keep track of the options such as database name etc
246 ACE_Name_Options *name_options_;
248 /// Name of the file used as the backing store.
249 ACE_TCHAR context_file_[MAXPATHLEN + MAXNAMELEN];
251 /// Synchronization variable.
252 ACE_LOCK *lock_;
255 ACE_END_VERSIONED_NAMESPACE_DECL
257 #include "ace/Local_Name_Space_T.cpp"
259 #include /**/ "ace/post.h"
260 #endif /* ACE_LOCAL_NAME_SPACE_T_H */