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