TAO_Singleton_Manager.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 
00004 //=============================================================================
00005 /**
00006  *  @file    TAO_Singleton_Manager.h
00007  *
00008  *  $Id: TAO_Singleton_Manager.h 76920 2007-02-05 20:23:47Z johnnyw $
00009  *
00010  *   Header file for the TAO-specific Singleton Manager.  Based
00011  *   entirely on ace/Object_Manager.{h,inl,cpp}.
00012  *
00013  *  @author  Ossama Othman <ossama@uci.edu>
00014  */
00015 //=============================================================================
00016 
00017 #ifndef TAO_SINGLETON_MANAGER_H
00018 #define TAO_SINGLETON_MANAGER_H
00019 
00020 #include /**/ "ace/pre.h"
00021 #include "ace/config-all.h"
00022 
00023 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00024 # pragma once
00025 #endif /* ACE_LACKS_PRAGMA_ONCE */
00026 
00027 #include /**/ "tao/TAO_Export.h"
00028 #include "tao/orbconf.h"
00029 #include "ace/Object_Manager_Base.h"
00030 
00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 /**
00034  * @class TAO_Singleton_Manager
00035  *
00036  * @brief Manager for TAO library services and singleton cleanup.
00037  *
00038  * The TAO_Singleton_Manager is basically simplified version of the
00039  * ACE_Object_Manager.  It is designed specifically to manage
00040  * singletons created by TAO.  For example, singleton instances
00041  * created by TAO will be automatically registered with the singleton
00042  * instance of this Singleton Manager.
00043  * @par
00044  * This class is necessary to ensure that TAO-specific
00045  * singletons are isolated to TAO itself, not ACE, for example.  The
00046  * idea is that destruction of the instance of the
00047  * TAO_Singleton_Manager triggers destruction of all objects/services
00048  * registered with it.
00049  */
00050 class TAO_Export TAO_Singleton_Manager : public ACE_Object_Manager_Base
00051 {
00052 public:
00053   /// Explicitly initialize.
00054   virtual int init (void);
00055 
00056   /**
00057    * Explicitly initialize the TAO_Singleton_Manager, in addition to
00058    * explicitly registering (or not registering) with the
00059    * ACE_Object_Manager.
00060    */
00061   int init (int register_with_object_manager);
00062 
00063   /// Explicitly destroy.
00064   virtual int fini (void);
00065 
00066   /**
00067    * Returns 1 before the TAO_Singleton_Manager has been constructed.
00068    * See ACE_Object_Manager::starting_up for more information.
00069    */
00070   static int starting_up (void);
00071 
00072   /// Returns 1 after the TAO_Singleton_Manager has been destroyed.
00073   /// See ACE_Object_Manager::shutting_down for more information.
00074   static int shutting_down (void);
00075 
00076   /// Accesses a default signal set used, for example, in
00077   /// ACE_Sig_Guard methods.
00078   static sigset_t *default_mask (void);
00079 
00080   /// Returns the current thread hook for the process.
00081   static ACE_Thread_Hook *thread_hook (void);
00082 
00083   /// Returns the existing thread hook and assign a new_thread_hook.
00084   static ACE_Thread_Hook *thread_hook (ACE_Thread_Hook *new_thread_hook);
00085 
00086   /// Accessor to singleton instance.
00087   static TAO_Singleton_Manager *instance (void);
00088 
00089   /// Register an ACE_Cleanup object for cleanup at process
00090   /// termination.
00091   /**
00092    * The object is deleted via the ace_cleanup_destroyer.  If you need
00093    * more flexiblity, see the other at_exit method below.  For OS's
00094    * that do not have processes, cleanup takes place  at the end of
00095    * main.  Returns 0 on success.  On failure, returns -1 and sets
00096    * errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual
00097    * memory, or EEXIST if the object (or array) had already been
00098    * registered.
00099    */
00100   static int at_exit (ACE_Cleanup *object, void *param = 0);
00101 
00102   /// Register an object (or array) for cleanup at process
00103   /// termination.
00104   /**
00105    * cleanup_hook points to a (global, or static member) function that
00106    * is called for the object or array when it to be destroyed.  It
00107    * may perform any necessary cleanup specific for that object or its
00108    * class.  param is passed as the second parameter to the
00109    * cleanup_hook function; the first parameter is the object (or
00110    * array) to be destroyed.  cleanup_hook, for example, may delete
00111    * the object (or array).  For OS's that do not have processes, this
00112    * function is the same as <at_thread_exit>.  Returns 0 on success.
00113    * On failure, returns -1 and sets errno to: EAGAIN if shutting
00114    * down, ENOMEM if insufficient virtual memory, or EEXIST if the
00115    * object (or array) had already been registered.
00116    */
00117   static int at_exit (void *object,
00118                       ACE_CLEANUP_FUNC cleanup_hook,
00119                       void *param);
00120 
00121 protected:
00122 
00123   /// Force allocation on the heap.
00124   //@{
00125   TAO_Singleton_Manager (void);
00126   ~TAO_Singleton_Manager (void);
00127   //@}
00128 
00129 private:
00130 
00131   /// Disallow copying by not implementing the following ...
00132   //@{
00133   TAO_Singleton_Manager (const TAO_Singleton_Manager &);
00134   TAO_Singleton_Manager &operator= (const TAO_Singleton_Manager &);
00135   //@}
00136 
00137   /// Register an object or array for deletion at program termination.
00138   /// See description of static version above for return values.
00139   int at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param);
00140 
00141 private:
00142 
00143   /// Default signal set used, for example, in ACE_Sig_Guard.
00144   sigset_t *default_mask_;
00145 
00146   /// Thread hook that's used by this process.
00147   ACE_Thread_Hook *thread_hook_;
00148 
00149   /// For at_exit support.
00150   ACE_OS_Exit_Info exit_info_;
00151 
00152   /// Indicates if TAO_Singleton_Manager is registered with the
00153   /// ACE_Object_Manager.
00154   int registered_with_object_manager_;
00155 
00156 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00157   /// Lock that is used to guard internal structures.
00158   TAO_SYNCH_RECURSIVE_MUTEX *internal_lock_;
00159 #endif /* ACE_MT_SAFE */
00160 
00161 };
00162 
00163 TAO_END_VERSIONED_NAMESPACE_DECL
00164 
00165 #if defined (__ACE_INLINE__)
00166 # include "tao/TAO_Singleton_Manager.inl"
00167 #endif /* __ACE_INLINE__ */
00168 
00169 #include /**/ "ace/post.h"
00170 
00171 #endif  /* TAO_SINGLETON_MANAGER_H */

Generated on Sun Jan 27 13:07:37 2008 for TAO by doxygen 1.3.6