00001 // -*- C++ -*- 00002 00003 /** 00004 * @file EC_Lifetime_Utils_T.h 00005 * 00006 * EC_Lifetime_Utils_T.h,v 1.5 2006/03/14 06:14:25 jtc Exp 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 ACE_ENV_ARG_DECL); 00040 00041 00042 //*************************************************************************** 00043 00044 /** 00045 * @class TAO_EC_Auto_Command<COMMAND> 00046 * 00047 * @brief Utility class which executes COMMAND in its destructor. 00048 * 00049 * Template argument requirements: 00050 * 00051 * Has void execute (ACE_ENV_SINGLE_ARG_DECL); method which 00052 * can throw ONLY CORBA exceptions. 00053 * Has default and copy constructors. 00054 * 00055 */ 00056 template <class T> 00057 class TAO_EC_Auto_Command 00058 { 00059 public: 00060 TAO_EC_Auto_Command (void); 00061 TAO_EC_Auto_Command (const T & command); 00062 ~TAO_EC_Auto_Command (void); 00063 void set_command (const T & command); 00064 void set_command (TAO_EC_Auto_Command<T> & auto_command); 00065 void execute (void); 00066 void allow_command (void); 00067 void disallow_command (void); 00068 00069 private: 00070 00071 TAO_EC_Auto_Command (const TAO_EC_Auto_Command &); 00072 TAO_EC_Auto_Command & operator= (const TAO_EC_Auto_Command &); 00073 00074 T command_; 00075 int allow_command_; 00076 }; 00077 00078 00079 //*************************************************************************** 00080 00081 template <class T> 00082 class TAO_EC_Shutdown_Command 00083 { 00084 public: 00085 TAO_EC_Shutdown_Command (void); 00086 TAO_EC_Shutdown_Command (T target); 00087 void execute (ACE_ENV_SINGLE_ARG_DECL); 00088 00089 private: 00090 00091 T target_; 00092 }; 00093 00094 //*************************************************************************** 00095 00096 /** 00097 * @class Servant_Var 00098 * 00099 * @brief Provides a type safe counted reference to servants. 00100 */ 00101 template <class T> 00102 class TAO_EC_Servant_Var 00103 { 00104 public: 00105 //! Constructor. Assumes ownership of \c p. 00106 TAO_EC_Servant_Var(T * p = 0); 00107 00108 //! Copy constructor. Adds reference to \c rhs. 00109 TAO_EC_Servant_Var(TAO_EC_Servant_Var<T> const & rhs); 00110 00111 //! Assignment operator. Adds reference to \c rhs. 00112 TAO_EC_Servant_Var<T> & operator=(TAO_EC_Servant_Var<T> const & rhs); 00113 00114 //! Destructor. Removes a reference from the underlying object, 00115 //! possibly destroying it. 00116 ~TAO_EC_Servant_Var(); 00117 00118 //! Assignment operator. Assumes ownership of \c p. 00119 TAO_EC_Servant_Var<T> & operator=(T * p); 00120 00121 # if !defined(ACE_LACKS_MEMBER_TEMPLATES) 00122 //! Template member constructor from a pointer that will implicitly 00123 //! cast to type T. Assumes ownership of \c p. 00124 //! This constructor allows constructs such as: 00125 //! Servant_Base<Base> p(new Derived); 00126 template <class Y> 00127 TAO_EC_Servant_Var(Y * p); 00128 00129 //! Template member copy constructor from a TAO_EC_Servant_Var<Y>, where 00130 //! Y can be implicitly cast to type T. 00131 template <class Y> 00132 TAO_EC_Servant_Var(TAO_EC_Servant_Var<Y> const & rhs); 00133 00134 //! Template member assignment operator from a TAO_EC_Servant_Var<Y>, where 00135 //! Y can be implicitly cast to type T. 00136 template <class Y> 00137 TAO_EC_Servant_Var<T> & operator=(TAO_EC_Servant_Var<Y> const & rhs); 00138 00139 //! Template member assignment operator from a pointer to Y, where Y 00140 //! can be implicitly cast to type T. 00141 template <class Y> 00142 TAO_EC_Servant_Var<T> & operator=(Y * p); 00143 # endif /* ACE_LACKS_MEMBER_TEMPLATES */ 00144 00145 //! Smart pointer operator-> provides access to the underlying object. 00146 T const * operator->() const; 00147 00148 //! Smart pointer operator-> provides access to the underlying object. 00149 T * operator->(); 00150 00151 //! Dereference the underlying object. 00152 T const & operator*() const; 00153 00154 //! Dereference the underlying object. 00155 T & operator*(); 00156 00157 //! Return a void pointer to the underlying object. This allows 00158 //! it to be used in conditional code and tested against 0. 00159 operator void const * () const; 00160 00161 //! As an IN parameter. 00162 T * in() const; 00163 00164 //! As an INOUT parameter. 00165 T *& inout(); 00166 00167 //! As an OUT parameter. 00168 T *& out(); 00169 00170 // Return a pointer to the underlying object, and this counted 00171 // reference will no longer own the object. 00172 T * _retn(); 00173 00174 private: 00175 T * ptr_; 00176 }; 00177 00178 //! Compare two TAO_EC_Servant_Vars for equivalence. 00179 template <class X, class Y> 00180 bool operator==(TAO_EC_Servant_Var<X> const & x, 00181 TAO_EC_Servant_Var<Y> const & y); 00182 00183 //! Compare two TAO_EC_Servant_Vars for non-equivalence. 00184 template <class X, class Y> 00185 bool operator!=(TAO_EC_Servant_Var<X> const & x, 00186 TAO_EC_Servant_Var<Y> const & y); 00187 00188 00189 TAO_END_VERSIONED_NAMESPACE_DECL 00190 00191 #if defined (__ACE_INLINE__) 00192 #include "orbsvcs/Event/EC_Lifetime_Utils_T.i" 00193 #endif /* __ACE_INLINE__ */ 00194 00195 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00196 #include "orbsvcs/Event/EC_Lifetime_Utils_T.cpp" 00197 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00198 00199 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00200 #pragma implementation ("EC_Lifetime_Utils_T.cpp") 00201 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00202 00203 #endif /* EC_LIFETIME_UTILS_T_H */