summaryrefslogtreecommitdiff
path: root/ACE/ace/Local_Name_Space_T.h
blob: 3694de0e89b900e246419b2c967947b17c17bb2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Local_Name_Space_T.h
 *
 *  @author Prashant Jain <pjain@cs.wustl.edu>
 *  @author Irfan Pyarali <irfan@wuerl.wustl.edu> and
 *  @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
 */
//=============================================================================

#ifndef ACE_LOCAL_NAME_SPACE_T_H
#define ACE_LOCAL_NAME_SPACE_T_H
#include /**/ "ace/pre.h"

#include "ace/Name_Space.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Naming_Context.h"
#include "ace/SString.h"
#include "ace/Local_Name_Space.h"
#include "ace/Null_Mutex.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/// A short-hand name for our set of name/value/type tuples passed back
/// to callers.
typedef ACE_Unbounded_Set<ACE_NS_WString> ACE_WSTRING_SET;

ACE_END_VERSIONED_NAMESPACE_DECL

# include "ace/Hash_Map_Manager_T.h"
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
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;
ACE_END_VERSIONED_NAMESPACE_DECL

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @class ACE_Name_Space_Map
 *
 * @brief This class serves as a Proxy that ensures our process always
 * has the appropriate allocator in place for every operation
 * that accesses or updates the Map Manager.
 *
 * We need this class because otherwise the ALLOCATOR
 * pointer will be stored in the Map_Manager that resides within
 * shared memory.  Naturally, this will cause horrible problems
 * since only the first process to set that pointer will be
 * guaranteed the address of the ALLOCATOR is meaningful!
 */
template <class ALLOCATOR>
class ACE_Name_Space_Map : public MAP_MANAGER
{
public:
  /// Constructor.
  ACE_Name_Space_Map (ALLOCATOR *alloc);

  // = The following methods are Proxies to the underlying methods
  // provided by ACE_Hash_Map_Manager.  When they are called, they
  // acquire the lock, set the allocator to the one specific to this
  // process, and then call down to perform the intended operation.
  int bind (const ACE_NS_String &,
            const ACE_NS_Internal &,
            ALLOCATOR *alloc);

  int unbind (const ACE_NS_String &,
              ACE_NS_Internal &,
              ALLOCATOR *alloc);

  int rebind (const ACE_NS_String &,
              const ACE_NS_Internal &,
              ACE_NS_String &,
              ACE_NS_Internal &,
              ALLOCATOR *alloc);

  int find (const ACE_NS_String &,
            ACE_NS_Internal &,
            ALLOCATOR *alloc);

  int close (ALLOCATOR *alloc);
};

/**
 * @class ACE_Local_Name_Space
 *
 * @brief Maintaining accesses Local Name Server Database.  Allows to
 * add NameBindings, change them, remove them and resolve
 * NameBindings.
 *
 * Manages a Naming Service for a local name space which
 * includes bindings for node_local and host_local naming
 * contexts.  All strings are stored in wide character format.
 * A Name Binding consists of a name (that's the key), a value
 * string and an optional type string (no wide chars).
 */
template <ACE_MEM_POOL_1, class ACE_LOCK>
class ACE_Local_Name_Space : public ACE_Name_Space
{
public:
  /// "Do-nothing" constructor.
  ACE_Local_Name_Space (void);

  /**
   * Specifies the scope of this namespace, opens and memory-maps the
   * associated file (if accessible) or contacts the dedicated name
   * server process for NET_LOCAL namespace.
   */
  ACE_Local_Name_Space (ACE_Naming_Context::Context_Scope_Type scope_in,
                        ACE_Name_Options *name_options);

  /**
   * Specifies the scope of this namespace, opens and memory-maps the
   * associated file (if accessible) or contacts the dedicated name
   * server process for NET_LOCAL namespace.
   */
  int open (ACE_Naming_Context::Context_Scope_Type scope_in);

  /// Destructor, do some cleanup :TBD: last dtor should "compress"
  /// file
  ~ACE_Local_Name_Space (void);

  /// Bind a new name to a naming context (Wide character strings).
  virtual int bind (const ACE_NS_WString &name,
                    const ACE_NS_WString &value,
                    const char *type = "");

  /**
   * Overwrite the value or type of an existing name in a
   * ACE_Local_Name_Space or bind a new name to the context, if it
   * didn't exist yet. (Wide character strings interface).
   */
  virtual int rebind (const ACE_NS_WString &name,
                      const ACE_NS_WString &value,
                      const char *type = "");

