3 //==========================================================================
5 * @file Naming_Context.h
7 * @author Gerhard Lenzer
8 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 * @author Prashant Jain <pjain@uci.edu>
11 //==========================================================================
13 #ifndef ACE_NAMING_CONTEXT_H
14 #define ACE_NAMING_CONTEXT_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/ACE_export.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/Service_Object.h"
24 #include "ace/Name_Space.h"
25 #include "ace/os_include/os_netdb.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 class ACE_Name_Options
;
31 class ACE_Static_Svc_Descriptor
;
34 * @class ACE_Naming_Context
36 * @brief Maintaining accesses Name Server Databases. Allows to add
37 * NameBindings, change them, remove them and resolve
40 * Manages a Naming Service . That represents a persistent
41 * string to string mapping for different scopes. The scope of a
42 * ACE_Naming_Context may be either local for the calling
43 * process (Note : A process is hereby not identified by it's
44 * pid, but by it's argv[0]. So different processes (in UNIX
45 * syntax) may access the same NameBindings), global for all
46 * processes running on one host or global for all processes on
47 * the net (that know the address of the net name server
48 * socket). Strings may be plain character strings or Wide
49 * character strings. A Name Binding consists of a name string
50 * (that's the key), a value string and an optional type string
53 class ACE_Export ACE_Naming_Context
: public ACE_Service_Object
56 enum Context_Scope_Type
58 /// Name lookup is local to the process.
60 /// Name lookup is local to the node (host).
62 /// Name lookup is local to the (sub)network.
66 /// "Do-nothing" constructor.
67 ACE_Naming_Context ();
70 * Specifies the scope of this namespace, opens and memory-maps the
71 * associated file (if accessible) or contacts the dedicated name
72 * server process for NET_LOCAL namespace. Note that @a light
73 * specifies whether or not we want to use
74 * ACE_Lite_MMap_Memory_Pool. By default we use ACE_MMap_Memory_Pool.
76 ACE_Naming_Context (Context_Scope_Type scope_in
, int light
= 0);
79 * Specifies the scope of this namespace, opens and memory-maps the
80 * associated file (if accessible) or contacts the dedicated name
81 * server process for NET_LOCAL namespace. Note that @a light
82 * specifies whether or not we want to use
83 * ACE_Lite_MMap_Memory_Pool. By default we use ACE_MMap_Memory_Pool.
85 int open (Context_Scope_Type scope_in
= ACE_Naming_Context::PROC_LOCAL
,
88 /// Deletes the instance of Name Space. Must be called before
89 /// switching name spaces.
92 /// Release all resources. Gets called by destructor and fini.
95 /// destructor, do some cleanup :TBD: last dtor should "compress"
97 ~ACE_Naming_Context ();
99 // = Dynamic initialization hooks.
100 /// Initialize name options and naming context when dynamically
102 virtual int init (int argc
, ACE_TCHAR
*argv
[]);
104 /// Close down the test when dynamically unlinked.
107 /// Returns information about this context.
108 virtual int info (ACE_TCHAR
**strp
, size_t length
) const;
110 /// Returns the ACE_Name_Options associated with the Naming_Context
111 ACE_Name_Options
*name_options ();
113 /// Bind a new name to a naming context (Wide character strings).
114 int bind (const ACE_NS_WString
&name_in
,
115 const ACE_NS_WString
&value_in
,
116 const char *type_in
= "");
118 /// Bind a new name to a naming context ( character strings).
119 int bind (const char *name_in
,
120 const char *value_in
,
121 const char *type_in
= "");
124 * Overwrite the value or type of an existing name in a
125 * ACE_Naming_Context or bind a new name to the context, if it
126 * didn't exist yet. (Wide character strings interface).
128 int rebind (const ACE_NS_WString
&name_in
,
129 const ACE_NS_WString
&value_in
,
130 const char *type_in
= "");
133 * Overwrite the value or type of an existing name in a
134 * ACE_Naming_Context or bind a new name to the context, if it
135 * didn't exist yet. ( character strings interface)
137 int rebind (const char *name_in
,
138 const char *value_in
,
139 const char *type_in
= "");
141 /// Delete a name from a ACE_Naming_Context (Wide character strings
143 int unbind (const ACE_NS_WString
&name_in
);
145 /// Delete a name from a ACE_Naming_Context (character strings
147 int unbind (const char *name_in
);
149 /// Get value and type of a given name binding (Wide chars). The
150 /// caller is responsible for deleting both @a value_out> and @a type_out!
151 int resolve (const ACE_NS_WString
&name_in
,
152 ACE_NS_WString
&value_out
,
156 * Get value and type of a given name binding (Wide chars output).
157 * The caller is responsible for deleting both @a value_out and
160 int resolve (const char *name_in
,
161 ACE_NS_WString
&value_out
,
164 /// Get value and type of a given name binding ( chars ). The caller
165 /// is responsible for deleting both @a value_out and @a type_out!
166 int resolve (const char *name_in
,
170 /// Get a set of names matching a specified pattern (wchars). Matching
171 /// means the names must begin with the pattern string.
172 int list_names (ACE_PWSTRING_SET
&set_out
,
173 const ACE_NS_WString
&pattern_in
);
175 /// Get a set of names matching a specified pattern (chars). Matching
176 /// means the names must begin with the pattern string.
177 int list_names (ACE_PWSTRING_SET
&set_out
,
178 const char *pattern_in
);
180 /// Get a set of values matching a specified pattern (wchars). Matching
181 /// means the values must begin with the pattern string.
182 int list_values (ACE_PWSTRING_SET
&set_out
,
183 const ACE_NS_WString
&pattern_in
);
185 /// Get a set of values matching a specified pattern (chars). Matching
186 /// means the values must begin with the pattern string.
187 int list_values (ACE_PWSTRING_SET
&set_out
,
188 const char *pattern_in
);
190 /// Get a set of types matching a specified pattern (wchars). Matching
191 /// means the types must begin with the pattern string.
192 int list_types (ACE_PWSTRING_SET
&set_out
,
193 const ACE_NS_WString
&pattern_in
);
195 /// Get a set of types matching a specified pattern (chars). Matching
196 /// means the types must begin with the pattern string.
197 int list_types (ACE_PWSTRING_SET
&set_out
,
198 const char *pattern_in
);
201 * Get a set of names matching a specified pattern (wchars). Matching
202 * means the names must begin with the pattern string. Returns the
203 * complete binding associated each pattern match.
205 virtual int list_name_entries (ACE_BINDING_SET
&set_out
,
206 const ACE_NS_WString
&pattern_in
);
209 * Get a set of names matching a specified pattern (wchars). Matching
210 * means the names must begin with the pattern string. Returns the
211 * complete binding associated each pattern match.
213 virtual int list_name_entries (ACE_BINDING_SET
&set_out
,
214 const char *pattern_in
);
217 * Get a set of values matching a specified pattern (wchars). Matching
218 * means the values must begin with the pattern string. Returns the
219 * complete binding associated each pattern match.
221 virtual int list_value_entries (ACE_BINDING_SET
&set_out
,
222 const ACE_NS_WString
&pattern_in
);
225 * Get a set of values matching a specified pattern (wchars). Matching
226 * means the values must begin with the pattern string. Returns the
227 * complete binding associated each pattern match.
229 virtual int list_value_entries (ACE_BINDING_SET
&set_out
,
230 const char *pattern_in
);
233 * Get a set of types matching a specified pattern (wchars). Matching
234 * means the types must begin with the pattern string. Returns the
235 * complete binding associated each pattern match.
237 virtual int list_type_entries (ACE_BINDING_SET
&set_out
,
238 const ACE_NS_WString
&pattern_in
);
241 * Get a set of types matching a specified pattern (wchars). Matching
242 * means the types must begin with the pattern string. Returns the
243 * complete binding associated each pattern match.
245 virtual int list_type_entries (ACE_BINDING_SET
&set_out
,
246 const char *pattern_in
);
248 /// Dump the state of the object.
252 /// Keep track of the options such as database name etc per Naming Context
253 ACE_Name_Options
*name_options_
;
255 /// Name space (can be either local or remote) dynamically bound.
256 ACE_Name_Space
*name_space_
;
258 /// Holds the local hostname.
259 ACE_TCHAR hostname_
[MAXHOSTNAMELEN
+ 1];
261 /// Holds name of net name server.
262 const ACE_TCHAR
*netnameserver_host_
;
264 /// Holds port number of the net name server.
265 int netnameserver_port_
;
267 /// 1 if we're on the same local machine as the name server, else 0.
272 * @class ACE_Name_Options
274 * @brief Manages the options for the ACE Name_Server.
276 class ACE_Export ACE_Name_Options
280 ~ACE_Name_Options ();
283 void parse_args (int argc
,
286 /// Set the port number
287 void nameserver_port (int port
);
289 /// Get the port number
290 int nameserver_port ();
293 ACE_Naming_Context::Context_Scope_Type
context ();
296 void context (ACE_Naming_Context::Context_Scope_Type
);
298 /// Set the host name
299 void nameserver_host (const ACE_TCHAR
*host
);
301 /// Get the host name
302 const ACE_TCHAR
*nameserver_host ();
304 /// Set name space directory
305 void namespace_dir (const ACE_TCHAR
*dir
);
307 /// Get name space directory
308 const ACE_TCHAR
*namespace_dir ();
311 void process_name (const ACE_TCHAR
*dir
);
314 const ACE_TCHAR
*process_name ();
316 /// Set database name
317 void database (const ACE_TCHAR
*);
319 /// Get database name
320 const ACE_TCHAR
*database ();
322 /// Set base address of the underlying allocator
323 void base_address (char *address
);
325 /// Get base address of the underlying allocator
326 char *base_address ();
328 /// Get use of registry in naming
329 bool use_registry () const;
331 /// Set use of registry in naming
332 void use_registry (bool x
);
334 /// Return debug status
337 /// Return verbose status
340 ACE_ALLOC_HOOK_DECLARE
;
343 /// Extra debugging info
346 /// Extra verbose messages
349 /// Use Win32 Registry
352 /// Port to connect to nameserver process.
353 int nameserver_port_
;
355 /// Hostname of nameserver.
356 const ACE_TCHAR
*nameserver_host_
;
358 /// Directory to hold name_bindings.
359 ACE_TCHAR
*namespace_dir_
;
361 /// Name of this process.
362 const ACE_TCHAR
*process_name_
;
364 /// Name of the database that stores the name/value/type bindings.
365 const ACE_TCHAR
*database_
;
367 /// Base address of the underlying allocator
370 /// The context in which the naming database will be created.
371 ACE_Naming_Context::Context_Scope_Type context_
;
374 ACE_FACTORY_DECLARE (ACE
, ACE_Naming_Context
)
375 ACE_STATIC_SVC_DECLARE_EXPORT (ACE
, ACE_Naming_Context
)
377 ACE_END_VERSIONED_NAMESPACE_DECL
379 #if defined (__ACE_INLINE__)
380 #include "ace/Naming_Context.inl"
381 #endif /* __ACE_INLINE__ */
383 #include /**/ "ace/post.h"
384 #endif /* ACE_NAMING_CONTEXT_H */