00001 // -*- C++ -*- 00002 00003 00004 //============================================================================= 00005 /** 00006 * @file TAO_Singleton_Manager.h 00007 * 00008 * TAO_Singleton_Manager.h,v 1.18 2005/12/02 09:45:19 ossama Exp 00009 * 00010 * Header file for the TAO-specific Singleton Manager. Based 00011 * entirely on ace/Object_Manager.{h,i,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 #if defined (ACE_HAS_EXCEPTIONS) 00034 typedef void (*TAO_unexpected_handler)(void); 00035 #endif /* ACE_HAS_EXCEPTIONS */ 00036 00037 /** 00038 * @class TAO_Singleton_Manager 00039 * 00040 * @brief Manager for TAO library services and singleton cleanup. 00041 * 00042 * The TAO_Singleton_Manager is basically simplified version of the 00043 * ACE_Object_Manager. It is designed specifically to manage 00044 * singletons created by TAO. For example, singleton instances 00045 * created by TAO will be automatically registered with the singleton 00046 * instance of this Singleton Manager. 00047 * @par 00048 * This class is necessary to ensure that TAO-specific 00049 * singletons are isolated to TAO itself, not ACE, for example. The 00050 * idea is that destruction of the instance of the 00051 * TAO_Singleton_Manager triggers destruction of all objects/services 00052 * registered with it. 00053 */ 00054 class TAO_Export TAO_Singleton_Manager : public ACE_Object_Manager_Base 00055 { 00056 public: 00057 /// Explicitly initialize. 00058 virtual int init (void); 00059 00060 /** 00061 * Explicitly initialize the TAO_Singleton_Manager, in addition to 00062 * explicitly registering (or not registering) with the 00063 * ACE_Object_Manager. 00064 */ 00065 int init (int register_with_object_manager); 00066 00067 /// Explicitly destroy. 00068 virtual int fini (void); 00069 00070 /** 00071 * Returns 1 before the TAO_Singleton_Manager has been constructed. 00072 * See ACE_Object_Manager::starting_up for more information. 00073 */ 00074 static int starting_up (void); 00075 00076 /// Returns 1 after the TAO_Singleton_Manager has been destroyed. 00077 /// See ACE_Object_Manager::shutting_down for more information. 00078 static int shutting_down (void); 00079 00080 /// Accesses a default signal set used, for example, in 00081 /// ACE_Sig_Guard methods. 00082 static sigset_t *default_mask (void); 00083 00084 /// Returns the current thread hook for the process. 00085 static ACE_Thread_Hook *thread_hook (void); 00086 00087 /// Returns the existing thread hook and assign a new_thread_hook. 00088 static ACE_Thread_Hook *thread_hook (ACE_Thread_Hook *new_thread_hook); 00089 00090 /// Accessor to singleton instance. 00091 static TAO_Singleton_Manager *instance (void); 00092 00093 /// Register an ACE_Cleanup object for cleanup at process 00094 /// termination. 00095 /** 00096 * The object is deleted via the ace_cleanup_destroyer. If you need 00097 * more flexiblity, see the other at_exit method below. For OS's 00098 * that do not have processes, cleanup takes place at the end of 00099 * main. Returns 0 on success. On failure, returns -1 and sets 00100 * errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual 00101 * memory, or EEXIST if the object (or array) had already been 00102 * registered. 00103 */ 00104 static int at_exit (ACE_Cleanup *object, void *param = 0); 00105 00106 /// Register an object (or array) for cleanup at process 00107 /// termination. 00108 /** 00109 * cleanup_hook points to a (global, or static member) function that 00110 * is called for the object or array when it to be destroyed. It 00111 * may perform any necessary cleanup specific for that object or its 00112 * class. param is passed as the second parameter to the 00113 * cleanup_hook function; the first parameter is the object (or 00114 * array) to be destroyed. cleanup_hook, for example, may delete 00115 * the object (or array). For OS's that do not have processes, this 00116 * function is the same as <at_thread_exit>. Returns 0 on success. 00117 * On failure, returns -1 and sets errno to: EAGAIN if shutting 00118 * down, ENOMEM if insufficient virtual memory, or EEXIST if the 00119 * object (or array) had already been registered. 00120 */ 00121 static int at_exit (void *object, 00122 ACE_CLEANUP_FUNC cleanup_hook, 00123 void *param); 00124 00125 #if defined (ACE_HAS_EXCEPTIONS) 00126 /// Set a new unexpected exception handler. 00127 /** 00128 * The old one will be stored for restoration later on. 00129 * 00130 * @note Calling this method multiple times will cause the stored 00131 * old unexpected exception handler pointer to be lost. 00132 */ 00133 void _set_unexpected (TAO_unexpected_handler u); 00134 #endif /* ACE_HAS_EXCEPTIONS */ 00135 00136 protected: 00137 00138 /// Force allocation on the heap. 00139 //@{ 00140 TAO_Singleton_Manager (void); 00141 ~TAO_Singleton_Manager (void); 00142 //@} 00143 00144 private: 00145 00146 /// Disallow copying by not implementing the following ... 00147 //@{ 00148 TAO_Singleton_Manager (const TAO_Singleton_Manager &); 00149 TAO_Singleton_Manager &operator= (const TAO_Singleton_Manager &); 00150 //@} 00151 00152 /// Register an object or array for deletion at program termination. 00153 /// See description of static version above for return values. 00154 int at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param); 00155 00156 private: 00157 00158 /// Default signal set used, for example, in ACE_Sig_Guard. 00159 sigset_t *default_mask_; 00160 00161 /// Thread hook that's used by this process. 00162 ACE_Thread_Hook *thread_hook_; 00163 00164 /// For at_exit support. 00165 ACE_OS_Exit_Info exit_info_; 00166 00167 /// Indicates if TAO_Singleton_Manager is registered with the 00168 /// ACE_Object_Manager. 00169 int registered_with_object_manager_; 00170 00171 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00172 /// Lock that is used to guard internal structures. 00173 TAO_SYNCH_RECURSIVE_MUTEX *internal_lock_; 00174 #endif /* ACE_MT_SAFE */ 00175 00176 #if defined (ACE_HAS_EXCEPTIONS) 00177 /// The old unexpected exception handler. 00178 /** 00179 * A pointer to the old unexpected exception handler is stored so 00180 * that it can be restored when TAO is unloaded, for example. 00181 * Otherwise, any unexpected exceptions will result in a call to 00182 * TAO's unexpected exception handler which may no longer exist if 00183 * TAO was unloaded. 00184 */ 00185 TAO_unexpected_handler old_unexpected_; 00186 #endif /* ACE_HAS_EXCEPTIONS */ 00187 }; 00188 00189 TAO_END_VERSIONED_NAMESPACE_DECL 00190 00191 #if defined (__ACE_INLINE__) 00192 # include "tao/TAO_Singleton_Manager.inl" 00193 #endif /* __ACE_INLINE__ */ 00194 00195 #include /**/ "ace/post.h" 00196 00197 #endif /* TAO_SINGLETON_MANAGER_H */