Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Object_Manager_Base.h
blob8335253c457d87eb83d781a64274848701d5c7ae
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Object_Manager_Base.h
7 * $Id: Object_Manager_Base.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
10 * @author Jesper S. M|ller<stophph@diku.dk>
11 * @author and a cast of thousands...
13 * Originally in OS.h.
15 //=============================================================================
17 #ifndef ACE_OBJECT_MANAGER_BASE_H
18 #define ACE_OBJECT_MANAGER_BASE_H
19 #include /**/ "ace/pre.h"
21 #include "ace/config-lite.h"
23 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 # pragma once
25 #endif /* ACE_LACKS_PRAGMA_ONCE */
27 #include /**/ "ace/ACE_export.h"
28 #include "ace/Cleanup.h"
29 #include "ace/os_include/sys/os_types.h"
30 #include "ace/os_include/os_signal.h"
32 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
34 class ACE_Object_Manager;
35 class ACE_OS_Object_Manager_Manager;
36 class ACE_TSS_Cleanup;
37 class ACE_TSS_Emulation;
38 class ACE_Log_Msg;
39 class ACE_Thread_Hook;
41 /**
42 * @class ACE_Object_Manager_Base
44 * @brief Base class for ACE_Object_Manager(s).
46 * Encapsulates the most useful ACE_Object_Manager data structures.
48 class ACE_Export ACE_Object_Manager_Base
50 protected:
51 /// Default constructor.
52 ACE_Object_Manager_Base (void);
54 /// Destructor.
55 virtual ~ACE_Object_Manager_Base (void);
57 public:
58 /**
59 * Explicitly initialize. Returns 0 on success, -1 on failure due
60 * to dynamic allocation failure (in which case errno is set to
61 * ENOMEM), or 1 if it had already been called.
63 virtual int init (void) = 0;
65 /**
66 * Explicitly destroy. Returns 0 on success, -1 on failure because
67 * the number of fini () calls hasn't reached the number of init ()
68 * calls, or 1 if it had already been called.
70 virtual int fini (void) = 0;
72 enum Object_Manager_State
74 OBJ_MAN_UNINITIALIZED = 0,
75 OBJ_MAN_INITIALIZING,
76 OBJ_MAN_INITIALIZED,
77 OBJ_MAN_SHUTTING_DOWN,
78 OBJ_MAN_SHUT_DOWN
81 protected:
82 /**
83 * Returns 1 before ACE_Object_Manager_Base has been constructed.
84 * This flag can be used to determine if the program is constructing
85 * static objects. If no static object spawns any threads, the
86 * program will be single-threaded when this flag returns 1. (Note
87 * that the program still might construct some static objects when
88 * this flag returns 0, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is not
89 * defined.)
91 int starting_up_i (void);
93 /**
94 * Returns 1 after ACE_Object_Manager_Base has been destroyed. This
95 * flag can be used to determine if the program is in the midst of
96 * destroying static objects. (Note that the program might destroy
97 * some static objects before this flag can return 1, if
98 * ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined.)
100 int shutting_down_i (void);
102 /// State of the Object_Manager;
103 Object_Manager_State object_manager_state_;
106 * Flag indicating whether the ACE_Object_Manager was dynamically
107 * allocated by ACE. (If is was dynamically allocated by the
108 * application, then the application is responsible for destroying
109 * it.)
111 bool dynamically_allocated_;
113 /// Link to next Object_Manager, for chaining.
114 ACE_Object_Manager_Base *next_;
115 private:
116 // Disallow copying by not implementing the following . . .
117 ACE_Object_Manager_Base (const ACE_Object_Manager_Base &);
118 ACE_Object_Manager_Base &operator= (const ACE_Object_Manager_Base &);
121 extern "C"
122 void
123 ACE_OS_Object_Manager_Internal_Exit_Hook (void);
126 // @@ This forward declaration should go away.
127 class ACE_Log_Msg;
129 class ACE_Export ACE_OS_Object_Manager : public ACE_Object_Manager_Base
131 public:
132 /// Explicitly initialize.
133 virtual int init (void);
135 /// Explicitly destroy.
136 virtual int fini (void);
139 * Returns 1 before the ACE_OS_Object_Manager has been
140 * constructed. See <ACE_Object_Manager::starting_up> for more
141 * information.
143 static int starting_up (void);
145 /// Returns 1 after the ACE_OS_Object_Manager has been destroyed.
146 /// See <ACE_Object_Manager::shutting_down> for more information.
147 static int shutting_down (void);
149 /// Unique identifiers for preallocated objects.
150 enum Preallocated_Object
152 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
153 ACE_OS_MONITOR_LOCK,
154 ACE_TSS_CLEANUP_LOCK,
155 ACE_LOG_MSG_INSTANCE_LOCK,
156 # if defined (ACE_HAS_TSS_EMULATION)
157 ACE_TSS_KEY_LOCK,
158 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
159 ACE_TSS_BASE_LOCK,
160 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
161 # endif /* ACE_HAS_TSS_EMULATION */
162 # else
163 // Without ACE_MT_SAFE, There are no preallocated objects. Make
164 // sure that the preallocated_array size is at least one by
165 // declaring this dummy . . .
166 ACE_OS_EMPTY_PREALLOCATED_OBJECT,
167 # endif /* ACE_MT_SAFE */
169 /// This enum value must be last!
170 ACE_OS_PREALLOCATED_OBJECTS
173 /// Accesses a default signal set used, for example, in
174 /// ACE_Sig_Guard methods.
175 static sigset_t *default_mask (void);
177 /// Returns the current thread hook for the process.
178 static ACE_Thread_Hook *thread_hook (void);
180 /// Returns the existing thread hook and assign a <new_thread_hook>.
181 static ACE_Thread_Hook *thread_hook (ACE_Thread_Hook *new_thread_hook);
183 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
184 /// Get/Set TSS exception action.
185 static ACE_SEH_EXCEPT_HANDLER seh_except_selector (void);
186 static ACE_SEH_EXCEPT_HANDLER seh_except_selector (ACE_SEH_EXCEPT_HANDLER);
188 static ACE_SEH_EXCEPT_HANDLER seh_except_handler (void);
189 static ACE_SEH_EXCEPT_HANDLER seh_except_handler (ACE_SEH_EXCEPT_HANDLER);
190 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
192 public:
193 // = Applications shouldn't use these so they're hidden here.
195 // They're public so that the ACE_Object_Manager can be
196 // constructed/destructed in <main> with
197 // <ACE_HAS_NONSTATIC_OBJECT_MANAGER>.
198 /// Constructor.
199 ACE_OS_Object_Manager (void);
201 /// Destructor.
202 ~ACE_OS_Object_Manager (void);
204 /// Accessor to singleton instance.
205 static ACE_OS_Object_Manager *instance (void);
207 /// For <ACE_OS::atexit> support.
208 int at_exit (ACE_EXIT_HOOK func);
210 //private:
211 /// Singleton instance pointer.
212 static ACE_OS_Object_Manager *instance_;
214 /// Table of preallocated objects.
215 static void *preallocated_object[ACE_OS_PREALLOCATED_OBJECTS];
217 /// Default signal set used, for example, in ACE_Sig_Guard.
218 sigset_t *default_mask_;
220 /// Thread hook that's used by this process.
221 ACE_Thread_Hook *thread_hook_;
223 /// For at_exit support.
224 ACE_OS_Exit_Info exit_info_;
226 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
227 /// These handlers determine how a thread handles win32 structured
228 /// exception.
229 ACE_SEH_EXCEPT_HANDLER seh_except_selector_;
230 ACE_SEH_EXCEPT_HANDLER seh_except_handler_;
231 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
233 /// For use by init () and fini (), to consolidate error reporting.
234 static void print_error_message (unsigned int line_number, const ACE_TCHAR *message);
236 /// This class is for internal use by ACE_OS, etc., only.
237 friend class ACE_Object_Manager;
238 friend class ACE_OS_Object_Manager_Manager;
239 friend class ACE_TSS_Cleanup;
240 friend class ACE_TSS_Emulation;
241 friend class ACE_Log_Msg;
242 friend void ACE_OS_Object_Manager_Internal_Exit_Hook ();
245 ACE_END_VERSIONED_NAMESPACE_DECL
247 #include /**/ "ace/post.h"
248 #endif /* ACE_OBJECT_MANAGER_BASE_H */