#include <TAO_Singleton_Manager.h>
Inheritance diagram for TAO_Singleton_Manager:
Public Member Functions | |
virtual int | init (void) |
Explicitly initialize. | |
int | init (int register_with_object_manager) |
virtual int | fini (void) |
Explicitly destroy. | |
void | _set_unexpected (TAO_unexpected_handler u) |
Set a new unexpected exception handler. | |
Static Public Member Functions | |
int | starting_up (void) |
int | shutting_down (void) |
sigset_t * | default_mask (void) |
ACE_Thread_Hook * | thread_hook (void) |
Returns the current thread hook for the process. | |
ACE_Thread_Hook * | thread_hook (ACE_Thread_Hook *new_thread_hook) |
Returns the existing thread hook and assign a new_thread_hook. | |
TAO_Singleton_Manager * | instance (void) |
Accessor to singleton instance. | |
int | at_exit (ACE_Cleanup *object, void *param=0) |
int | at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
Protected Member Functions | |
TAO_Singleton_Manager (void) | |
~TAO_Singleton_Manager (void) | |
Private Member Functions | |
int | at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
TAO_Singleton_Manager (const TAO_Singleton_Manager &) | |
TAO_Singleton_Manager & | operator= (const TAO_Singleton_Manager &) |
Private Attributes | |
sigset_t * | default_mask_ |
Default signal set used, for example, in ACE_Sig_Guard. | |
ACE_Thread_Hook * | thread_hook_ |
Thread hook that's used by this process. | |
ACE_OS_Exit_Info | exit_info_ |
For at_exit support. | |
int | registered_with_object_manager_ |
TAO_unexpected_handler | old_unexpected_ |
The old unexpected exception handler. |
The TAO_Singleton_Manager is basically simplified version of the ACE_Object_Manager. It is designed specifically to manage singletons created by TAO. For example, singleton instances created by TAO will be automatically registered with the singleton instance of this Singleton Manager.
Definition at line 54 of file TAO_Singleton_Manager.h.
|
|
|
Definition at line 86 of file TAO_Singleton_Manager.cpp. References fini().
00087 { 00088 this->dynamically_allocated_ = 0; // Don't delete this again in fini() 00089 (void) this->fini (); 00090 } |
|
|
|
Set a new unexpected exception handler. The old one will be stored for restoration later on.
Definition at line 315 of file TAO_Singleton_Manager.cpp. References old_unexpected_. Referenced by TAO::ORB::init_orb_globals().
00316 { 00317 // This must be done after the system TypeCodes and Exceptions have 00318 // been initialized. An unexpected exception will cause TAO's 00319 // unexpected exception handler to be called. That handler 00320 // transforms all unexpected exceptions to CORBA::UNKNOWN, which of 00321 // course requires the TypeCode constants and system exceptions to 00322 // have been initialized. 00323 # if (!defined (_MSC_VER) \ 00324 && defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB) \ 00325 && (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB != 0)) || defined (ghs) 00326 this->old_unexpected_ = std::set_unexpected (u); 00327 # else 00328 this->old_unexpected_ = set_unexpected (u); 00329 # endif /* ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB */ 00330 } |
|
cleanup_hook points to a (global, or static member) function that is called for the object or array when it to be destroyed. It may perform any necessary cleanup specific for that object or its class. param is passed as the second parameter to the cleanup_hook function; the first parameter is the object (or array) to be destroyed. cleanup_hook, for example, may delete the object (or array). For OS's that do not have processes, this function is the same as . Returns 0 on success. On failure, returns -1 and sets errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual memory, or EEXIST if the object (or array) had already been registered. Definition at line 20 of file TAO_Singleton_Manager.inl. References at_exit_i(), and instance().
00023 { 00024 return TAO_Singleton_Manager::instance ()->at_exit_i ( 00025 object, 00026 cleanup_hook, 00027 param); 00028 } |
|
The object is deleted via the ace_cleanup_destroyer. If you need more flexiblity, see the other at_exit method below. For OS's that do not have processes, cleanup takes place at the end of main. Returns 0 on success. On failure, returns -1 and sets errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual memory, or EEXIST if the object (or array) had already been registered. Definition at line 9 of file TAO_Singleton_Manager.inl. References ACE_CLEANUP_DESTROYER_NAME(), ACE_CLEANUP_FUNC, at_exit_i(), and instance(). Referenced by TAO_TSS_Singleton< TYPE, ACE_LOCK >::instance(), and TAO_Singleton< TYPE, ACE_LOCK >::instance().
00011 { 00012 return TAO_Singleton_Manager::instance ()->at_exit_i ( 00013 object, 00014 (ACE_CLEANUP_FUNC) ACE_CLEANUP_DESTROYER_NAME, 00015 param); 00016 } |
|
Register an object or array for deletion at program termination. See description of static version above for return values. Definition at line 334 of file TAO_Singleton_Manager.cpp. References ACE_GUARD_RETURN, ACE_OS_Exit_Info::at_exit_i(), ACE_OS_Exit_Info::find(), ACE_Object_Manager_Base::shutting_down_i(), TAO_SYNCH_RECURSIVE_MUTEX, and the_instance. Referenced by at_exit().
00337 { 00338 ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, 00339 ace_mon, 00340 *the_instance->internal_lock_, 00341 -1)); 00342 00343 if (this->shutting_down_i ()) 00344 { 00345 errno = EAGAIN; 00346 return -1; 00347 } 00348 00349 if (this->exit_info_.find (object)) 00350 { 00351 // The object has already been registered. 00352 errno = EEXIST; 00353 return -1; 00354 } 00355 00356 return this->exit_info_.at_exit_i (object, cleanup_hook, param); 00357 } |
|
Accesses a default signal set used, for example, in ACE_Sig_Guard methods. Definition at line 93 of file TAO_Singleton_Manager.cpp. References default_mask_, and instance().
00094 { 00095 return TAO_Singleton_Manager::instance ()->default_mask_; 00096 } |
|
Explicitly destroy.
Implements ACE_Object_Manager_Base. Definition at line 221 of file TAO_Singleton_Manager.cpp. References ACE_OS_Exit_Info::call_hooks(), ACE_Object_Manager_Base::fini(), ACE_Object_Manager_Base::shutting_down_i(), and the_instance. Referenced by ~TAO_Singleton_Manager().
00222 { 00223 if (the_instance == 0 || this->shutting_down_i ()) 00224 // Too late. Or, maybe too early. Either fini () has already 00225 // been called, or init () was never called. 00226 return this->object_manager_state_ == OBJ_MAN_SHUT_DOWN ? 1 : -1; 00227 00228 // No mutex here. Only the main thread should destroy the singleton 00229 // TAO_Singleton_Manager instance. 00230 00231 // Indicate that the TAO_Singleton_Manager instance is being shut 00232 // down. This object manager should be the last one to be shut 00233 // down. 00234 this->object_manager_state_ = OBJ_MAN_SHUTTING_DOWN; 00235 00236 // If another Object_Manager has registered for termination, do it. 00237 if (this->next_) 00238 { 00239 this->next_->fini (); 00240 this->next_ = 0; // Protect against recursive calls. 00241 } 00242 00243 // Call all registered cleanup hooks, in reverse order of 00244 // registration. 00245 this->exit_info_.call_hooks (); 00246 00247 // // Only clean up preallocated objects when the singleton Instance is being 00248 // // destroyed. 00249 // if (this == the_instance) 00250 // { 00251 // #if ! defined (ACE_HAS_STATIC_PREALLOCATION) 00252 // // Cleanup the dynamically preallocated objects. 00253 // # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00254 // // @@ No MT-specific preallocated objects yet. 00255 // # endif /* ACE_MT_SAFE */ 00256 // // @@ No preallocated objects yet. 00257 // #endif /* ! ACE_HAS_STATIC_PREALLOCATION */ 00258 // } 00259 00260 delete this-> default_mask_; 00261 this->default_mask_ = 0; 00262 00263 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00264 delete this->internal_lock_; 00265 this->internal_lock_ = 0; 00266 #endif /* ACE_MT_SAFE */ 00267 00268 #if defined (ACE_HAS_EXCEPTIONS) 00269 // Restore the old unexpected exception handler since TAO will no 00270 // longer be handling exceptions. Allow the application to once 00271 // again handle unexpected exceptions. 00272 # if (!defined (_MSC_VER) \ 00273 && defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB) \ 00274 && (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB != 0)) || defined (ghs) 00275 (void) std::set_unexpected (this->old_unexpected_); 00276 # else 00277 (void) set_unexpected (this->old_unexpected_); 00278 # endif /* ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB */ 00279 #endif /* ACE_HAS_EXCEPTIONS */ 00280 00281 // Indicate that this TAO_Singleton_Manager instance has been shut down. 00282 this->object_manager_state_ = OBJ_MAN_SHUT_DOWN; 00283 00284 if (this == the_instance) 00285 the_instance = 0; 00286 00287 if (this->dynamically_allocated_) 00288 { 00289 delete this; 00290 } 00291 00292 return 0; 00293 } |
|
Explicitly initialize the TAO_Singleton_Manager, in addition to explicitly registering (or not registering) with the ACE_Object_Manager. Definition at line 155 of file TAO_Singleton_Manager.cpp. References ACE_CLEANUP_FUNC, ACE_NEW_RETURN, ACE_Object_Manager::at_exit(), registered_with_object_manager_, ACE_OS::sigfillset(), ACE_Object_Manager_Base::starting_up_i(), and the_instance.
00156 { 00157 if (this->starting_up_i ()) 00158 { 00159 // First, indicate that this TAO_Singleton_Manager instance is being 00160 // initialized. 00161 this->object_manager_state_ = OBJ_MAN_INITIALIZING; 00162 00163 if (this == the_instance) 00164 { 00165 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00166 // @@ No MT-specific pre-allocated objects. 00167 # endif /* ACE_MT_SAFE */ 00168 } 00169 00170 ACE_NEW_RETURN (this->default_mask_, sigset_t, -1); 00171 ACE_OS::sigfillset (this->default_mask_); 00172 00173 // Finally, indicate that the TAO_Singleton_Manager instance has 00174 // been initialized. 00175 this->object_manager_state_ = OBJ_MAN_INITIALIZED; 00176 00177 return 0; 00178 } 00179 00180 // @@ This strange looking code is what provides the "register on 00181 // explicit call to init()" semantics. This was needed since the 00182 // TAO_Singleton_Manager constructor invokes init(). 00183 // Unfortunately, I couldn't get rid of that init() call without 00184 // breaking things. The fact things broke needs to be 00185 // investigated further. 00186 if (this->registered_with_object_manager_ != -1 00187 && register_with_object_manager != this->registered_with_object_manager_) 00188 { 00189 // An attempt was made to register the TAO_Singleton_Manager 00190 // with a manager of a different type from the one it is 00191 // currently registered with. This indicates a problem with the 00192 // caller's logic. 00193 00194 errno = EINVAL; 00195 return -1; 00196 } 00197 00198 if (this->registered_with_object_manager_ == -1) 00199 { 00200 if (register_with_object_manager == 1 00201 && ACE_Object_Manager::at_exit ( 00202 this, 00203 (ACE_CLEANUP_FUNC) TAO_SINGLETON_MANAGER_CLEANUP_DESTROYER_NAME, 00204 0) != 0) 00205 return -1; 00206 00207 this->registered_with_object_manager_ = 00208 register_with_object_manager; 00209 } 00210 00211 // Had already initialized. 00212 return 1; 00213 } |
|
Explicitly initialize.
Implements ACE_Object_Manager_Base. Definition at line 140 of file TAO_Singleton_Manager.cpp. References registered_with_object_manager_. Referenced by CORBA::ORB_init(), and PortableInterceptor::register_orb_initializer().
00141 { 00142 if (this->registered_with_object_manager_ == -1) 00143 { 00144 // Register the TAO_Singleton_Manager with the 00145 // ACE_Object_Manager. 00146 int register_with_object_manager = 1; 00147 00148 return this->init (register_with_object_manager); 00149 } 00150 00151 return 1; // Already initialized. 00152 } |
|
Accessor to singleton instance.
Definition at line 114 of file TAO_Singleton_Manager.cpp. References ACE_ASSERT, ACE_NEW_RETURN, ACE_Object_Manager_Base::dynamically_allocated_, and the_instance. Referenced by at_exit(), default_mask(), TAO::ORB::init_orb_globals(), CORBA::ORB_init(), PortableInterceptor::register_orb_initializer(), and thread_hook().
00115 { 00116 // This function should be called during construction of static 00117 // instances, or before any other threads have been created in the 00118 // process. So, it's not thread safe. 00119 00120 if (the_instance == 0) 00121 { 00122 TAO_Singleton_Manager *instance_pointer; 00123 00124 ACE_NEW_RETURN (instance_pointer, 00125 TAO_Singleton_Manager, 00126 0); 00127 ACE_ASSERT (instance_pointer == the_instance); 00128 00129 instance_pointer->dynamically_allocated_ = 1; 00130 00131 return instance_pointer; 00132 } 00133 else 00134 { 00135 return the_instance; 00136 } 00137 } |
|
|
|
Returns 1 after the TAO_Singleton_Manager has been destroyed. See ACE_Object_Manager::shutting_down for more information. Definition at line 305 of file TAO_Singleton_Manager.cpp. References ACE_Object_Manager_Base::shutting_down_i(), and the_instance. Referenced by TAO_TSS_Singleton< TYPE, ACE_LOCK >::instance(), and TAO_Singleton< TYPE, ACE_LOCK >::instance().
00306 { 00307 return 00308 the_instance 00309 ? the_instance->shutting_down_i () 00310 : 1; 00311 } |
|
Returns 1 before the TAO_Singleton_Manager has been constructed. See ACE_Object_Manager::starting_up for more information. Definition at line 296 of file TAO_Singleton_Manager.cpp. References ACE_Object_Manager_Base::starting_up_i(), and the_instance. Referenced by TAO_TSS_Singleton< TYPE, ACE_LOCK >::instance(), and TAO_Singleton< TYPE, ACE_LOCK >::instance().
00297 { 00298 return 00299 the_instance 00300 ? the_instance->starting_up_i () 00301 : 1; 00302 } |
|
Returns the existing thread hook and assign a new_thread_hook.
Definition at line 105 of file TAO_Singleton_Manager.cpp. References instance(), and thread_hook_.
00106 { 00107 TAO_Singleton_Manager *tao_om = TAO_Singleton_Manager::instance (); 00108 ACE_Thread_Hook *old_hook = tao_om->thread_hook_; 00109 tao_om->thread_hook_ = new_thread_hook; 00110 return old_hook; 00111 } |
|
Returns the current thread hook for the process.
Definition at line 99 of file TAO_Singleton_Manager.cpp. References instance(), and thread_hook_.
00100 { 00101 return TAO_Singleton_Manager::instance ()->thread_hook_; 00102 } |
|
Default signal set used, for example, in ACE_Sig_Guard.
Definition at line 159 of file TAO_Singleton_Manager.h. Referenced by default_mask(). |
|
For at_exit support.
Definition at line 165 of file TAO_Singleton_Manager.h. |
|
The old unexpected exception handler. A pointer to the old unexpected exception handler is stored so that it can be restored when TAO is unloaded, for example. Otherwise, any unexpected exceptions will result in a call to TAO's unexpected exception handler which may no longer exist if TAO was unloaded. Definition at line 185 of file TAO_Singleton_Manager.h. Referenced by _set_unexpected(). |
|
Indicates if TAO_Singleton_Manager is registered with the ACE_Object_Manager. Definition at line 169 of file TAO_Singleton_Manager.h. Referenced by init(). |
|
Thread hook that's used by this process.
Definition at line 162 of file TAO_Singleton_Manager.h. Referenced by thread_hook(). |