3 //=============================================================================
7 * @author Irfan Pyarali (irfan@cs.wustl.edu)
9 //=============================================================================
12 #ifndef ACE_REGISTRY_H
13 #define ACE_REGISTRY_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/config-all.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
23 // This only works on registry-capable Win32 platforms.
25 #include "ace/Containers.h"
26 #include "ace/SString.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
33 * @brief A Name Server implementation
35 * The registry interface is inspired by the interface
36 * specified in the CORBA Naming Service Specification.
37 * The implementation is done through Win32 <Reg*> functions.
38 * Other than providing an OO wrapper for the Win32 <Reg*>
39 * functions, ACE_Registry provides an abstraction for iteration
40 * over the elements of the Registry.
42 class ACE_Export ACE_Registry
46 /// International string
47 struct ACE_Export Name_Component
52 bool operator== (const Name_Component
&rhs
) const;
53 bool operator!= (const Name_Component
&rhs
) const;
56 // The <id_> field is used,
57 // but the <kind_> field is currently ignored
59 /// A Name is an ordered collections of components (ids)
60 typedef ACE_Unbounded_Set
<Name_Component
> Name
;
62 /// Separator for components in a name
63 static const ACE_TCHAR STRING_SEPARATOR
[];
65 /// Convert a @a name to a @c string
66 static ACE_TString
make_string (const Name
&name
);
68 /// Convert a @a string to a @c name
69 static Name
make_name (const ACE_TString
&string
);
71 /// There are two types of bindings
72 enum Binding_Type
{INVALID
, OBJECT
, CONTEXT
};
74 struct ACE_Export Binding
76 /// Empty (default) constructor
81 Binding (const Name
&binding_name
,
82 Binding_Type binding_type
);
86 Binding (const ACE_TString
&binding_name
,
87 Binding_Type binding_type
);
89 bool operator== (const Binding
&rhs
) const;
90 bool operator!= (const Binding
&rhs
) const;
95 void name (Name
&name
);
97 /// Set Name (String version)
98 void name (ACE_TString
&name
);
100 /// Get Name (String version)
101 ACE_TString
name (void);
104 Binding_Type
type (void);
107 /// A binding has a name
114 /// A list of bindings
115 typedef ACE_Unbounded_Set
<Binding
> Binding_List
;
117 // Forward declaration of iterator
118 class Binding_Iterator
;
123 * @brief An object representation
125 * In CORBA, all objects inherit from (CORBA::Object).
126 * For the registry, this is used as a wrapper for an
127 * instance of a built-in data type.
128 * Think about an object as being similar to a file
131 class ACE_Export Object
134 /// Default constructor
135 Object (void *data
= 0,
137 u_long type
= REG_NONE
);
140 void data (void *data
);
143 void *data (void) const;
146 void size (u_long size
);
149 u_long
size (void) const;
152 void type (u_long type
);
155 u_long
type (void) const;
169 * @class Naming_Context
171 * @brief An context representation
173 * Think about a context as being similar to a directory
176 class ACE_Export Naming_Context
180 friend class ACE_Predefined_Naming_Contexts
;
183 /// Max sizes of names
184 /// (Not too sure about this value)
185 MAX_OBJECT_NAME_SIZE
= BUFSIZ
,
187 /// Max size of context name
188 MAX_CONTEXT_NAME_SIZE
= MAXPATHLEN
+ 1
191 /// Empty constructor: keys will be NULL
192 Naming_Context (void);
194 /// Constructor: key_ will be set to @a key
195 Naming_Context (const HKEY
&key
);
197 /// Destructor will call <Naming_Context::close>.
198 ~Naming_Context (void);
200 // The following interfaces are for objects
203 * Insert @a object with @a name into @c this context.
204 * This will fail if @a name already exists
207 int bind_new (const Name
&name
,
208 const Object
&object
);
211 * Insert @a object with @a name into @c this context
212 * This will fail if @a name already exists
215 int bind_new (const ACE_TString
&name
,
216 const Object
&object
);
219 * Insert or update @a object with @a name into @c this context
220 * This will not fail if @a name already exists
223 int bind (const Name
&name
,
224 const Object
&object
);
227 * Insert or update <object> with @a name into @c this context
228 * This will not fail if @a name already exists
231 int bind (const ACE_TString
&name
,
232 const Object
&object
);
234 /// Update <object> with @a name in @c this context
236 int rebind (const Name
&name
,
237 const Object
&object
);
239 /// Update <object> with @a name in @c this context
240 int rebind (const ACE_TString
&name
,
241 const Object
&object
);
243 /// Find <object> with @a name in @c this context
245 int resolve (const Name
&name
,
248 /// Find <object> with @a name in @c this context
249 int resolve (const ACE_TString
&name
,
252 /// Delete object with @a name in @c this context
254 int unbind (const Name
&name
);
256 /// Delete object with @a name in @c this context
257 int unbind (const ACE_TString
&name
);
260 // The following interfaces are for Naming Context
262 /// Create new @c naming_context
263 int new_context (Naming_Context
&naming_context
);
266 * Insert <naming_context> with @a name relative to @c this context
267 * This will fail if @a name already exists
270 int bind_new_context (const Name
&name
,
271 Naming_Context
&naming_context
,
272 u_long persistence
= REG_OPTION_NON_VOLATILE
,
273 u_long security_access
= KEY_ALL_ACCESS
,
274 LPSECURITY_ATTRIBUTES security_attributes
= 0);
276 /// Insert <naming_context> with @a name relative to @c this context
277 /// This will fail if @a name already exists
278 int bind_new_context (const ACE_TString
&name
,
279 Naming_Context
&naming_context
,
280 u_long persistence
= REG_OPTION_NON_VOLATILE
,
281 u_long security_access
= KEY_ALL_ACCESS
,
282 LPSECURITY_ATTRIBUTES security_attributes
= 0);
285 * Insert or update <naming_context> with @a name relative to @c this context
286 * This will not fail if @a name already exists
289 int bind_context (const Name
&name
,
290 /* const */ Naming_Context
&naming_context
,
291 u_long persistence
= REG_OPTION_NON_VOLATILE
,
292 u_long security_access
= KEY_ALL_ACCESS
,
293 LPSECURITY_ATTRIBUTES security_attributes
= 0);
295 /// Insert or update <naming_context> with @a name relative to @c this context
296 /// This will not fail if @a name already exists
297 int bind_context (const ACE_TString
&name
,
298 /* const */ Naming_Context
&naming_context
,
299 u_long persistence
= REG_OPTION_NON_VOLATILE
,
300 u_long security_access
= KEY_ALL_ACCESS
,
301 LPSECURITY_ATTRIBUTES security_attributes
= 0);
303 /// Rename <naming_context> to @a name
305 int rebind_context (const Name
&name
,
306 /* const */ Naming_Context
&naming_context
);
308 /// Rename <naming_context> to @a name
309 int rebind_context (const ACE_TString
&name
,
310 /* const */ Naming_Context
&naming_context
);
312 /// Find <naming_context> with @a name in @c this context
314 int resolve_context (const Name
&name
,
315 Naming_Context
&naming_context
,
316 u_long security_access
= KEY_ALL_ACCESS
);
318 /// Find <naming_context> with @a name in @c this context
319 int resolve_context (const ACE_TString
&name
,
320 Naming_Context
&naming_context
,
321 u_long security_access
= KEY_ALL_ACCESS
);
323 /// Remove naming_context with @a name from @c this context
325 int unbind_context (const Name
&name
);
327 /// Remove naming_context with @a name from @c this context
328 int unbind_context (const ACE_TString
&name
);
330 /// Same as <unbind_context> with @c this as naming_context
334 * listing function: iterator creator
335 * This is useful when there are many objects and contexts
336 * in @c this context and you only want to look at a few entries
339 int list (u_long how_many
,
341 Binding_Iterator
&iterator
);
343 /// listing function: iterator creator
344 /// This gives back a listing of all entries in @c this context.
345 int list (Binding_List
&list
);
347 // Some other necessary functions which are
348 // not part of the CORBA interface
350 /// Sync content of context to disk
353 /// Close the handle of the context
354 /// @note <close> does not call <flush>
362 // void parent (HKEY parent);
368 void name (Name
&name
);
370 /// Set name (String version)
371 void name (ACE_TString
&name
);
373 /// Get name (String version)
374 ACE_TString
name (void);
381 void parent (HKEY parent
);
385 void name (const Name
&name
);
389 void name (const ACE_TString
&name
);
392 /// Disallow copy constructors
393 Naming_Context (const Naming_Context
&rhs
);
395 /// Disallow assignment
396 const Naming_Context
&operator= (const Naming_Context
&rhs
);
409 * @class Binding_Iterator
413 * Useful when iteratorating over a few entries at a time
415 class ACE_Export Binding_Iterator
419 friend class Naming_Context
;
421 /// Default constructor
422 Binding_Iterator (void);
425 int next_one (Binding
&binding
);
427 /// Next <how_many> entries
428 int next_n (u_long how_many
,
434 /// Reset the internal state of the iterator
437 /// Get naming_context that the iterator is iterating over
438 Naming_Context
&naming_context (void);
442 /// Set naming_context that the iterator is iterating over
443 void naming_context (Naming_Context
& naming_context
);
445 /// Reference to context
446 Naming_Context
*naming_context_
;
449 // This should really be private
450 // But the compiler is broken
453 * @class Iteration_State
455 * Base class for state
457 class ACE_Export Iteration_State
461 Iteration_State (void);
464 virtual ~Iteration_State (void);
466 /// Set the iterator reference.
467 void iterator (Binding_Iterator
*iterator
);
469 /// Next <how_many> entries
470 virtual int next_n (u_long how_many
,
471 Binding_List
&list
) = 0;
477 /// Pointer to parent iterator
478 Binding_Iterator
*parent_
;
484 class ACE_Export Object_Iteration
: public Iteration_State
486 /// Next <how_many> entries
487 int next_n (u_long how_many
,
491 class ACE_Export Context_Iteration
: public Iteration_State
494 /// Next @a how_many entries
495 int next_n (u_long how_many
,
499 class ACE_Export Iteration_Complete
: public Iteration_State
502 /// Next @a how_many entries
503 int next_n (u_long how_many
,
508 friend class Iteration_State
;
509 friend class Object_Iteration
;
510 friend class Context_Iteration
;
511 friend class Iteration_Complete
;
513 /// Instances of all states
514 Object_Iteration object_iteration_
;
515 Context_Iteration context_iteration_
;
516 Iteration_Complete iteration_complete_
;
518 /// Pointer to current state
519 Iteration_State
*current_enumeration_
;
521 /// Set current_enumeration
522 void current_enumeration (Iteration_State
& current_enumeration
);
524 /// Get current_enumeration
525 Iteration_State
¤t_enumeration (void);
530 * @class ACE_Predefined_Naming_Contexts
532 * @brief A factory for predefined registries, which exist by default
535 * This factory can connect to both local and remote
536 * predefined registries.
538 class ACE_Export ACE_Predefined_Naming_Contexts
542 * Factory method for connecting to predefined registries. This
543 * method works for both remote and local machines. However, for
544 * remote machines, HKEY_CLASSES_ROOT and HKEY_CURRENT_USER types
547 static int connect (ACE_Registry::Naming_Context
&naming_context
,
548 HKEY predefined
= HKEY_LOCAL_MACHINE
,
549 const ACE_TCHAR
*machine_name
= 0);
552 /// Check if @a machine_name is the local host
553 static int is_local_host (const ACE_TCHAR
*machine_name
);
556 ACE_END_VERSIONED_NAMESPACE_DECL
558 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */
559 #include /**/ "ace/post.h"
560 #endif /* ACE_REGISTRY_H */