Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Registry.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Registry.h
00006  *
00007  *  $Id: Registry.h,v 1.1.1.4 2003/02/21 18:36:32 chad 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/OS.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 /**
00031  * @class ACE_Registry
00032  *
00033  * @brief A Name Server implementation
00034  *
00035  * The registry interface is inspired by the interface
00036  * specified in the CORBA Naming Service Specification.
00037  * The implementation is done through Win32 <Reg*> functions.
00038  * Other than providing an OO wrapper for the Win32 <Reg*>
00039  * functions, ACE_Registry provides an abstraction for iteration
00040  * over the elements of the Registry.
00041  */
00042 class ACE_Export ACE_Registry
00043 {
00044 public:
00045 
00046   /// International string
00047   struct ACE_Export Name_Component
00048   {
00049     ACE_TString id_;
00050     ACE_TString kind_;
00051 
00052     int operator== (const Name_Component &rhs) const;
00053     int operator!= (const Name_Component &rhs) const;
00054     // Comparison
00055   };
00056   // The <id_> field is used,
00057   // but the <kind_> field is currently ignored
00058 
00059   /// A Name is an ordered collections of components (ids)
00060   typedef ACE_Unbounded_Set<Name_Component> Name;
00061 
00062   /// Separator for components in a name
00063   static const ACE_TCHAR *STRING_SEPARATOR;
00064 
00065   /// Convert a <name> to a <string>
00066   static ACE_TString make_string (const Name &name);
00067 
00068   /// Convert a <string> to a <name>
00069   static Name make_name (const ACE_TString &string);
00070 
00071   /// There are two types of bindings
00072   enum Binding_Type {INVALID, OBJECT, CONTEXT};
00073 
00074   struct ACE_Export Binding
00075   {
00076     /// Empty (default) constructor
00077     Binding (void);
00078 
00079     /// Constructor
00080     /// (Name version)
00081     Binding (const Name &binding_name,
00082              Binding_Type binding_type);
00083 
00084     /// Constructor
00085     /// (String version)
00086     Binding (const ACE_TString &binding_name,
00087              Binding_Type binding_type);
00088 
00089     int operator== (const Binding &rhs) const;
00090     int operator!= (const Binding &rhs) const;
00091     // Comparison
00092 
00093     /// Name accessor
00094     /// (Name version)
00095     void name (Name &name);
00096 
00097     /// Set Name (String version)
00098     void name (ACE_TString &name);
00099 
00100     /// Get Name (String version)
00101     ACE_TString name (void);
00102 
00103     /// Type accessor
00104     Binding_Type type (void);
00105 
00106   private:
00107     /// A binding has a name
00108     ACE_TString name_;
00109 
00110     /// .... and a type
00111     Binding_Type type_;
00112   };
00113 
00114   // A list of bindings
00115   typedef ACE_Unbounded_Set<Binding> Binding_List;
00116 
00117   // Forward declaration of iterator
00118   class Binding_Iterator;
00119 
00120   /**
00121    * @class Object
00122    *
00123    * @brief An object representation
00124    *
00125    * In CORBA, all objects inherit from (CORBA::Object).
00126    * For the registry, this is used as a wrapper for an
00127    * instance of a built-in data type.
00128    * Think about an object as being similar to a file
00129    * in a file system.
00130    */
00131   class ACE_Export Object
00132   {
00133   public:
00134     /// Default constructor
00135     Object (void *data = 0,
00136             u_long size = 0,
00137             u_long type = REG_NONE);
00138 
00139     /// Set data
00140     void data (void *data);
00141 
00142     /// Get data
00143     void *data (void) const;
00144 
00145     /// Set size
00146     void size (u_long size);
00147 
00148     /// Get size
00149     u_long size (void) const;
00150 
00151     /// Set type
00152     void type (u_long type);
00153 
00154     /// Get type
00155     u_long type (void) const;
00156 
00157   private:
00158     /// Pointer to data
00159     void *data_;
00160 
00161     /// Size of the data
00162     u_long size_;
00163 
00164     /// Type of data
00165     u_long type_;
00166   };
00167 
00168   /**
00169    * @class Naming_Context
00170    *
00171    * @brief An context representation
00172    *
00173    * Think about a context as being similar to a directory
00174    * in a file system.
00175    */
00176   class ACE_Export Naming_Context
00177   {
00178   public:
00179     /// Friend factory
00180     friend class ACE_Predefined_Naming_Contexts;
00181 
00182     enum {
00183       /// Max sizes of names
00184       /// (Not too sure about this value)
00185       MAX_OBJECT_NAME_SIZE = BUFSIZ,
00186 
00187       /// Max size of context name
00188       MAX_CONTEXT_NAME_SIZE = MAXPATHLEN + 1
00189     };
00190 
00191     /// Empty constructor: keys will be NULL
00192     Naming_Context (void);
00193 
00194     /// Constructor: key_ will be set to <key>
00195     Naming_Context (const HKEY &key);
00196 
00197     /// Destructor will call <Naming_Context::close>.
00198     ~Naming_Context (void);
00199 
00200     // The following interfaces are for objects
00201 
00202     /**
00203      * Insert <object> with <name> into <this> context
00204      * This will fail if <name> already exists
00205      * (Name version)
00206      */
00207     int bind_new (const Name &name,
00208                   const Object &object);
00209 
00210     /**
00211      * Insert <object> with <name> into <this> context
00212      * This will fail if <name> already exists
00213      * (String version)
00214      */
00215     int bind_new (const ACE_TString &name,
00216                   const Object &object);
00217 
00218     /**
00219      * Insert or update <object> with <name> into <this> context
00220      * This will not fail if <name> already exists
00221      * (Name version)
00222      */
00223     int bind (const Name &name,
00224               const Object &object);
00225 
00226     /**
00227      * Insert or update <object> with <name> into <this> context
00228      * This will not fail if <name> already exists
00229      * (String version)
00230      */
00231     int bind (const ACE_TString &name,
00232               const Object &object);
00233 
00234     /// Update <object> with <name> in <this> context
00235     /// (Name version)
00236     int rebind (const Name &name,
00237                 const Object &object);
00238 
00239     /// Update <object> with <name> in <this> context
00240     int rebind (const ACE_TString &name,
00241                 const Object &object);
00242 
00243     /// Find <object> with <name> in <this> context
00244     /// (Name version)
00245     int resolve (const Name &name,
00246                  Object &object);
00247 
00248     /// Find <object> with <name> in <this> context
00249     int resolve (const ACE_TString &name,
00250                  Object &object);
00251 
00252     /// Delete object with <name> in <this> context
00253     /// (Name version)
00254     int unbind (const Name &name);
00255 
00256     /// Delete object with <name> in <this> context
00257     int unbind (const ACE_TString &name);
00258 
00259 
00260     // The following interfaces are for Naming Context
00261 
00262     /// Create new <naming_context>
00263     int new_context (Naming_Context &naming_context);
00264 
00265     /**
00266      * Insert <naming_context> with <name> relative to <this> context
00267      * This will fail if <name> already exists
00268      * (Name version)
00269      */
00270     int bind_new_context (const Name &name,
00271                           Naming_Context &naming_context,
00272                           u_long persistence = REG_OPTION_NON_VOLATILE,
00273                           u_long security_access = KEY_ALL_ACCESS,
00274                           LPSECURITY_ATTRIBUTES security_attributes = 0);
00275 
00276     /// Insert <naming_context> with <name> relative to <this> context
00277     /// This will fail if <name> already exists
00278     int bind_new_context (const ACE_TString &name,
00279                           Naming_Context &naming_context,
00280                           u_long persistence = REG_OPTION_NON_VOLATILE,
00281                           u_long security_access = KEY_ALL_ACCESS,
00282                           LPSECURITY_ATTRIBUTES security_attributes = 0);
00283 
00284     /**
00285      * Insert or update <naming_context> with <name> relative to <this> context
00286      * This will not fail if <name> already exists
00287      * (Name version)
00288      */
00289     int bind_context (const Name &name,
00290                       /* const */ Naming_Context &naming_context,
00291                       u_long persistence = REG_OPTION_NON_VOLATILE,
00292                       u_long security_access = KEY_ALL_ACCESS,
00293                       LPSECURITY_ATTRIBUTES security_attributes = 0);
00294 
00295     /// Insert or update <naming_context> with <name> relative to <this> context
00296     /// This will not fail if <name> already exists
00297     int bind_context (const ACE_TString &name,
00298                       /* const */ Naming_Context &naming_context,
00299                       u_long persistence = REG_OPTION_NON_VOLATILE,
00300                       u_long security_access = KEY_ALL_ACCESS,
00301                       LPSECURITY_ATTRIBUTES security_attributes = 0);
00302 
00303     /// Rename <naming_context> to <name>
00304     /// (Name version)
00305     int rebind_context (const Name &name,
00306                         /* const */ Naming_Context &naming_context);
00307 
00308     /// Rename <naming_context> to <name>
00309     int rebind_context (const ACE_TString &name,
00310                         /* const */ Naming_Context &naming_context);
00311 
00312     /// Find <naming_context> with <name> in <this> context
00313     /// (Name version)
00314     int resolve_context (const Name &name,
00315                          Naming_Context &naming_context,
00316                          u_long security_access = KEY_ALL_ACCESS);
00317 
00318     /// Find <naming_context> with <name> in <this> context
00319     int resolve_context (const ACE_TString &name,
00320                          Naming_Context &naming_context,
00321                          u_long security_access = KEY_ALL_ACCESS);
00322 
00323     /// Remove naming_context with <name> from <this> context
00324     /// (Name version)
00325     int unbind_context (const Name &name);
00326 
00327     /// Remove naming_context with <name> from <this> context
00328     int unbind_context (const ACE_TString &name);
00329 
00330     /// Same as <unbind_context> with <this> as naming_context
00331     int destroy (void);
00332 
00333     /**
00334      * listing function: iterator creator
00335      * This is useful when there are many objects and contexts
00336      * in <this> context and you only want to look at a few entries
00337      * at a time
00338      */
00339     int list (u_long how_many,
00340               Binding_List &list,
00341               Binding_Iterator &iterator);
00342 
00343     /// listing function: iterator creator
00344     /// This gives back a listing of all entries in <this> context.
00345     int list (Binding_List &list);
00346 
00347 
00348     // Some other necessary functions which are
00349     // not part of the CORBA interface
00350 
00351     /// Sync content of context to disk
00352     int flush (void);
00353 
00354     /// Close the handle of the context
00355     /// Note: <close> does not call <flush>
00356     int close (void);
00357 
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 <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 <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 <machine_name> is the local host
00556   static int is_local_host (const ACE_TCHAR *machine_name);
00557 };
00558 
00559 // Fix me!  Shouldn't have to define this stuff
00560 
00561 #if defined (ACE_HAS_BROKEN_NESTED_TEMPLATES)
00562   typedef ACE_Registry::Name_Component Name_Component;
00563   typedef ACE_Registry::Binding Binding;
00564 #endif /* ACE_HAS_BROKEN_NESTED_TEMPLATES */
00565 
00566 #endif /* ACE_WIN32 */
00567 #include "ace/post.h"
00568 #endif /* ACE_REGISTRY_H */

Generated on Mon Jun 16 11:21:03 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002