Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / tao / TAO_Singleton_Manager.h
blobbe2c6bf30c4f5a5880725483caba0d537b70dd4f
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file TAO_Singleton_Manager.h
7 * Header file for the TAO-specific Singleton Manager. Based
8 * entirely on ace/Object_Manager.{h,inl,cpp}.
10 * @author Ossama Othman <ossama@uci.edu>
12 //=============================================================================
14 #ifndef TAO_SINGLETON_MANAGER_H
15 #define TAO_SINGLETON_MANAGER_H
17 #include /**/ "ace/pre.h"
18 #include "ace/config-all.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include /**/ "tao/TAO_Export.h"
25 #include "tao/orbconf.h"
26 #include "ace/Object_Manager_Base.h"
28 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
30 /**
31 * @class TAO_Singleton_Manager
33 * @brief Manager for TAO library services and singleton cleanup.
35 * The TAO_Singleton_Manager is basically simplified version of the
36 * ACE_Object_Manager. It is designed specifically to manage
37 * singletons created by TAO. For example, singleton instances
38 * created by TAO will be automatically registered with the singleton
39 * instance of this Singleton Manager.
40 * @par
41 * This class is necessary to ensure that TAO-specific
42 * singletons are isolated to TAO itself, not ACE, for example. The
43 * idea is that destruction of the instance of the
44 * TAO_Singleton_Manager triggers destruction of all objects/services
45 * registered with it.
47 class TAO_Export TAO_Singleton_Manager : public ACE_Object_Manager_Base
49 public:
50 /// Explicitly initialize.
51 virtual int init ();
53 /**
54 * Explicitly initialize the TAO_Singleton_Manager, in addition to
55 * explicitly registering (or not registering) with the
56 * ACE_Object_Manager.
58 int init (int register_with_object_manager);
60 /// Explicitly destroy.
61 virtual int fini ();
63 /**
64 * Returns 1 before the TAO_Singleton_Manager has been constructed.
65 * See ACE_Object_Manager::starting_up for more information.
67 static int starting_up ();
69 /// Returns 1 after the TAO_Singleton_Manager has been destroyed.
70 /// See ACE_Object_Manager::shutting_down for more information.
71 static int shutting_down ();
73 /// Accesses a default signal set used, for example, in
74 /// ACE_Sig_Guard methods.
75 static sigset_t *default_mask ();
77 /// Returns the current thread hook for the process.
78 static ACE_Thread_Hook *thread_hook ();
80 /// Returns the existing thread hook and assign a new_thread_hook.
81 static ACE_Thread_Hook *thread_hook (ACE_Thread_Hook *new_thread_hook);
83 /// Accessor to singleton instance.
84 static TAO_Singleton_Manager *instance ();
86 /// Register an ACE_Cleanup object for cleanup at process
87 /// termination.
88 /**
89 * The object is deleted via the ace_cleanup_destroyer. If you need
90 * more flexiblity, see the other at_exit method below. For OS's
91 * that do not have processes, cleanup takes place at the end of
92 * main. Returns 0 on success. On failure, returns -1 and sets
93 * errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual
94 * memory, or EEXIST if the object (or array) had already been
95 * registered.
97 static int at_exit (ACE_Cleanup *object, void *param = 0, const char* name = 0);
99 /// Register an object (or array) for cleanup at process
100 /// termination.
102 * @a cleanup_hook points to a (global, or static member) function that
103 * is called for the object or array when it to be destroyed. It
104 * may perform any necessary cleanup specific for that object or its
105 * class. @a param is passed as the second parameter to the
106 * cleanup_hook function; the first parameter is the object (or
107 * array) to be destroyed. @a cleanup_hook, for example, may delete
108 * the object (or array). For OS's that do not have processes, this
109 * function is the same as @c at_thread_exit. Returns 0 on success.
110 * On failure, returns -1 and sets errno to: EAGAIN if shutting
111 * down, ENOMEM if insufficient virtual memory, or EEXIST if the
112 * object (or array) had already been registered.
114 static int at_exit (void *object,
115 ACE_CLEANUP_FUNC cleanup_hook,
116 void *param,
117 const char* name);
119 protected:
120 /// Force allocation on the heap.
121 //@{
122 TAO_Singleton_Manager ();
123 ~TAO_Singleton_Manager ();
124 //@}
126 private:
127 TAO_Singleton_Manager (const TAO_Singleton_Manager &) = delete;
128 TAO_Singleton_Manager &operator= (const TAO_Singleton_Manager &) = delete;
129 TAO_Singleton_Manager (TAO_Singleton_Manager &&) = delete;
130 TAO_Singleton_Manager &operator= (TAO_Singleton_Manager &&) = delete;
132 /// Register an object or array for deletion at program termination.
133 /// See description of static version above for return values.
134 int at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param, const char* name);
136 private:
137 /// Default signal set used, for example, in ACE_Sig_Guard.
138 sigset_t *default_mask_;
140 /// Thread hook that's used by this process.
141 ACE_Thread_Hook *thread_hook_;
143 /// For at_exit support.
144 ACE_OS_Exit_Info exit_info_;
146 /// Indicates if TAO_Singleton_Manager is registered with the
147 /// ACE_Object_Manager.
148 int registered_with_object_manager_;
150 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
151 /// Lock that is used to guard internal structures.
152 TAO_SYNCH_RECURSIVE_MUTEX *internal_lock_;
153 #endif /* ACE_MT_SAFE */
156 TAO_END_VERSIONED_NAMESPACE_DECL
158 #if defined (__ACE_INLINE__)
159 # include "tao/TAO_Singleton_Manager.inl"
160 #endif /* __ACE_INLINE__ */
162 #include /**/ "ace/post.h"
164 #endif /* TAO_SINGLETON_MANAGER_H */