00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file TAO_Singleton.h 00006 * 00007 * $Id: TAO_Singleton.h 74014 2006-08-14 13:52:22Z johnnyw $ 00008 * 00009 * Header file for the TAO-specific Singleton implementation. 00010 * Based entirely on ace/Singleton.*. 00011 * 00012 * @author Ossama Othman <ossama@uci.edu> 00013 */ 00014 //============================================================================= 00015 00016 00017 #ifndef TAO_SINGLETON_H 00018 #define TAO_SINGLETON_H 00019 00020 #include /**/ "ace/pre.h" 00021 00022 #include "ace/TSS_T.h" 00023 00024 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00025 # pragma once 00026 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00027 00028 #include /**/ "tao/Versioned_Namespace.h" 00029 00030 #include "ace/Cleanup.h" 00031 00032 00033 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00034 00035 /** 00036 * @class TAO_Singleton 00037 * 00038 * @brief TAO-specific Singleton class 00039 * 00040 * TAO_Singletons are used by TAO to register TAO-specific 00041 * singleton instances with the TAO_Object_Manager. This 00042 * ensures that TAO singletons are isolated from ACE's 00043 * Object_Manager, thus allowing TAO to be safely dynamically 00044 * unloaded. 00045 */ 00046 template <class TYPE, class ACE_LOCK> 00047 class TAO_Singleton : public ACE_Cleanup 00048 { 00049 00050 public: 00051 /// Global access point to the Singleton. 00052 static TYPE *instance (void); 00053 00054 /// Cleanup method, used by <ace_cleanup_destroyer> to destroy the 00055 /// singleton. 00056 virtual void cleanup (void *param = 0); 00057 00058 /// Dump the state of the object. 00059 static void dump (void); 00060 00061 protected: 00062 /// Default constructor. 00063 TAO_Singleton (void); 00064 00065 /// Contained instance. 00066 TYPE instance_; 00067 00068 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) 00069 /// Pointer to the Singleton (ACE_Cleanup) instance. 00070 static TAO_Singleton<TYPE, ACE_LOCK> *singleton_; 00071 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ 00072 00073 /// Get pointer to the TAO Singleton instance. 00074 static TAO_Singleton<TYPE, ACE_LOCK> *&instance_i (void); 00075 }; 00076 00077 /** 00078 * @class TAO_TSS_Singleton 00079 * 00080 * @brief TAO-specific Singleton class 00081 * 00082 * TAO_Singletons are used by TAO to register TAO-specific 00083 * singleton instances with the TAO_Object_Manager. This 00084 * ensures that TAO singletons are isolated from ACE's 00085 * Object_Manager, thus allowing TAO to be safely dynamically 00086 * unloaded. 00087 */ 00088 template <class TYPE, class ACE_LOCK> 00089 class TAO_TSS_Singleton : public ACE_Cleanup 00090 { 00091 00092 public: 00093 /// Global access point to the Singleton. 00094 static TYPE *instance (void); 00095 00096 /// Cleanup method, used by <ace_cleanup_destroyer> to destroy the 00097 /// singleton. 00098 virtual void cleanup (void *param = 0); 00099 00100 /// Dump the state of the object. 00101 static void dump (void); 00102 00103 protected: 00104 /// Default constructor. 00105 TAO_TSS_Singleton (void); 00106 00107 /// Contained instance. 00108 ACE_TSS_TYPE (TYPE) instance_; 00109 00110 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) 00111 /// Pointer to the Singleton (ACE_Cleanup) instance. 00112 static TAO_TSS_Singleton<TYPE, ACE_LOCK> *singleton_; 00113 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ 00114 00115 /// Get pointer to the TAO TSS Singleton instance. 00116 static TAO_TSS_Singleton<TYPE, ACE_LOCK> *&instance_i (void); 00117 00118 private: 00119 00120 ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_TSS_Singleton<TYPE,ACE_LOCK> &)) 00121 ACE_UNIMPLEMENTED_FUNC (TAO_TSS_Singleton (const TAO_TSS_Singleton<TYPE,ACE_LOCK> &)) 00122 00123 }; 00124 00125 TAO_END_VERSIONED_NAMESPACE_DECL 00126 00127 #if defined (__ACE_INLINE__) 00128 #include "tao/TAO_Singleton.inl" 00129 #endif /* __ACE_INLINE__ */ 00130 00131 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00132 #include "tao/TAO_Singleton.cpp" 00133 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00134 00135 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00136 #pragma implementation ("TAO_Singleton.cpp") 00137 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00138 00139 00140 #include /**/ "ace/post.h" 00141 00142 #endif /* TAO_SINGLETON_H */