00001 // -*- C++ -*- 00002 00003 /** 00004 * @file EC_Lifetime_Utils.h 00005 * 00006 * EC_Lifetime_Utils.h,v 1.11 2006/03/15 07:52:22 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_H 00018 #define TAO_EC_LIFETIME_UTILS_H 00019 #include /**/ "ace/pre.h" 00020 00021 #include /**/ "orbsvcs/Event/event_serv_export.h" 00022 #include "orbsvcs/RtecEventChannelAdminC.h" 00023 #include "tao/PortableServer/PortableServer.h" 00024 #include "tao/ORB.h" 00025 00026 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00027 # pragma once 00028 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00029 00030 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00031 00032 /** 00033 * @class TAO_EC_Object_Deactivator 00034 * 00035 * @brief Utility for deactivating servants from POA. 00036 * 00037 * Maintains state necessary to deactivate a servant from POA. 00038 * Can be told to deactivate a servant explicitly or can do so 00039 * automagically, in its destructor. 00040 */ 00041 class TAO_RTEvent_Serv_Export TAO_EC_Object_Deactivator 00042 { 00043 public: 00044 /// Default constructor. Deactivation info can be supplied later 00045 /// through set_values (). 00046 TAO_EC_Object_Deactivator (void); 00047 00048 /// Constructor. Set @a id which will be deactivated from @ poa in 00049 /// the deactivator's destructor, unless deactivate () or 00050 /// disallow_deactivation () are invoked before the destruction. 00051 TAO_EC_Object_Deactivator (PortableServer::POA_ptr poa, 00052 PortableServer::ObjectId const & id); 00053 00054 /// Destructor. Deactivates id_ from poa_ if those values have 00055 /// been set, and neither deactivate() nor disallow_deactivation() 00056 /// have been invoked. 00057 ~TAO_EC_Object_Deactivator (void); 00058 00059 /// Set <id> which will be deactivated from <poa> in 00060 /// the deactivator's destructor, unless deactivate () or 00061 /// disallow_deactivation () are invoked before the destruction. 00062 void set_values (PortableServer::POA_ptr poa, 00063 PortableServer::ObjectId const & id); 00064 00065 /// Take on the state of @a deactivator. @a deactivator loses its state. 00066 void set_values (TAO_EC_Object_Deactivator & deactivator); 00067 00068 /// Explicitly enable deactivation to happen in destructor or when 00069 /// deactivate() is called. 00070 void allow_deactivation (void); 00071 00072 /// Explicitly disable deactivation from happening in destructor or 00073 /// when deactivate() is called. 00074 void disallow_deactivation (void); 00075 00076 /// Perform deactivation now if <poa_> and <id_> values have been set, and 00077 /// deactivation hasn't happened yet nor has it been explicitly 00078 /// disallowed. CORBA exceptions occurring during deactivation are 00079 /// not propagated. Deactivation will NOT happen in the destructor. 00080 void deactivate (void); 00081 00082 /// Accessor for the POA used in deactivation. 00083 PortableServer::POA_var poa (void) const; 00084 00085 private: 00086 00087 /// Disallow. 00088 //@{ 00089 TAO_EC_Object_Deactivator (const TAO_EC_Object_Deactivator &rhs); 00090 TAO_EC_Object_Deactivator& operator= (const TAO_EC_Object_Deactivator &rhs); 00091 //@} 00092 00093 /// POA from which the object will be deactivated. 00094 PortableServer::POA_var poa_; 00095 00096 /// ObjectId of the object to be deactivated. 00097 PortableServer::ObjectId id_; 00098 00099 /// Flag indicating whether deactivation will be attempted. 00100 /// The flag is set to false if <poa_> and <id_> haven't been set 00101 /// yet, or if deactivation already happened, or if 00102 /// disallow_deactivation () method is invoked. 00103 int deactivate_; 00104 }; 00105 00106 //*************************************************************************** 00107 00108 /** 00109 * @class TAO_EC_Deactivated_Object 00110 * 00111 * @brief Object deactivation utility (mix-in) class. 00112 * 00113 * Maintains state necessary to deactivate object inheriting from this 00114 * class from POA. The state can be set using set_deactivator() 00115 * method. Then, the object can deactivate itself by doing 00116 * this->deactivator_.deactivate () 00117 * 00118 * NOTE: deactivation does NOT happen automatically, and must be 00119 * explicitly initiated as described above. 00120 */ 00121 class TAO_RTEvent_Serv_Export TAO_EC_Deactivated_Object 00122 { 00123 public: 00124 00125 /// Set deactivation state to that specified by the @a deactivator 00126 /// argument. 00127 void set_deactivator (TAO_EC_Object_Deactivator & deactivator); 00128 00129 protected: 00130 00131 TAO_EC_Deactivated_Object (void); 00132 ~TAO_EC_Deactivated_Object (void); 00133 00134 /// Utility for deactivating ourselves from POA. 00135 TAO_EC_Object_Deactivator deactivator_; 00136 }; 00137 00138 //*************************************************************************** 00139 00140 /** 00141 * @class TAO_EC_ORB_Holder 00142 * 00143 * @brief Utility for automatically destroying the ORB. 00144 * 00145 * Holds a reference to an ORB, and calls destroy() on it in the 00146 * destructor. 00147 */ 00148 class TAO_RTEvent_Serv_Export TAO_EC_ORB_Holder 00149 { 00150 public: 00151 /// Constructor. No-op. 00152 TAO_EC_ORB_Holder (void); 00153 00154 /// Destructor. If holding an ORB, destroy it. 00155 ~TAO_EC_ORB_Holder (void); 00156 00157 /// Set the ORB to be destroyed in destructor to <orb_var>. If 00158 /// TAO_EC_ORB_Holder already held an orb prior to invocation of 00159 /// this method, that orb is NOT destroyed. 00160 void init (CORBA::ORB_var orb_var); 00161 00162 private: 00163 00164 /// Disallow. 00165 //@{ 00166 TAO_EC_ORB_Holder & operator= (const TAO_EC_ORB_Holder &rhs); 00167 TAO_EC_ORB_Holder(const TAO_EC_ORB_Holder &rhs); 00168 //@} 00169 00170 /// ORB to be destroyed. 00171 CORBA::ORB_var orb_; 00172 }; 00173 00174 //*************************************************************************** 00175 00176 /** 00177 * @class TAO_EC_Event_Channel_Holder 00178 * 00179 * @brief Utility for automatically destroying the Event Channel. 00180 * 00181 * Holds a reference to an Event Channel, and calls destroy() on it in the 00182 * destructor. 00183 */ 00184 class TAO_RTEvent_Serv_Export TAO_EC_Event_Channel_Holder 00185 { 00186 public: 00187 /// Constructor. No-op. 00188 TAO_EC_Event_Channel_Holder (void); 00189 00190 /// Destructor. If holding an Event Channel, destroy it. 00191 ~TAO_EC_Event_Channel_Holder (void); 00192 00193 /// Set the Event Channel to be destroyed in destructor to @a ec_var. If 00194 /// TAO_EC_Event_Channel_Holder already held an Event Channel prior 00195 /// to invocation of this method, that Event Channel is NOT destroyed. 00196 void init (RtecEventChannelAdmin::EventChannel_var ec_var); 00197 00198 private: 00199 00200 /// Disallow. 00201 //@{ 00202 TAO_EC_Event_Channel_Holder & operator= (const TAO_EC_Event_Channel_Holder &rhs); 00203 TAO_EC_Event_Channel_Holder(const TAO_EC_Event_Channel_Holder &rhs); 00204 //@} 00205 00206 /// EC to be destroyed. 00207 RtecEventChannelAdmin::EventChannel_var ec_; 00208 }; 00209 00210 TAO_END_VERSIONED_NAMESPACE_DECL 00211 00212 #if defined (__ACE_INLINE__) 00213 #include "orbsvcs/Event/EC_Lifetime_Utils.i" 00214 #endif /* __ACE_INLINE__ */ 00215 00216 #include /**/ "ace/post.h" 00217 #endif /* TAO_EC_LIFETIME_UTILS_H */