3 //=============================================================================
7 * $Id: Registry.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Irfan Pyarali (irfan@cs.wustl.edu)
11 //=============================================================================
14 #ifndef ACE_REGISTRY_H
15 #define ACE_REGISTRY_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/config-all.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
25 // This only works on registry-capable Win32 platforms.
27 #include "ace/Containers.h"
28 #include "ace/SString.h"
30 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 * @brief A Name Server implementation
37 * The registry interface is inspired by the interface
38 * specified in the CORBA Naming Service Specification.
39 * The implementation is done through Win32 <Reg*> functions.
40 * Other than providing an OO wrapper for the Win32 <Reg*>
41 * functions, ACE_Registry provides an abstraction for iteration
42 * over the elements of the Registry.
44 class ACE_Export ACE_Registry
48 /// International string
49 struct ACE_Export Name_Component
54 bool operator== (const Name_Component
&rhs
) const;
55 bool operator!= (const Name_Component
&rhs
) const;
58 // The <id_> field is used,
59 // but the <kind_> field is currently ignored
61 /// A Name is an ordered collections of components (ids)
62 typedef ACE_Unbounded_Set
<Name_Component
> Name
;
64 /// Separator for components in a name
65 static const ACE_TCHAR STRING_SEPARATOR
[];
67 /// Convert a @a name to a @c string
68 static ACE_TString
make_string (const Name
&name
);
70 /// Convert a @a string to a @c name
71 static Name
make_name (const ACE_TString
&string
);
73 /// There are two types of bindings
74 enum Binding_Type
{INVALID
, OBJECT
, CONTEXT
};
76 struct ACE_Export Binding
78 /// Empty (default) constructor
83 Binding (const Name
&binding_name
,
84 Binding_Type binding_type
);
88 Binding (const ACE_TString
&binding_name
,
89 Binding_Type binding_type
);
91 bool operator== (const Binding
&rhs
) const;
92 bool operator!= (const Binding
&rhs
) const;
97 void name (Name
&name
);
99 /// Set Name (String version)
100 void name (ACE_TString
&name
);
102 /// Get Name (String version)
103 ACE_TString
name (void);
106 Binding_Type
type (void);
109 /// A binding has a name
116 /// A list of bindings
117 typedef ACE_Unbounded_Set
<Binding
> Binding_List
;
119 // Forward declaration of iterator
120 class Binding_Iterator
;
125 * @brief An object representation
127 * In CORBA, all objects inherit from (CORBA::Object).
128 * For the registry, this is used as a wrapper for an
129 * instance of a built-in data type.
130 * Think about an object as being similar to a file
133 class ACE_Export Object
136 /// Default constructor
137 Object (void *data
= 0,
139 u_long type
= REG_NONE
);
142 void data (void *data
);
145 void *data (void) const;
148 void size (u_long size
);
151 u_long
size (void) const;
154 void type (u_long type
);
157 u_long
type (void) const;
171 * @class Naming_Context
173 * @brief An context representation
175 * Think about a context as being similar to a directory
178 class ACE_Export Naming_Context
182 friend class ACE_Predefined_Naming_Contexts
;
185 /// Max sizes of names
186 /// (Not too sure about this value)
187 MAX_OBJECT_NAME_SIZE
= BUFSIZ
,
189 /// Max size of context name
190 MAX_CONTEXT_NAME_SIZE
= MAXPATHLEN
+ 1
193 /// Empty constructor: keys will be NULL
194 Naming_Context (void);
196 /// Constructor: key_ will be set to @a key
197 Naming_Context (const HKEY
&key
);
199 /// Destructor will call <Naming_Context::close>.
200 ~Naming_Context (void);
202 // The following interfaces are for objects
205 * Insert @a object with @a name into @c this context.
206 * This will fail if @a name already exists
209 int bind_new (const Name
&name
,
210 const Object
&object
);
213 * Insert @a object with @a name into @c this context
214 * This will fail if @a name already exists
217 int bind_new (const ACE_TString
&name
,
218 const Object
&object
);
221 * Insert or update @a object with @a name into @c this context
222 * This will not fail if @a name already exists
225 int bind (const Name
&name
,
226 const Object
&object
);
229 * Insert or update <object> with @a name into @c this context
230 * This will not fail if @a name already exists
233 int bind (const ACE_TString
&name
,
234 const Object
&object
);
236 /// Update <object> with @a name in @c this context
238 int rebind (const Name
&name
,
239 const Object
&object
);
241 /// Update <object> with @a name in @c this context
242 int rebind (const ACE_TString
&name
,
243 const Object
&object
);
245 /// Find <object> with @a name in @c this context
247 int resolve (const Name
&name
,
250 /// Find <object> with @a name in @c this context
251 int resolve (const ACE_TString
&name
,
254 /// Delete object with @a name in @c this context
256 int unbind (const Name
&name
);
258 /// Delete object with @a name in @c this context
259 int unbind (const ACE_TString
&name
);
262 // The following interfaces are for Naming Context
264 /// Create new @c naming_context
265 int new_context (Naming_Context
&naming_context
);
268 * Insert <naming_context> with @a name relative to @c this context
269 * This will fail if @a name already exists
272 int bind_new_context (const Name
&name
,
273 Naming_Context
&naming_context
,
274 u_long persistence
= REG_OPTION_NON_VOLATILE
,
275 u_long security_access
= KEY_ALL_ACCESS
,
276 LPSECURITY_ATTRIBUTES security_attributes
= 0);
278 /// Insert <naming_context> with @a name relative to @c this context
279 /// This will fail if @a name already exists
280 int bind_new_context (const ACE_TString
&name
,
281 Naming_Context
&naming_context
,
282 u_long persistence
= REG_OPTION_NON_VOLATILE
,
283 u_long security_access
= KEY_ALL_ACCESS
,
284 LPSECURITY_ATTRIBUTES security_attributes
= 0);
287 * Insert or update <naming_context> with @a name relative to @c this context
288 * This will not fail if @a name already exists
291 int bind_context (const Name
&name
,
292 /* const */ Naming_Context
&naming_context
,
293 u_long persistence
= REG_OPTION_NON_VOLATILE
,
294 u_long security_access
= KEY_ALL_ACCESS
,
295 LPSECURITY_ATTRIBUTES security_attributes
= 0);
297 /// Insert or update <naming_context> with @a name relative to @c this context
298 /// This will not fail if @a name already exists
299 int bind_context (const ACE_TString
&name
,
300 /* const */ Naming_Context
&naming_context
,
301 u_long persistence
= REG_OPTION_NON_VOLATILE
,
302 u_long security_access
= KEY_ALL_ACCESS
,
303 LPSECURITY_ATTRIBUTES security_attributes
= 0);
305 /// Rename <naming_context> to @a name
307 int rebind_context (const Name
&name
,
308 /* const */ Naming_Context
&naming_context
);
310 /// Rename <naming_context> to @a name
311 int rebind_context (const ACE_TString
&name
,
312 /* const */ Naming_Context
&naming_context
);
314 /// Find <naming_context> with @a name in @c this context
316 int resolve_context (const Name
&name
,
317 Naming_Context
&naming_context
,
318 u_long security_access
= KEY_ALL_ACCESS
);
320 /// Find <naming_context> with @a name in @c this context
321 int resolve_context (const ACE_TString
&name
,
322 Naming_Context
&naming_context
,
323 u_long security_access
= KEY_ALL_ACCESS
);
325 /// Remove naming_context with @a name from @c this context
327 int unbind_context (const Name
&name
);
329 /// Remove naming_context with @a name from @c this context
330 int unbind_context (const ACE_TString
&name
);
332 /// Same as <unbind_context> with @c this as naming_context
336 * listing function: iterator creator
337 * This is useful when there are many objects and contexts
338 * in @c this context and you only want to look at a few entries
341 int list (u_long how_many
,
343 Binding_Iterator
&iterator
);
345 /// listing function: iterator creator
346 /// This gives back a listing of all entries in @c this context.
347 int list (Binding_List
&list
);
349 // Some other necessary functions which are
350 // not part of the CORBA interface
352 /// Sync content of context to disk
355 /// Close the handle of the context
356 /// @note <close> does not call <flush>
364 // void parent (HKEY parent);
370 void name (Name
&name
);
372 /// Set name (String version)
373 void name (ACE_TString
&name
);
375 /// Get name (String version)
376 ACE_TString
name (void);
383 void parent (HKEY parent
);
387 void name (const Name
&name
);
391 void name (const ACE_TString
&name
);
394 /// Disallow copy constructors
395 Naming_Context (const Naming_Context
&rhs
);
397 /// Disallow assignment
398 const Naming_Context
&operator= (const Naming_Context
&rhs
);
411 * @class Binding_Iterator
415 * Useful when iteratorating over a few entries at a time
417 class ACE_Export Binding_Iterator
421 friend class Naming_Context
;
423 /// Default constructor
424 Binding_Iterator (void);
427 int next_one (Binding
&binding
);
429 /// Next <how_many> entries
430 int next_n (u_long how_many
,
436 /// Reset the internal state of the iterator
439 /// Get naming_context that the iterator is iterating over
440 Naming_Context
&naming_context (void);
444 /// Set naming_context that the iterator is iterating over
445 void naming_context (Naming_Context
& naming_context
);
447 /// Reference to context
448 Naming_Context
*naming_context_
;
451 // This should really be private
452 // But the compiler is broken
455 * @class Iteration_State
457 * Base class for state
459 class ACE_Export Iteration_State
465 /// Set the iterator reference.
466 void iterator (Binding_Iterator
*iterator
);
468 /// Next <how_many> entries
469 virtual int next_n (u_long how_many
,
470 Binding_List
&list
) = 0;
476 /// Pointer to parent iterator
477 Binding_Iterator
*parent_
;
483 class ACE_Export Object_Iteration
: public Iteration_State
485 /// Next <how_many> entries
486 int next_n (u_long how_many
,
490 class ACE_Export Context_Iteration
: public Iteration_State
493 /// Next @a how_many entries
494 int next_n (u_long how_many
,
498 class ACE_Export Iteration_Complete
: public Iteration_State
501 /// Next @a how_many entries
502 int next_n (u_long how_many
,
507 friend class Iteration_State
;
508 friend class Object_Iteration
;
509 friend class Context_Iteration
;
510 friend class Iteration_Complete
;
512 /// Instances of all states
513 Object_Iteration object_iteration_
;
514 Context_Iteration context_iteration_
;
515 Iteration_Complete iteration_complete_
;
517 /// Pointer to current state
518 Iteration_State
*current_enumeration_
;
520 /// Set current_enumeration
521 void current_enumeration (Iteration_State
& current_enumeration
);
523 /// Get current_enumeration
524 Iteration_State
¤t_enumeration (void);
529 * @class ACE_Predefined_Naming_Contexts
531 * @brief A factory for predefined registries, which exist by default
534 * This factory can connect to both local and remote
535 * predefined registries.
537 class ACE_Export ACE_Predefined_Naming_Contexts
541 * Factory method for connecting to predefined registries. This
542 * method works for both remote and local machines. However, for
543 * remote machines, HKEY_CLASSES_ROOT and HKEY_CURRENT_USER types
546 static int connect (ACE_Registry::Naming_Context
&naming_context
,
547 HKEY predefined
= HKEY_LOCAL_MACHINE
,
548 const ACE_TCHAR
*machine_name
= 0);
551 /// Check if @a machine_name is the local host
552 static int is_local_host (const ACE_TCHAR
*machine_name
);
555 ACE_END_VERSIONED_NAMESPACE_DECL
557 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */
558 #include /**/ "ace/post.h"
559 #endif /* ACE_REGISTRY_H */