Registry.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Registry.h
00006  *
00007  *  Registry.h,v 4.39 2006/04/19 08:09:55 jwillemsen Exp
00008  *
00009  *  @author Irfan Pyarali (irfan@cs.wustl.edu)
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef ACE_REGISTRY_H
00015 #define ACE_REGISTRY_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/config-all.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #if defined (ACE_WIN32)
00025 // This only works on Win32 platforms
00026 
00027 #include "ace/Containers.h"
00028 #include "ace/SString.h"
00029 
00030 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00031 
00032 /**
00033  * @class ACE_Registry
00034  *
00035  * @brief A Name Server implementation
00036  *
00037  * The registry interface is inspired by the interface
00038  * specified in the CORBA Naming Service Specification.
00039  * The implementation is done through Win32 <Reg*> functions.
00040  * Other than providing an OO wrapper for the Win32 <Reg*>
00041  * functions, ACE_Registry provides an abstraction for iteration
00042  * over the elements of the Registry.
00043  */
00044 class ACE_Export ACE_Registry
00045 {
00046 public:
00047 
00048   /// International string
00049   struct ACE_Export Name_Component
00050   {
00051     ACE_TString id_;
00052     ACE_TString kind_;
00053 
00054     bool operator== (const Name_Component &rhs) const;
00055     bool operator!= (const Name_Component &rhs) const;
00056     // Comparison
00057   };
00058   // The <id_> field is used,
00059   // but the <kind_> field is currently ignored
00060 
00061   /// A Name is an ordered collections of components (ids)
00062   typedef ACE_Unbounded_Set<Name_Component> Name;
00063 
00064   /// Separator for components in a name
00065   static const ACE_TCHAR STRING_SEPARATOR[];
00066 
00067   /// Convert a @a name to a @c string
00068   static ACE_TString make_string (const Name &name);
00069 
00070   /// Convert a @a string to a @c name
00071   static Name make_name (const ACE_TString &string);
00072 
00073   /// There are two types of bindings
00074   enum Binding_Type {INVALID, OBJECT, CONTEXT};
00075 
00076   struct ACE_Export Binding
00077   {
00078     /// Empty (default) constructor
00079     Binding (void);
00080 
00081     /// Constructor
00082     /// (Name version)
00083     Binding (const Name &binding_name,
00084              Binding_Type binding_type);
00085 
00086     /// Constructor
00087     /// (String version)
00088     Binding (const ACE_TString &binding_name,
00089              Binding_Type binding_type);
00090 
00091     bool operator== (const Binding &rhs) const;
00092     bool operator!= (const Binding &rhs) const;
00093     // Comparison
00094 
00095     /// Name accessor
00096     /// (Name version)
00097     void name (Name &name);
00098 
00099     /// Set Name (String version)
00100     void name (ACE_TString &name);
00101 
00102     /// Get Name (String version)
00103     ACE_TString name (void);
00104 
00105     /// Type accessor
00106     Binding_Type type (void);
00107 
00108   private:
00109     /// A binding has a name
00110     ACE_TString name_;
00111 
00112     /// .... and a type
00113     Binding_Type type_;
00114   };
00115 
00116   /// A list of bindings
00117   typedef ACE_Unbounded_Set<Binding> Binding_List;
00118 
00119   // Forward declaration of iterator
00120   class Binding_Iterator;
00121 
00122   /**
00123    * @class Object
00124    *
00125    * @brief An object representation
00126    *
00127    * In CORBA, all objects inherit from (CORBA::Object).
00128    * For the registry, this is used as a wrapper for an
00129    * instance of a built-in data type.
00130    * Think about an object as being similar to a file
00131    * in a file system.
00132    */
00133   class ACE_Export Object
00134   {
00135   public:
00136     /// Default constructor
00137     Object (void *data = 0,
00138             u_long size = 0,
00139             u_long type = REG_NONE);
00140 
00141     /// Set data
00142     void data (void *data);
00143 
00144     /// Get data
00145     void *data (void) const;
00146 
00147     /// Set size
00148     void size (u_long size);
00149 
00150     /// Get size
00151     u_long size (void) const;
00152 
00153     /// Set type
00154     void type (u_long type);
00155 
00156     /// Get type
00157     u_long type (void) const;
00158 
00159   private:
00160     /// Pointer to data
00161     void *data_;
00162 
00163     /// Size of the data
00164     u_long size_;
00165 
00166     /// Type of data
00167     u_long type_;
00168   };
00169 
00170   /**
00171    * @class Naming_Context
00172    *
00173    * @brief An context representation
00174    *
00175    * Think about a context as being similar to a directory
00176    * in a file system.
00177    */
00178   class ACE_Export Naming_Context
00179   {
00180   public:
00181     /// Friend factory
00182     friend class ACE_Predefined_Naming_Contexts;
00183 
00184     enum {
00185       /// Max sizes of names
00186       /// (Not too sure about this value)
00187       MAX_OBJECT_NAME_SIZE = BUFSIZ,
00188 
00189       /// Max size of context name
00190       MAX_CONTEXT_NAME_SIZE = MAXPATHLEN + 1
00191     };
00192 
00193     /// Empty constructor: keys will be NULL
00194     Naming_Context (void);
00195 
00196     /// Constructor: key_ will be set to <key>
00197     Naming_Context (const HKEY &key);
00198 
00199     /// Destructor will call <Naming_Context::close>.
00200     ~Naming_Context (void);
00201 
00202     // The following interfaces are for objects
00203 
00204     /**
00205      * Insert @a object with @a name into @c this context.
00206      * This will fail if @a name already exists
00207      * (Name version)
00208      */
00209     int bind_new (const Name &name,
00210                   const Object &object);
00211 
00212     /**
00213      * Insert @a object with @a name into @c this context
00214      * This will fail if @a name already exists
00215      * (String version)
00216      */
00217     int bind_new (const ACE_TString &name,
00218                   const Object &object);
00219 
00220     /**
00221      * Insert or update @a object with @a name into @c this context
00222      * This will not fail if @a name already exists
00223      * (Name version)
00224      */
00225     int bind (const Name &name,
00226               const Object &object);
00227 
00228     /**
00229      * Insert or update <object> with <name> into <this> context
00230      * This will not fail if <name> already exists
00231      * (String version)
00232      */
00233     int bind (const ACE_TString &name,
00234               const Object &object);
00235 
00236     /// Update <object> with <name> in <this> context
00237     /// (Name version)
00238     int rebind (const Name &name,
00239                 const Object &object);
00240 
00241     /// Update <object> with <name> in <this> context
00242     int rebind (const ACE_TString &name,
00243                 const Object &object);
00244 
00245     /// Find <object> with <name> in <this> context
00246     /// (Name version)
00247     int resolve (const Name &name,
00248                  Object &object);
00249 
00250     /// Find <object> with <name> in <this> context
00251     int resolve (const ACE_TString &name,
00252                  Object &object);
00253 
00254     /// Delete object with <name> in <this> context
00255     /// (Name version)
00256     int unbind (const Name &name);
00257 
00258     /// Delete object with <name> in <this> context
00259     int unbind (const ACE_TString &name);
00260 
00261 
00262     // The following interfaces are for Naming Context
00263 
00264     /// Create new @c naming_context
00265     int new_context (Naming_Context &naming_context);
00266 
00267     /**
00268      * Insert <naming_context> with <name> relative to <this> context
00269      * This will fail if <name> already exists
00270      * (Name version)
00271      */
00272     int bind_new_context (const Name &name,
00273                           Naming_Context &naming_context,
00274                           u_long persistence = REG_OPTION_NON_VOLATILE,
00275                           u_long security_access = KEY_ALL_ACCESS,
00276                           LPSECURITY_ATTRIBUTES security_attributes = 0);
00277 
00278     /// Insert <naming_context> with <name> relative to <this> context
00279     /// This will fail if <name> already exists
00280     int bind_new_context (const ACE_TString &name,
00281                           Naming_Context &naming_context,
00282                           u_long persistence = REG_OPTION_NON_VOLATILE,
00283                           u_long security_access = KEY_ALL_ACCESS,
00284                           LPSECURITY_ATTRIBUTES security_attributes = 0);
00285 
00286     /**
00287      * Insert or update <naming_context> with <name> relative to <this> context
00288      * This will not fail if <name> already exists
00289      * (Name version)
00290      */
00291     int bind_context (const Name &name,
00292                       /* const */ Naming_Context &naming_context,
00293                       u_long persistence = REG_OPTION_NON_VOLATILE,
00294                       u_long security_access = KEY_ALL_ACCESS,
00295                       LPSECURITY_ATTRIBUTES security_attributes = 0);
00296 
00297     /// Insert or update <naming_context> with <name> relative to <this> context
00298     /// This will not fail if <name> already exists
00299     int bind_context (const ACE_TString &name,
00300                       /* const */ Naming_Context &naming_context,
00301                       u_long persistence = REG_OPTION_NON_VOLATILE,
00302                       u_long security_access = KEY_ALL_ACCESS,
00303                       LPSECURITY_ATTRIBUTES security_attributes = 0);
00304 
00305     /// Rename <naming_context> to <name>
00306     /// (Name version)
00307     int rebind_context (const Name &name,
00308                         /* const */ Naming_Context &naming_context);
00309 
00310     /// Rename <naming_context> to <name>
00311     int rebind_context (const ACE_TString &name,
00312                         /* const */ Naming_Context &naming_context);
00313 
00314     /// Find <naming_context> with <name> in <this> context
00315     /// (Name version)
00316     int resolve_context (const Name &name,
00317                          Naming_Context &naming_context,
00318                          u_long security_access = KEY_ALL_ACCESS);
00319 
00320     /// Find <naming_context> with <name> in <this> context
00321     int resolve_context (const ACE_TString &name,
00322                          Naming_Context &naming_context,
00323                          u_long security_access = KEY_ALL_ACCESS);
00324 
00325     /// Remove naming_context with <name> from <this> context
00326     /// (Name version)
00327     int unbind_context (const Name &name);
00328 
00329     /// Remove naming_context with <name> from <this> context
00330     int unbind_context (const ACE_TString &name);
00331 
00332     /// Same as <unbind_context> with <this> as naming_context
00333     int destroy (void);
00334 
00335     /**
00336      * listing function: iterator creator
00337      * This is useful when there are many objects and contexts
00338      * in <this> context and you only want to look at a few entries
00339      * at a time
00340      */
00341     int list (u_long how_many,
00342               Binding_List &list,
00343               Binding_Iterator &iterator);
00344 
00345     /// listing function: iterator creator
00346     /// This gives back a listing of all entries in <this> context.
00347     int list (Binding_List &list);
00348 
00349     // Some other necessary functions which are
00350     // not part of the CORBA interface
00351 
00352     /// Sync content of context to disk
00353     int flush (void);
00354 
00355     /// Close the handle of the context
00356     /// @note <close> does not call <flush>
00357     int close (void);
00358 
00359     // Accessors
00360 
00361     /// Get key
00362     HKEY key (void);
00363 
00364     // void parent (HKEY parent);
00365     /// Get parent
00366     HKEY parent (void);
00367 
00368     /// Get name
00369     /// (Name version)
00370     void name (Name &name);
00371 
00372     /// Set name (String version)
00373     void name (ACE_TString &name);
00374 
00375     /// Get name (String version)
00376     ACE_TString name (void);
00377 
00378   protected:
00379     /// Set key
00380     void key (HKEY key);
00381 
00382     /// Set parent
00383     void parent (HKEY parent);
00384 
00385     /// Set name
00386     /// (Name version)
00387     void name (const Name &name);
00388 
00389     /// Set name
00390     /// (String version)
00391     void name (const ACE_TString &name);
00392 
00393   private:
00394     /// Disallow copy constructors
00395     Naming_Context (const Naming_Context &rhs);
00396 
00397     /// Disallow assignment
00398     const Naming_Context &operator= (const Naming_Context &rhs);
00399 
00400     /// Key for self
00401     HKEY key_;
00402 
00403     /// Key for parent
00404     HKEY parent_key_;
00405 
00406     /// Name of self
00407     ACE_TString name_;
00408   };
00409 
00410   /**
00411    * @class Binding_Iterator
00412    *
00413    * @brief An iterator
00414    *
00415    * Useful when iteratorating over a few entries at a time
00416    */
00417   class ACE_Export Binding_Iterator
00418   {
00419   public:
00420     /// Friend factory
00421     friend class Naming_Context;
00422 
00423     /// Default constructor
00424     Binding_Iterator (void);
00425 
00426     /// Next entry
00427     int next_one (Binding &binding);
00428 
00429     /// Next <how_many> entries
00430     int next_n (u_long how_many,
00431                 Binding_List &list);
00432 
00433     /// Cleanup
00434     int destroy (void);
00435 
00436     /// Reset the internal state of the iterator
00437     void reset (void);
00438 
00439     /// Get naming_context that the iterator is iterating over
00440     Naming_Context &naming_context (void);
00441 
00442   private:
00443 
00444     /// Set naming_context that the iterator is iterating over
00445     void naming_context (Naming_Context& naming_context);
00446 
00447     /// Reference to context
00448     Naming_Context *naming_context_;
00449 
00450   public:
00451     // This should really be private
00452     // But the compiler is broken
00453 
00454     /**
00455      * @class Iteration_State
00456      *
00457      * Base class for state
00458      */
00459     class ACE_Export Iteration_State
00460       {
00461       public:
00462         /// Constructor
00463         Iteration_State (Binding_Iterator &iterator);
00464 
00465         /// Next <how_many> entries
00466         virtual int next_n (u_long how_many,
00467                             Binding_List &list) = 0;
00468 
00469         /// Reset state
00470         void reset (void);
00471 
00472       protected:
00473         /// Pointer to parent iterator
00474         Binding_Iterator *parent_;
00475 
00476         u_long index_;
00477       };
00478 
00479   private:
00480     class ACE_Export Object_Iteration : public Iteration_State
00481       {
00482       public:
00483         Object_Iteration (Binding_Iterator &iterator);
00484 
00485         /// Next <how_many> entries
00486         int next_n (u_long how_many,
00487                     Binding_List &list);
00488       };
00489 
00490     class ACE_Export Context_Iteration : public Iteration_State
00491       {
00492       public:
00493         Context_Iteration (Binding_Iterator &iterator);
00494 
00495         /// Next @a how_many entries
00496         int next_n (u_long how_many,
00497                     Binding_List &list);
00498       };
00499 
00500     class ACE_Export Iteration_Complete : public Iteration_State
00501       {
00502       public:
00503         Iteration_Complete (Binding_Iterator &iterator);
00504 
00505         /// Next @a how_many entries
00506         int next_n (u_long how_many,
00507                     Binding_List &list);
00508       };
00509 
00510     /// Friend states
00511     friend class Iteration_State;
00512     friend class Object_Iteration;
00513     friend class Context_Iteration;
00514     friend class Iteration_Complete;
00515 
00516     /// Instances of all states
00517     Object_Iteration object_iteration_;
00518     Context_Iteration context_iteration_;
00519     Iteration_Complete iteration_complete_;
00520 
00521     /// Pointer to current state
00522     Iteration_State *current_enumeration_;
00523 
00524     /// Set current_enumeration
00525     void current_enumeration (Iteration_State& current_enumeration);
00526 
00527     /// Get current_enumeration
00528     Iteration_State &current_enumeration (void);
00529   };
00530 };
00531 
00532 /**
00533  * @class ACE_Predefined_Naming_Contexts
00534  *
00535  * @brief A factory for predefined registries, which exist by default
00536  * on Win32 platforms
00537  *
00538  * This factory can connect to both local and remote
00539  * predefined registries.
00540  */
00541 class ACE_Export ACE_Predefined_Naming_Contexts
00542 {
00543 public:
00544   /**
00545    * Factory method for connecting to predefined registries.  This
00546    * method works for both remote and local machines.  However, for
00547    * remote machines, HKEY_CLASSES_ROOT and HKEY_CURRENT_USER types
00548    * are not allowed
00549    */
00550   static int connect (ACE_Registry::Naming_Context &naming_context,
00551                       HKEY predefined = HKEY_LOCAL_MACHINE,
00552                       const ACE_TCHAR *machine_name = 0);
00553 
00554 private:
00555   /// Check if @a machine_name is the local host
00556   static int is_local_host (const ACE_TCHAR *machine_name);
00557 };
00558 
00559 ACE_END_VERSIONED_NAMESPACE_DECL
00560 
00561 #endif /* ACE_WIN32 */
00562 #include /**/ "ace/post.h"
00563 #endif /* ACE_REGISTRY_H */

Generated on Thu Nov 9 09:42:01 2006 for ACE by doxygen 1.3.6