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)
24 #include "ace/Containers.h"
25 #include "ace/SString.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
32 * @brief A Name Server implementation
34 * The registry interface is inspired by the interface
35 * specified in the CORBA Naming Service Specification.
36 * The implementation is done through Win32 <Reg*> functions.
37 * Other than providing an OO wrapper for the Win32 <Reg*>
38 * functions, ACE_Registry provides an abstraction for iteration
39 * over the elements of the Registry.
41 class ACE_Export ACE_Registry
44 /// International string
45 struct ACE_Export Name_Component
50 bool operator== (const Name_Component
&rhs
) const;
51 bool operator!= (const Name_Component
&rhs
) const;
54 // The <id_> field is used,
55 // but the <kind_> field is currently ignored
57 /// A Name is an ordered collections of components (ids)
58 typedef ACE_Unbounded_Set
<Name_Component
> Name
;
60 /// Separator for components in a name
61 static const ACE_TCHAR STRING_SEPARATOR
[];
63 /// Convert a @a name to a @c string
64 static ACE_TString
make_string (const Name
&name
);
66 /// Convert a @a string to a @c name
67 static Name
make_name (const ACE_TString
&string
);
69 /// There are two types of bindings
70 enum Binding_Type
{INVALID
, OBJECT
, CONTEXT
};
72 struct ACE_Export Binding
74 /// Empty (default) constructor
79 Binding (const Name
&binding_name
,
80 Binding_Type binding_type
);
84 Binding (const ACE_TString
&binding_name
,
85 Binding_Type binding_type
);
87 bool operator== (const Binding
&rhs
) const;
88 bool operator!= (const Binding
&rhs
) const;
93 void name (Name
&name
);
95 /// Set Name (String version)
96 void name (ACE_TString
&name
);
98 /// Get Name (String version)
102 Binding_Type
type ();
105 /// A binding has a name
112 /// A list of bindings
113 typedef ACE_Unbounded_Set
<Binding
> Binding_List
;
115 // Forward declaration of iterator
116 class Binding_Iterator
;
121 * @brief An object representation
123 * In CORBA, all objects inherit from (CORBA::Object).
124 * For the registry, this is used as a wrapper for an
125 * instance of a built-in data type.
126 * Think about an object as being similar to a file
129 class ACE_Export Object
132 /// Default constructor
133 Object (void *data
= 0,
135 u_long type
= REG_NONE
);
138 void data (void *data
);
144 void size (u_long size
);
147 u_long
size () const;
150 void type (u_long type
);
153 u_long
type () const;
167 * @class Naming_Context
169 * @brief An context representation
171 * Think about a context as being similar to a directory
174 class ACE_Export Naming_Context
178 friend class ACE_Predefined_Naming_Contexts
;
181 /// Max sizes of names
182 /// (Not too sure about this value)
183 MAX_OBJECT_NAME_SIZE
= BUFSIZ
,
185 /// Max size of context name
186 MAX_CONTEXT_NAME_SIZE
= MAXPATHLEN
+ 1
189 /// Empty constructor: keys will be NULL
192 /// Constructor: key_ will be set to @a key
193 Naming_Context (const HKEY
&key
);
195 /// Destructor will call <Naming_Context::close>.
198 // The following interfaces are for objects
201 * Insert @a object with @a name into @c this context.
202 * This will fail if @a name already exists
205 int bind_new (const Name
&name
,
206 const Object
&object
);
209 * Insert @a object with @a name into @c this context
210 * This will fail if @a name already exists
213 int bind_new (const ACE_TString
&name
,
214 const Object
&object
);
217 * Insert or update @a object with @a name into @c this context
218 * This will not fail if @a name already exists
221 int bind (const Name
&name
,
222 const Object
&object
);
225 * Insert or update <object> with @a name into @c this context
226 * This will not fail if @a name already exists
229 int bind (const ACE_TString
&name
,
230 const Object
&object
);
232 /// Update <object> with @a name in @c this context
234 int rebind (const Name
&name
,
235 const Object
&object
);
237 /// Update <object> with @a name in @c this context
238 int rebind (const ACE_TString
&name
,
239 const Object
&object
);
241 /// Find <object> with @a name in @c this context
243 int resolve (const Name
&name
,
246 /// Find <object> with @a name in @c this context
247 int resolve (const ACE_TString
&name
,
250 /// Delete object with @a name in @c this context
252 int unbind (const Name
&name
);
254 /// Delete object with @a name in @c this context
255 int unbind (const ACE_TString
&name
);
258 // The following interfaces are for Naming Context
260 /// Create new @c naming_context
261 int new_context (Naming_Context
&naming_context
);
264 * Insert <naming_context> with @a name relative to @c this context
265 * This will fail if @a name already exists
268 int bind_new_context (const Name
&name
,
269 Naming_Context
&naming_context
,
270 u_long persistence
= REG_OPTION_NON_VOLATILE
,
271 u_long security_access
= KEY_ALL_ACCESS
,
272 LPSECURITY_ATTRIBUTES security_attributes
= 0);
274 /// Insert <naming_context> with @a name relative to @c this context
275 /// This will fail if @a name already exists
276 int bind_new_context (const ACE_TString
&name
,
277 Naming_Context
&naming_context
,
278 u_long persistence
= REG_OPTION_NON_VOLATILE
,
279 u_long security_access
= KEY_ALL_ACCESS
,
280 LPSECURITY_ATTRIBUTES security_attributes
= 0);
283 * Insert or update <naming_context> with @a name relative to @c this context
284 * This will not fail if @a name already exists
287 int bind_context (const Name
&name
,
288 /* const */ Naming_Context
&naming_context
,
289 u_long persistence
= REG_OPTION_NON_VOLATILE
,
290 u_long security_access
= KEY_ALL_ACCESS
,
291 LPSECURITY_ATTRIBUTES security_attributes
= 0);
293 /// Insert or update <naming_context> with @a name relative to @c this context
294 /// This will not fail if @a name already exists
295 int bind_context (const ACE_TString
&name
,
296 /* const */ Naming_Context
&naming_context
,
297 u_long persistence
= REG_OPTION_NON_VOLATILE
,
298 u_long security_access
= KEY_ALL_ACCESS
,
299 LPSECURITY_ATTRIBUTES security_attributes
= 0);
301 /// Rename <naming_context> to @a name
303 int rebind_context (const Name
&name
,
304 /* const */ Naming_Context
&naming_context
);
306 /// Rename <naming_context> to @a name
307 int rebind_context (const ACE_TString
&name
,
308 /* const */ Naming_Context
&naming_context
);
310 /// Find <naming_context> with @a name in @c this context
312 int resolve_context (const Name
&name
,
313 Naming_Context
&naming_context
,
314 u_long security_access
= KEY_ALL_ACCESS
);
316 /// Find <naming_context> with @a name in @c this context
317 int resolve_context (const ACE_TString
&name
,
318 Naming_Context
&naming_context
,
319 u_long security_access
= KEY_ALL_ACCESS
);
321 /// Remove naming_context with @a name from @c this context
323 int unbind_context (const Name
&name
);
325 /// Remove naming_context with @a name from @c this context
326 int unbind_context (const ACE_TString
&name
);
328 /// Same as <unbind_context> with @c this as naming_context
332 * listing function: iterator creator
333 * This is useful when there are many objects and contexts
334 * in @c this context and you only want to look at a few entries
337 int list (u_long how_many
,
339 Binding_Iterator
&iterator
);
341 /// listing function: iterator creator
342 /// This gives back a listing of all entries in @c this context.
343 int list (Binding_List
&list
);
345 // Some other necessary functions which are
346 // not part of the CORBA interface
348 /// Sync content of context to disk
351 /// Close the handle of the context
352 /// @note <close> does not call <flush>
360 // void parent (HKEY parent);
366 void name (Name
&name
);
368 /// Set name (String version)
369 void name (ACE_TString
&name
);
371 /// Get name (String version)
379 void parent (HKEY parent
);
383 void name (const Name
&name
);
387 void name (const ACE_TString
&name
);
390 /// Disallow copy constructors
391 Naming_Context (const Naming_Context
&rhs
);
393 /// Disallow assignment
394 const Naming_Context
&operator= (const Naming_Context
&rhs
);
407 * @class Binding_Iterator
411 * Useful when iteratorating over a few entries at a time
413 class ACE_Export Binding_Iterator
417 friend class Naming_Context
;
419 /// Default constructor
423 int next_one (Binding
&binding
);
425 /// Next <how_many> entries
426 int next_n (u_long how_many
,
432 /// Reset the internal state of the iterator
435 /// Get naming_context that the iterator is iterating over
436 Naming_Context
&naming_context ();
439 /// Set naming_context that the iterator is iterating over
440 void naming_context (Naming_Context
& naming_context
);
442 /// Reference to context
443 Naming_Context
*naming_context_
;
446 // This should really be private
447 // But the compiler is broken
450 * @class Iteration_State
452 * Base class for state
454 class ACE_Export Iteration_State
461 virtual ~Iteration_State ();
463 /// Set the iterator reference.
464 void iterator (Binding_Iterator
*iterator
);
466 /// Next <how_many> entries
467 virtual int next_n (u_long how_many
,
468 Binding_List
&list
) = 0;
474 /// Pointer to parent iterator
475 Binding_Iterator
*parent_
;
481 class ACE_Export Object_Iteration
: public Iteration_State
483 /// Next <how_many> entries
484 int next_n (u_long how_many
,
488 class ACE_Export Context_Iteration
: public Iteration_State
491 /// Next @a how_many entries
492 int next_n (u_long how_many
,
496 class ACE_Export Iteration_Complete
: public Iteration_State
499 /// Next @a how_many entries
500 int next_n (u_long how_many
,
505 friend class Iteration_State
;
506 friend class Object_Iteration
;
507 friend class Context_Iteration
;
508 friend class Iteration_Complete
;
510 /// Instances of all states
511 Object_Iteration object_iteration_
;
512 Context_Iteration context_iteration_
;
513 Iteration_Complete iteration_complete_
;
515 /// Pointer to current state
516 Iteration_State
*current_enumeration_
;
518 /// Set current_enumeration
519 void current_enumeration (Iteration_State
& current_enumeration
);
521 /// Get current_enumeration
522 Iteration_State
¤t_enumeration ();
527 * @class ACE_Predefined_Naming_Contexts
529 * @brief A factory for predefined registries, which exist by default
532 * This factory can connect to both local and remote
533 * predefined registries.
535 class ACE_Export ACE_Predefined_Naming_Contexts
539 * Factory method for connecting to predefined registries. This
540 * method works for both remote and local machines. However, for
541 * remote machines, HKEY_CLASSES_ROOT and HKEY_CURRENT_USER types
544 static int connect (ACE_Registry::Naming_Context
&naming_context
,
545 HKEY predefined
= HKEY_LOCAL_MACHINE
,
546 const ACE_TCHAR
*machine_name
= 0);
549 /// Check if @a machine_name is the local host
550 static int is_local_host (const ACE_TCHAR
*machine_name
);
553 ACE_END_VERSIONED_NAMESPACE_DECL
555 #endif /* ACE_WIN32 */
556 #include /**/ "ace/post.h"
557 #endif /* ACE_REGISTRY_H */