00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Cleanup.h 00006 * 00007 * $Id: Cleanup.h 84163 2009-01-15 07:57:27Z johnnyw $ 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 * @author Jesper S. M|ller<stophph@diku.dk> 00011 * @author and a cast of thousands... 00012 * 00013 * Originally in OS.h. 00014 */ 00015 //============================================================================= 00016 00017 #ifndef ACE_CLEANUP_H 00018 # define ACE_CLEANUP_H 00019 00020 # include /**/ "ace/pre.h" 00021 00022 # include "ace/config-lite.h" 00023 00024 # if !defined (ACE_LACKS_PRAGMA_ONCE) 00025 # pragma once 00026 # endif /* ACE_LACKS_PRAGMA_ONCE */ 00027 00028 #include /**/ "ace/ACE_export.h" 00029 00030 # include "ace/Intrusive_List.h" 00031 # include "ace/Intrusive_List_Node.h" 00032 00033 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1) 00034 # include "ace/Global_Macros.h" 00035 # define ACE_CLEANUP_DESTROYER_NAME ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _ace_cleanup_destroyer) 00036 #else 00037 # define ACE_CLEANUP_DESTROYER_NAME ace_cleanup_destroyer 00038 #endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */ 00039 00040 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00041 00042 /** 00043 * @class ACE_Cleanup 00044 * 00045 * @brief Base class for objects that are cleaned by ACE_Object_Manager. 00046 */ 00047 class ACE_Export ACE_Cleanup 00048 { 00049 public: 00050 /// No-op constructor. 00051 ACE_Cleanup (void); 00052 00053 /// Destructor. 00054 virtual ~ACE_Cleanup (void); 00055 00056 /// Cleanup method that, by default, simply deletes itself. 00057 virtual void cleanup (void *param = 0); 00058 }; 00059 00060 /// Adapter for cleanup, used by ACE_Object_Manager. 00061 extern "C" ACE_Export 00062 void ACE_CLEANUP_DESTROYER_NAME (ACE_Cleanup *, void *param = 0); 00063 00064 /** 00065 * @class ACE_Cleanup_Info_Node 00066 * 00067 * @brief For maintaining a list of ACE_Cleanup_Info items. 00068 * 00069 * For internal use by ACE_Object_Manager. 00070 */ 00071 class ACE_Cleanup_Info_Node : public ACE_Intrusive_List_Node<ACE_Cleanup_Info_Node> 00072 { 00073 public: 00074 ACE_Cleanup_Info_Node (void); 00075 ACE_Cleanup_Info_Node (void *object, 00076 ACE_CLEANUP_FUNC cleanup_hook, 00077 void *param, 00078 const char *name); 00079 ~ACE_Cleanup_Info_Node (void); 00080 00081 /// Equality operator. 00082 bool operator== (const ACE_Cleanup_Info_Node &o) const; 00083 00084 /// Inequality operator. 00085 bool operator!= (const ACE_Cleanup_Info_Node &o) const; 00086 00087 void* object(void); 00088 00089 ACE_CLEANUP_FUNC cleanup_hook (void); 00090 00091 void *param (void); 00092 private: 00093 /// Point to object that gets passed into the <cleanup_hook_>. 00094 void *object_; 00095 00096 /// Cleanup hook that gets called back. 00097 ACE_CLEANUP_FUNC cleanup_hook_; 00098 00099 /// Parameter passed to the <cleanup_hook_>. 00100 void *param_; 00101 00102 /// Name of the cleanup object 00103 const char *name_; 00104 }; 00105 00106 typedef ACE_Intrusive_List<ACE_Cleanup_Info_Node> ACE_Cleanup_Info_Node_List; 00107 00108 /** 00109 * @class ACE_OS_Exit_Info 00110 * 00111 * @brief Hold Object Manager cleanup (exit) information. 00112 * 00113 * @internal 00114 * 00115 * For internal use by the ACE library, only. 00116 */ 00117 class ACE_Export ACE_OS_Exit_Info 00118 { 00119 public: 00120 /// Default constructor. 00121 ACE_OS_Exit_Info (void); 00122 00123 /// Destructor. 00124 ~ACE_OS_Exit_Info (void); 00125 00126 /// Use to register a cleanup hook. 00127 int at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param, const char* name = 0); 00128 00129 /// Look for a registered cleanup hook object. Returns true if already 00130 /// registered, false if not. 00131 bool find (void *object); 00132 00133 /// Remove a registered cleanup hook object. Returns true if removed 00134 /// false if not. 00135 bool remove (void *object); 00136 00137 /// Call all registered cleanup hooks, in reverse order of 00138 /// registration. 00139 void call_hooks (); 00140 00141 private: 00142 /** 00143 * Keeps track of all registered objects. 00144 */ 00145 ACE_Cleanup_Info_Node_List registered_objects_; 00146 }; 00147 00148 00149 ACE_END_VERSIONED_NAMESPACE_DECL 00150 00151 # if defined (ACE_HAS_INLINED_OSCALLS) 00152 # if defined (ACE_INLINE) 00153 # undef ACE_INLINE 00154 # endif /* ACE_INLINE */ 00155 # define ACE_INLINE inline 00156 # include "ace/Cleanup.inl" 00157 # endif /* ACE_HAS_INLINED_OSCALLS */ 00158 00159 # include /**/ "ace/post.h" 00160 #endif /* ACE_CLEANUP_H */