  /// Delete a name from a ACE_Local_Name_Space (Wide character strings
  /// Interface).
  virtual int unbind (const ACE_NS_WString &name);
  virtual int unbind_i (const ACE_NS_WString &name);

  /// Get value and type of a given name binding (Wide chars).  The
  /// caller is responsible for deleting @a type!
  virtual int resolve (const ACE_NS_WString &name,
                       ACE_NS_WString &value,
                       char *&type);
  virtual int resolve_i (const ACE_NS_WString &name,
                         ACE_NS_WString &value,
                         char *&type);

  /// Get a set of names matching a specified pattern (wchars). Matching
  /// means the names must begin with the pattern string.
  virtual int list_names (ACE_WSTRING_SET &set,
                          const ACE_NS_WString &pattern);
  virtual int list_names_i (ACE_WSTRING_SET &set,
                          const ACE_NS_WString &pattern);

  /// Get a set of values matching a specified pattern (wchars). Matching
  /// means the values must begin with the pattern string.
  virtual int list_values (ACE_WSTRING_SET &set,
                           const ACE_NS_WString &pattern);
  virtual int list_values_i (ACE_WSTRING_SET &set,
                             const ACE_NS_WString &pattern);

  /// Get a set of types matching a specified pattern (wchars). Matching
  /// means the types must begin with the pattern string.
  virtual int list_types (ACE_WSTRING_SET &set,
                          const ACE_NS_WString &pattern);
  virtual int list_types_i (ACE_WSTRING_SET &set,
                            const ACE_NS_WString &pattern);

  /**
   * Get a set of names matching a specified pattern (wchars). Matching
   * means the names must begin with the pattern string. Returns the
   * complete binding associated each pattern match.
   */
  virtual int list_name_entries (ACE_BINDING_SET &set,
                                 const ACE_NS_WString &pattern);
  virtual int list_name_entries_i (ACE_BINDING_SET &set,
                                   const ACE_NS_WString &pattern);

  /**
   * Get a set of values matching a specified pattern (wchars). Matching
   * means the values must begin with the pattern string. Returns the
   * complete binding associated each pattern match.
   */
  virtual int list_value_entries (ACE_BINDING_SET &set,
                                  const ACE_NS_WString &pattern);
  virtual int list_value_entries_i (ACE_BINDING_SET &set,
                                    const ACE_NS_WString &pattern);

  /**
   * Get a set of types matching a specified pattern (wchars). Matching
   * means the types must begin with the pattern string. Returns the
   * complete binding associated each pattern match.
   */
  virtual int list_type_entries (ACE_BINDING_SET &set,
                                 const ACE_NS_WString &pattern);
  virtual int list_type_entries_i (ACE_BINDING_SET &set,
                                   const ACE_NS_WString &pattern);

  /// Dump the state of the object
  virtual void dump () const;
  virtual void dump_i () const;

  // = I just know this is going to cause problems on some platform...
  typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_MEM_POOL_2, ACE_LOCK> >
          ALLOCATOR;

  ACE_ALLOC_HOOK_DECLARE;

private:
#if defined (ACE_WIN32)
  /// Remap the backing store
  int remap (EXCEPTION_POINTERS *ep);
#endif /* ACE_WIN32 */

  /// Factor out code from bind() and rebind().
  int shared_bind (const ACE_NS_WString &name,
                   const ACE_NS_WString &value,
                   const char *type, int rebind);
  int shared_bind_i (const ACE_NS_WString &name,
                     const ACE_NS_WString &value,
                     const char *type, int rebind);

  /// Allocate the appropriate type of map manager that stores the
  /// key/value binding.
  int create_manager (void);
  int create_manager_i (void);

  /// Pointer to the allocator
  ALLOCATOR *allocator_;

  /// Pointer to the allocated map manager.
  ACE_Name_Space_Map <ALLOCATOR> *name_space_map_;

  /// Scope of this naming context (e.g., PROC_LOCAL, NODE_LOCAL, or
  /// NET_LOCAL).
  ACE_Naming_Context::Context_Scope_Type ns_scope_;

  /// Keep track of the options such as database name etc
  ACE_Name_Options *name_options_;

  /// Name of the file used as the backing store.
  ACE_TCHAR context_file_[MAXPATHLEN + MAXNAMELEN];

  /// Synchronization variable.
  ACE_LOCK *lock_;
};

ACE_END_VERSIONED_NAMESPACE_DECL

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Local_Name_Space_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Local_Name_Space_T.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#include /**/ "ace/post.h"
#endif /* ACE_LOCAL_NAME_SPACE_T_H */