Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / Object_Manager_Base.h
blobfe4b9285d776145bde89c7dbb8f28da63417c92b
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Object_Manager_Base.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Jesper S. M|ller<stophph@diku.dk>
9 * @author and a cast of thousands...
11 //=============================================================================
13 #ifndef ACE_OBJECT_MANAGER_BASE_H
14 #define ACE_OBJECT_MANAGER_BASE_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/config-lite.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include /**/ "ace/ACE_export.h"
24 #include "ace/Cleanup.h"
25 #include "ace/os_include/sys/os_types.h"
26 #include "ace/os_include/os_signal.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 class ACE_Object_Manager;
31 class ACE_OS_Object_Manager_Manager;
32 class ACE_TSS_Cleanup;
33 class ACE_TSS_Emulation;
34 class ACE_Log_Msg;
35 class ACE_Thread_Hook;
37 /**
38 * @class ACE_Object_Manager_Base
40 * @brief Base class for ACE_Object_Manager(s).
42 * Encapsulates the most useful ACE_Object_Manager data structures.
44 class ACE_Export ACE_Object_Manager_Base
46 protected:
47 /// Default constructor.
48 ACE_Object_Manager_Base ();
50 /// Destructor.
51 virtual ~ACE_Object_Manager_Base ();
53 public:
54 /**
55 * Explicitly initialize. Returns 0 on success, -1 on failure due
56 * to dynamic allocation failure (in which case errno is set to
57 * ENOMEM), or 1 if it had already been called.
59 virtual int init () = 0;
61 /**
62 * Explicitly destroy. Returns 0 on success, -1 on failure because
63 * the number of fini () calls hasn't reached the number of init ()
64 * calls, or 1 if it had already been called.
66 virtual int fini () = 0;
68 enum Object_Manager_State
70 OBJ_MAN_UNINITIALIZED = 0,
71 OBJ_MAN_INITIALIZING,
72 OBJ_MAN_INITIALIZED,
73 OBJ_MAN_SHUTTING_DOWN,
74 OBJ_MAN_SHUT_DOWN
77 protected:
78 /**
79 * Returns 1 before ACE_Object_Manager_Base has been constructed.
80 * This flag can be used to determine if the program is constructing
81 * static objects. If no static object spawns any threads, the
82 * program will be single-threaded when this flag returns 1. (Note
83 * that the program still might construct some static objects when
84 * this flag returns 0, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is not
85 * defined.)
87 int starting_up_i ();
89 /**
90 * Returns 1 after ACE_Object_Manager_Base has been destroyed. This
91 * flag can be used to determine if the program is in the midst of
92 * destroying static objects. (Note that the program might destroy
93 * some static objects before this flag can return 1, if
94 * ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined.)
96 int shutting_down_i ();
98 /// State of the Object_Manager;
99 Object_Manager_State object_manager_state_;
102 * Flag indicating whether the ACE_Object_Manager was dynamically
103 * allocated by ACE. (If is was dynamically allocated by the
104 * application, then the application is responsible for destroying
105 * it.)
107 bool dynamically_allocated_;
109 /// Link to next Object_Manager, for chaining.
110 ACE_Object_Manager_Base *next_;
111 private:
112 ACE_Object_Manager_Base (const ACE_Object_Manager_Base &) = delete;
113 ACE_Object_Manager_Base &operator= (const ACE_Object_Manager_Base &) = delete;
114 ACE_Object_Manager_Base (ACE_Object_Manager_Base &&) = delete;
115 ACE_Object_Manager_Base &operator= (ACE_Object_Manager_Base &&) = delete;
118 extern "C"
119 void ACE_OS_Object_Manager_Internal_Exit_Hook ();
121 // @@ This forward declaration should go away.
122 class ACE_Log_Msg;
124 class ACE_Export ACE_OS_Object_Manager : public ACE_Object_Manager_Base
126 public:
127 ACE_ALLOC_HOOK_DECLARE;
129 /// Explicitly initialize.
130 virtual int init ();
132 /// Explicitly destroy.
133 virtual int fini ();
136 * Returns 1 before the ACE_OS_Object_Manager has been
137 * constructed. See <ACE_Object_Manager::starting_up> for more
138 * information.
140 static int starting_up ();
142 /// Returns 1 after the ACE_OS_Object_Manager has been destroyed.
143 /// See <ACE_Object_Manager::shutting_down> for more information.
144 static int shutting_down ();
146 /// Unique identifiers for preallocated objects.
147 enum Preallocated_Object
149 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
150 ACE_OS_MONITOR_LOCK,
151 ACE_TSS_CLEANUP_LOCK,
152 ACE_LOG_MSG_INSTANCE_LOCK,
153 # if defined (ACE_HAS_TSS_EMULATION)
154 ACE_TSS_KEY_LOCK,
155 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
156 ACE_TSS_BASE_LOCK,
157 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
158 # endif /* ACE_HAS_TSS_EMULATION */
159 # else
160 // Without ACE_MT_SAFE, There are no preallocated objects. Make
161 // sure that the preallocated_array size is at least one by
162 // declaring this dummy . . .
163 ACE_OS_EMPTY_PREALLOCATED_OBJECT,
164 # endif /* ACE_MT_SAFE */
166 /// This enum value must be last!
167 ACE_OS_PREALLOCATED_OBJECTS
170 /// Accesses a default signal set used, for example, in
171 /// ACE_Sig_Guard methods.
172 static sigset_t *default_mask ();
174 /// Returns the current thread hook for the process.
175 static ACE_Thread_Hook *thread_hook ();
177 /// Returns the existing thread hook and assign a <new_thread_hook>.
178 static ACE_Thread_Hook *thread_hook (ACE_Thread_Hook *new_thread_hook);
180 #if defined (ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS)
181 /// Get/Set TSS exception action.
182 static ACE_SEH_EXCEPT_HANDLER seh_except_selector ();
183 static ACE_SEH_EXCEPT_HANDLER seh_except_selector (ACE_SEH_EXCEPT_HANDLER);
185 static ACE_SEH_EXCEPT_HANDLER seh_except_handler ();
186 static ACE_SEH_EXCEPT_HANDLER seh_except_handler (ACE_SEH_EXCEPT_HANDLER);
187 #endif /* ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS */
189 public:
190 // = Applications shouldn't use these so they're hidden here.
192 // They're public so that the ACE_Object_Manager can be
193 // constructed/destructed in <main> with
194 // <ACE_HAS_NONSTATIC_OBJECT_MANAGER>.
195 /// Constructor.
196 ACE_OS_Object_Manager ();
198 /// Destructor.
199 ~ACE_OS_Object_Manager ();
201 /// Accessor to singleton instance.
202 static ACE_OS_Object_Manager *instance ();
204 /// For <ACE_OS::atexit> support.
205 int at_exit (ACE_EXIT_HOOK func, const char* name = 0);
207 //private:
208 /// Singleton instance pointer.
209 static ACE_OS_Object_Manager *instance_;
211 /// Table of preallocated objects.
212 static void *preallocated_object[ACE_OS_PREALLOCATED_OBJECTS];
214 /// Default signal set used, for example, in ACE_Sig_Guard.
215 sigset_t *default_mask_;
217 /// Thread hook that's used by this process.
218 ACE_Thread_Hook *thread_hook_;
220 /// For at_exit support.
221 ACE_OS_Exit_Info exit_info_;
223 #if defined (ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS)
224 /// These handlers determine how a thread handles win32 structured
225 /// exception.
226 ACE_SEH_EXCEPT_HANDLER seh_except_selector_;
227 ACE_SEH_EXCEPT_HANDLER seh_except_handler_;
228 #endif /* ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS */
230 /// For use by init () and fini (), to consolidate error reporting.
231 static void print_error_message (unsigned int line_number, const ACE_TCHAR *message);
233 /// This class is for internal use by ACE_OS, etc., only.
234 friend class ACE_Object_Manager;
235 friend class ACE_OS_Object_Manager_Manager;
236 friend class ACE_TSS_Cleanup;
237 friend class ACE_TSS_Emulation;
238 friend class ACE_Log_Msg;
239 friend void ACE_OS_Object_Manager_Internal_Exit_Hook ();
242 ACE_END_VERSIONED_NAMESPACE_DECL
244 #include /**/ "ace/post.h"
245 #endif /* ACE_OBJECT_MANAGER_BASE_H */