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

Framework_Component.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 //=============================================================================
00003 /**
00004  *  @file    Framework_Component.h
00005  *
00006  *  $Id: Framework_Component.h,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00007  *
00008  * A prototype mechanism that allows framework components, singletons
00009  * such as ACE_Reactor, ACE_Proactor, etc, to be registered with a
00010  * central repository managed by the <ACE_Object_Manager> or
00011  * <ACE_Service_Config> that will handle destruction.
00012  *
00013  * This technique obviates changing ACE_Object_Manager and
00014  * ACE_Service_Config everytime a new framework is added.  Which also
00015  * means that unused framework components don't need to linked into
00016  * the final application which is important for applications with
00017  * stringent footprint requirements.
00018  *
00019  * Framework components need only provide a static method,
00020  * close_singleton() and add the ACE_REGISTER_FRAMEWORK_COMPONENT macro
00021  * call to their instance() methods in order to participate.  Components
00022  * that don't have a close_singleton() method can also participate via
00023  * template specialization of ACE_Framework_Component_T.
00024  *
00025  * This design uses the External Polymorphism pattern to avoid having
00026  * to derive all framework components from a common base class that
00027  * has virtual methods (this is crucial to avoid unnecessary overhead),
00028  * and is based on the dump debugging implementation found in
00029  * <ace/Dump.h>.
00030  *
00031  *  @author Don Hinton <dhinton@ieee.org>.
00032  */
00033 //=============================================================================
00034 
00035 #ifndef ACE_FRAMEWORK_COMPONENT_H
00036 #define ACE_FRAMEWORK_COMPONENT_H
00037 #include "ace/pre.h"
00038 
00039 #include "ace/Synch.h"
00040 
00041 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00042 # pragma once
00043 #endif /* ACE_LACKS_PRAGMA_ONCE */
00044 
00045 #define ACE_DEFAULT_FRAMEWORK_REPOSITORY_SIZE 1024
00046 
00047 /**
00048  * @class ACE_Framework_Component
00049  *
00050  * @brief Base class that defines a uniform interface for all managed
00051  * framework components.
00052  */
00053 class ACE_Export ACE_Framework_Component
00054 {
00055 public:
00056   friend class ACE_Framework_Repository;
00057 
00058   /// Constructor.
00059   ACE_Framework_Component (void *_this,
00060                            const ACE_TCHAR *dll_name = 0,
00061                            const ACE_TCHAR *name = 0);
00062 
00063   /// Close the contained singleton.
00064   virtual void close_singleton (void) = 0;
00065 
00066 protected:
00067   /// Destructor.
00068   virtual ~ACE_Framework_Component (void);
00069 
00070 private:
00071   /// Pointer to the actual component.
00072   const void *this_;
00073 
00074   /// Library associated with this component
00075   const ACE_TCHAR *dll_name_;
00076 
00077   /// Component name
00078   const ACE_TCHAR *name_;
00079 };
00080 
00081 /**
00082  * @class ACE_Framework_Repository
00083  *
00084  * @brief Contains all framework components used by an application.
00085  *
00086  * This class contains a vector of ACE_Framework_Component *'s.  On
00087  * destruction, framework components are destroyed in the reverse order
00088  * that they were added originally.
00089  */
00090 class ACE_Export ACE_Framework_Repository
00091 {
00092 public:
00093   // This is just to silence a compiler warning about no public ctors
00094   friend class ACE_Framework_Component;
00095 
00096   enum
00097   {
00098     DEFAULT_SIZE = ACE_DEFAULT_FRAMEWORK_REPOSITORY_SIZE
00099   };
00100 
00101   /// Close down the repository and free up dynamically allocated
00102   /// resources.
00103   ~ACE_Framework_Repository (void);
00104 
00105   /// Initialize the repository.
00106   int open (int size = DEFAULT_SIZE);
00107 
00108   /// Close down the repository and free up dynamically allocated
00109   /// resources, also called by dtor.
00110   int close (void);
00111 
00112   /// Get pointer to a process-wide <ACE_Framework_Repository>.
00113   static ACE_Framework_Repository *instance
00114     (int size = ACE_Framework_Repository::DEFAULT_SIZE);
00115 
00116   /// Delete the dynamically allocated Singleton.
00117   static void close_singleton (void);
00118 
00119   // = Search structure operations (all acquire locks as necessary).
00120 
00121   /// Insert a new component.  Returns -1 when the repository is full
00122   /// and 0 on success.
00123   int register_component (ACE_Framework_Component *fc);
00124 
00125   /// Remove a component.  Returns -1 on error or if component not found
00126   /// and 0 on success.
00127   int remove_component (const ACE_TCHAR *name);
00128 
00129   /// Remove all components associated with a particular dll.
00130   int remove_dll_components (const ACE_TCHAR *dll_name);
00131 
00132   /// Return the current size of the repository.
00133   int current_size (void) const;
00134 
00135   /// Return the total size of the repository.
00136   int total_size (void) const;
00137 
00138   /// Dump the state of an object.
00139   void dump (void) const;
00140 
00141   /// Declare the dynamic allocation hooks.
00142   ACE_ALLOC_HOOK_DECLARE;
00143 
00144 private:
00145   // = Initialization and termination methods.
00146 
00147   /// Initialize the repository.
00148   ACE_Framework_Repository (int size = ACE_Framework_Repository::DEFAULT_SIZE);
00149 
00150   /// Actually removes the dll components, must be called with locks held.
00151   int remove_dll_components_i (const ACE_TCHAR *dll_name);
00152 
00153   /// Compact component_vector_ after components have been removed__maintains
00154   /// order.
00155   void compact (void);
00156 
00157   /// Contains all the framework components.
00158   ACE_Framework_Component **component_vector_;
00159 
00160   /// Current number of components.
00161   int current_size_;
00162 
00163   /// Maximum number of components.
00164   int total_size_;
00165 
00166   /// Pointer to a process-wide ACE_Framework_Repository.
00167   static ACE_Framework_Repository *repository_;
00168 
00169   /// Flag set when repository is the process of shutting down.  This
00170   /// is necessary to keep from self-deadlocking since some of
00171   /// the components might make calls back to the repository to
00172   /// unload their components, e.g., ACE_DLL_Manager.
00173   static sig_atomic_t shutting_down_;
00174 
00175 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00176   /// Synchronization variable for the MT_SAFE Repository
00177   ACE_Thread_Mutex lock_;
00178 #endif /* ACE_MT_SAFE */
00179 
00180   /// Don't allow these to be called.
00181   ACE_UNIMPLEMENTED_FUNC (ACE_Framework_Repository (const ACE_Framework_Repository &))
00182   ACE_UNIMPLEMENTED_FUNC (ACE_Framework_Repository &operator= (const ACE_Framework_Repository &))
00183 };
00184 
00185 #if defined (__ACE_INLINE__)
00186 #include "ace/Framework_Component.inl"
00187 #endif /* __ACE_INLINE__ */
00188 
00189 // Include the templates classes at this point.
00190 #include "ace/Framework_Component_T.h"
00191 
00192 #include "ace/post.h"
00193 #endif /* ACE_FRAMEWORK_COMPONENT_H */

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