00001 // -*- C++ -*- 00002 00003 /** 00004 * @file EC_Lifetime_Utils_T.h 00005 * 00006 * $Id: EC_Lifetime_Utils_T.h 76589 2007-01-25 18:04:11Z elliott_c $ 00007 * 00008 * @author Jody Hagins (jody@atdesk.com) 00009 * @author Marina Spivak (marina@atdesk.com) 00010 * 00011 * This file is a temporary place for general CORBA application 00012 * utility classes. These classes will be moved out from the EC 00013 * library and into TAO or will be replaced by other TAO classes with 00014 * similar functionality. 00015 */ 00016 00017 #ifndef TAO_EC_LIFETIME_UTILS_T_H 00018 #define TAO_EC_LIFETIME_UTILS_T_H 00019 00020 #include "orbsvcs/Event/EC_Lifetime_Utils.h" 00021 00022 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00023 # pragma once 00024 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00025 00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00027 00028 /** 00029 * @brief Helper for activating objects. 00030 * Activates @a servant with @a poa and returns the object reference via 00031 * @a obj_ref. If @a object_deactivator != 0, it is populated with info 00032 * necessary to deactivate the @a servant from @a poa. 00033 */ 00034 template <typename T> 00035 void activate (T & obj_ref, 00036 PortableServer::POA_ptr poa, 00037 PortableServer::ServantBase * servant, 00038 TAO_EC_Object_Deactivator & object_deactivator); 00039 00040 00041 //*************************************************************************** 00042 00043 /** 00044 * @class TAO_EC_Auto_Command<COMMAND> 00045 * 00046 * @brief Utility class which executes COMMAND in its destructor. 00047 * 00048 * Template argument requirements: 00049 * 00050 * Has void execute (void); method which 00051 * can throw ONLY CORBA exceptions. 00052 * Has default and copy constructors. 00053 * 00054 */ 00055 template <class T> 00056 class TAO_EC_Auto_Command 00057 { 00058 public: 00059 TAO_EC_Auto_Command (void); 00060 TAO_EC_Auto_Command (const T & command); 00061 ~TAO_EC_Auto_Command (void); 00062 void set_command (const T & command); 00063 void set_command (TAO_EC_Auto_Command<T> & auto_command); 00064 void execute (void); 00065 void allow_command (void); 00066 void disallow_command (void); 00067 00068 private: 00069 00070 TAO_EC_Auto_Command (const TAO_EC_Auto_Command &); 00071 TAO_EC_Auto_Command & operator= (const TAO_EC_Auto_Command &); 00072 00073 T command_; 00074 int allow_command_; 00075 }; 00076 00077 00078 //*************************************************************************** 00079 00080 template <class T> 00081 class TAO_EC_Shutdown_Command 00082 { 00083 public: 00084 TAO_EC_Shutdown_Command (void); 00085 TAO_EC_Shutdown_Command (T target); 00086 void execute (void); 00087 00088 private: 00089 00090 T target_; 00091 }; 00092 00093 //*************************************************************************** 00094 00095 /** 00096 * @class Servant_Var 00097 * 00098 * @brief Provides a type safe counted reference to servants. 00099 */ 00100 template <class T> 00101 class TAO_EC_Servant_Var 00102 { 00103 public: 00104 //! Constructor. Assumes ownership of \c p. 00105 TAO_EC_Servant_Var(T * p = 0); 00106 00107 //! Copy constructor. Adds reference to \c rhs. 00108 TAO_EC_Servant_Var(TAO_EC_Servant_Var<T> const & rhs); 00109 00110 //! Assignment operator. Adds reference to \c rhs. 00111 TAO_EC_Servant_Var<T> & operator=(TAO_EC_Servant_Var<T> const & rhs); 00112 00113 //! Destructor. Removes a reference from the underlying object, 00114 //! possibly destroying it. 00115 ~TAO_EC_Servant_Var(); 00116 00117 //! Assignment operator. Assumes ownership of \c p. 00118 TAO_EC_Servant_Var<T> & operator=(T * p); 00119 00120 # if !defined(ACE_LACKS_MEMBER_TEMPLATES) 00121 //! Template member constructor from a pointer that will implicitly 00122 //! cast to type T. Assumes ownership of \c p. 00123 //! This constructor allows constructs such as: 00124 //! Servant_Base<Base> p(new Derived); 00125 template <class Y> 00126 TAO_EC_Servant_Var(Y * p); 00127 00128 //! Template member copy constructor from a TAO_EC_Servant_Var<Y>, where 00129 //! Y can be implicitly cast to type T. 00130 template <class Y> 00131 TAO_EC_Servant_Var(TAO_EC_Servant_Var<Y> const & rhs); 00132 00133 //! Template member assignment operator from a TAO_EC_Servant_Var<Y>, where 00134 //! Y can be implicitly cast to type T. 00135 template <class Y> 00136 TAO_EC_Servant_Var<T> & operator=(TAO_EC_Servant_Var<Y> const & rhs); 00137 00138 //! Template member assignment operator from a pointer to Y, where Y 00139 //! can be implicitly cast to type T. 00140 template <class Y> 00141 TAO_EC_Servant_Var<T> & operator=(Y * p); 00142 # endif /* ACE_LACKS_MEMBER_TEMPLATES */ 00143 00144 //! Smart pointer operator-> provides access to the underlying object. 00145 T const * operator->() const; 00146 00147 //! Smart pointer operator-> provides access to the underlying object. 00148 T * operator->(); 00149 00150 //! Dereference the underlying object. 00151 T const & operator*() const; 00152 00153 //! Dereference the underlying object. 00154 T & operator*(); 00155 00156 //! Return a void pointer to the underlying object. This allows 00157 //! it to be used in conditional code and tested against 0. 00158 operator void const * () const; 00159 00160 //! As an IN parameter. 00161 T * in() const; 00162 00163 //! As an INOUT parameter. 00164 T *& inout(); 00165 00166 //! As an OUT parameter. 00167 T *& out(); 00168 00169 // Return a pointer to the underlying object, and this counted 00170 // reference will no longer own the object. 00171 T * _retn(); 00172 00173 private: 00174 T * ptr_; 00175 }; 00176 00177 //! Compare two TAO_EC_Servant_Vars for equivalence. 00178 template <class X, class Y> 00179 bool operator==(TAO_EC_Servant_Var<X> const & x, 00180 TAO_EC_Servant_Var<Y> const & y); 00181 00182 //! Compare two TAO_EC_Servant_Vars for non-equivalence. 00183 template <class X, class Y> 00184 bool operator!=(TAO_EC_Servant_Var<X> const & x, 00185 TAO_EC_Servant_Var<Y> const & y); 00186 00187 00188 TAO_END_VERSIONED_NAMESPACE_DECL 00189 00190 #if defined (__ACE_INLINE__) 00191 #include "orbsvcs/Event/EC_Lifetime_Utils_T.inl" 00192 #endif /* __ACE_INLINE__ */ 00193 00194 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00195 #include "orbsvcs/Event/EC_Lifetime_Utils_T.cpp" 00196 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00197 00198 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00199 #pragma implementation ("EC_Lifetime_Utils_T.cpp") 00200 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00201 00202 #endif /* EC_LIFETIME_UTILS_T_H */