Object_Manager_Base.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Object_Manager_Base.h
00006  *
00007  *  Object_Manager_Base.h,v 1.10 2006/05/30 13:15:25 schmidt Exp
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  *  @author Jesper S. M|ller<stophph@diku.dk>
00011  *  @author and a cast of thousands...
00012  *
00013  *  Originally in OS.h.
00014  */
00015 //=============================================================================
00016 
00017 #ifndef ACE_OBJECT_MANAGER_BASE_H
00018 #define ACE_OBJECT_MANAGER_BASE_H
00019 #include /**/ "ace/pre.h"
00020 
00021 #include "ace/config-lite.h"
00022 
00023 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00024 # pragma once
00025 #endif /* ACE_LACKS_PRAGMA_ONCE */
00026 
00027 #include "ace/ACE_export.h"
00028 #include "ace/Cleanup.h"
00029 #include "ace/os_include/sys/os_types.h"
00030 #include "ace/os_include/os_signal.h"
00031 
00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00033 
00034 class ACE_Object_Manager;
00035 class ACE_OS_Object_Manager_Manager;
00036 class ACE_TSS_Cleanup;
00037 class ACE_TSS_Emulation;
00038 class ACE_Log_Msg;
00039 class ACE_Thread_Hook;
00040 
00041 /**
00042  * @class ACE_Object_Manager_Base
00043  *
00044  * @brief Base class for ACE_Object_Manager(s).
00045  *
00046  * Encapsulates the most useful ACE_Object_Manager data structures.
00047  */
00048 class ACE_Export ACE_Object_Manager_Base
00049 {
00050 protected:
00051   /// Default constructor.
00052   ACE_Object_Manager_Base (void);
00053 
00054   /// Destructor.
00055   virtual ~ACE_Object_Manager_Base (void);
00056 
00057 public:
00058   /**
00059    * Explicitly initialize.  Returns 0 on success, -1 on failure due
00060    * to dynamic allocation failure (in which case errno is set to
00061    * ENOMEM), or 1 if it had already been called.
00062    */
00063   virtual int init (void) = 0;
00064 
00065   /**
00066    * Explicitly destroy.  Returns 0 on success, -1 on failure because
00067    * the number of fini () calls hasn't reached the number of init ()
00068    * calls, or 1 if it had already been called.
00069    */
00070   virtual int fini (void) = 0;
00071 
00072   enum Object_Manager_State
00073     {
00074       OBJ_MAN_UNINITIALIZED = 0,
00075       OBJ_MAN_INITIALIZING,
00076       OBJ_MAN_INITIALIZED,
00077       OBJ_MAN_SHUTTING_DOWN,
00078       OBJ_MAN_SHUT_DOWN
00079     };
00080 
00081 protected:
00082   /**
00083    * Returns 1 before ACE_Object_Manager_Base has been constructed.
00084    * This flag can be used to determine if the program is constructing
00085    * static objects.  If no static object spawns any threads, the
00086    * program will be single-threaded when this flag returns 1.  (Note
00087    * that the program still might construct some static objects when
00088    * this flag returns 0, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is not
00089    * defined.)
00090    */
00091   int starting_up_i (void);
00092 
00093   /**
00094    * Returns 1 after ACE_Object_Manager_Base has been destroyed.  This
00095    * flag can be used to determine if the program is in the midst of
00096    * destroying static objects.  (Note that the program might destroy
00097    * some static objects before this flag can return 1, if
00098    * ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined.)
00099    */
00100   int shutting_down_i (void);
00101 
00102   /// State of the Object_Manager;
00103   Object_Manager_State object_manager_state_;
00104 
00105   /**
00106    * Flag indicating whether the ACE_Object_Manager was dynamically
00107    * allocated by ACE.  (If is was dynamically allocated by the
00108    * application, then the application is responsible for destroying
00109    * it.)
00110    */
00111   unsigned int dynamically_allocated_;
00112 
00113   /// Link to next Object_Manager, for chaining.
00114   ACE_Object_Manager_Base *next_;
00115 private:
00116   // Disallow copying by not implementing the following . . .
00117   ACE_Object_Manager_Base (const ACE_Object_Manager_Base &);
00118   ACE_Object_Manager_Base &operator= (const ACE_Object_Manager_Base &);
00119 };
00120 
00121 extern "C"
00122 void
00123 ACE_OS_Object_Manager_Internal_Exit_Hook (void);
00124 
00125 
00126 // @@ This forward declaration should go away.
00127 class ACE_Log_Msg;
00128 
00129 class ACE_Export ACE_OS_Object_Manager : public ACE_Object_Manager_Base
00130 {
00131 public:
00132   /// Explicitly initialize.
00133   virtual int init (void);
00134 
00135   /// Explicitly destroy.
00136   virtual int fini (void);
00137 
00138   /**
00139    * Returns 1 before the <ACE_OS_Object_Manager> has been
00140    * constructed.  See <ACE_Object_Manager::starting_up> for more
00141    * information.
00142    */
00143   static int starting_up (void);
00144 
00145   /// Returns 1 after the <ACE_OS_Object_Manager> has been destroyed.
00146   /// See <ACE_Object_Manager::shutting_down> for more information.
00147   static int shutting_down (void);
00148 
00149   /// Unique identifiers for preallocated objects.
00150   enum Preallocated_Object
00151     {
00152 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00153       ACE_OS_MONITOR_LOCK,
00154       ACE_TSS_CLEANUP_LOCK,
00155       ACE_LOG_MSG_INSTANCE_LOCK,
00156 #   if defined (ACE_HAS_TSS_EMULATION)
00157       ACE_TSS_KEY_LOCK,
00158 #     if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
00159       ACE_TSS_BASE_LOCK,
00160 #     endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
00161 #   endif /* ACE_HAS_TSS_EMULATION */
00162 # else
00163       // Without ACE_MT_SAFE, There are no preallocated objects.  Make
00164       // sure that the preallocated_array size is at least one by
00165       // declaring this dummy . . .
00166       ACE_OS_EMPTY_PREALLOCATED_OBJECT,
00167 # endif /* ACE_MT_SAFE */
00168 
00169       /// This enum value must be last!
00170       ACE_OS_PREALLOCATED_OBJECTS
00171     };
00172 
00173   /// Accesses a default signal set used, for example, in
00174   /// <ACE_Sig_Guard> methods.
00175   static sigset_t *default_mask (void);
00176 
00177   /// Returns the current thread hook for the process.
00178   static ACE_Thread_Hook *thread_hook (void);
00179 
00180   /// Returns the existing thread hook and assign a <new_thread_hook>.
00181   static ACE_Thread_Hook *thread_hook (ACE_Thread_Hook *new_thread_hook);
00182 
00183 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00184   /// Get/Set TSS exception action.
00185   static ACE_SEH_EXCEPT_HANDLER seh_except_selector (void);
00186   static ACE_SEH_EXCEPT_HANDLER seh_except_selector (ACE_SEH_EXCEPT_HANDLER);
00187 
00188   static ACE_SEH_EXCEPT_HANDLER seh_except_handler (void);
00189   static ACE_SEH_EXCEPT_HANDLER seh_except_handler (ACE_SEH_EXCEPT_HANDLER);
00190 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
00191 
00192 public:
00193   // = Applications shouldn't use these so they're hidden here.
00194 
00195   // They're public so that the <ACE_Object_Manager> can be
00196   // constructed/destructed in <main> with
00197   // <ACE_HAS_NONSTATIC_OBJECT_MANAGER>.
00198   /// Constructor.
00199   ACE_OS_Object_Manager (void);
00200 
00201   /// Destructor.
00202   ~ACE_OS_Object_Manager (void);
00203 
00204   /// Accessor to singleton instance.
00205   static ACE_OS_Object_Manager *instance (void);
00206 
00207   /// For <ACE_OS::atexit> support.
00208   int at_exit (ACE_EXIT_HOOK func);
00209 
00210 //private:
00211   /// Singleton instance pointer.
00212   static ACE_OS_Object_Manager *instance_;
00213 
00214   /// Table of preallocated objects.
00215   static void *preallocated_object[ACE_OS_PREALLOCATED_OBJECTS];
00216 
00217   /// Default signal set used, for example, in ACE_Sig_Guard.
00218   sigset_t *default_mask_;
00219 
00220   /// Thread hook that's used by this process.
00221   ACE_Thread_Hook *thread_hook_;
00222 
00223   /// For at_exit support.
00224   ACE_OS_Exit_Info exit_info_;
00225 
00226 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
00227   /// These handlers determine how a thread handles win32 structured
00228   /// exception.
00229   ACE_SEH_EXCEPT_HANDLER seh_except_selector_;
00230   ACE_SEH_EXCEPT_HANDLER seh_except_handler_;
00231 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
00232 
00233   /// For use by init () and fini (), to consolidate error reporting.
00234   static void print_error_message (unsigned int line_number, const ACE_TCHAR *message);
00235 
00236   /// This class is for internal use by ACE_OS, etc., only.
00237   friend class ACE_Object_Manager;
00238   friend class ACE_OS_Object_Manager_Manager;
00239   friend class ACE_TSS_Cleanup;
00240   friend class ACE_TSS_Emulation;
00241   friend class ACE_Log_Msg;
00242   friend void ACE_OS_Object_Manager_Internal_Exit_Hook ();
00243 };
00244 
00245 ACE_END_VERSIONED_NAMESPACE_DECL
00246 
00247 #include /**/ "ace/post.h"
00248 #endif /* ACE_OBJECT_MANAGER_BASE_H */

Generated on Thu Nov 9 09:41:57 2006 for ACE by doxygen 1.3.6