00001 // -*- C++ -*- 00002 00003 // =================================================================== 00004 /** 00005 * @file Transport_Selection_Guard.h 00006 * 00007 * $Id: Transport_Selection_Guard.h 84838 2009-03-16 13:07:49Z johnnyw $ 00008 * 00009 * @author Iliyan Jeliazkov <iliyan@ociweb.com> 00010 */ 00011 // =================================================================== 00012 00013 #ifndef TAO_TRANSPORT_SELECTION_GUARD_H 00014 #define TAO_TRANSPORT_SELECTION_GUARD_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "tao/TAO_Export.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "tao/orbconf.h" 00025 00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00027 00028 // Forward declarations 00029 class TAO_Transport; 00030 class TAO_ORB_Core; 00031 00032 namespace TAO 00033 { 00034 /** 00035 * @class Transport_Selection_Guard 00036 * 00037 * @brief Used by the Transport Current feature to keep track of 00038 * which Transport is currently active. 00039 * 00040 * Whenever a Transport is selected: during an upcall, or prior to a 00041 * client invocation an instance of this class is created [on the 00042 * stack, or as a member of another class] to keep track of the said 00043 * Transport. The class implements the RAII idiom, which makes it 00044 * possible to build a stack of these instances as the thread is 00045 * doing nested upcalls or client invocations. 00046 * 00047 * It utilizes TAO_TSS_Resources::tsg_ member pointer to keep track 00048 * of stack-linked Transport_Selection_Guard instances. 00049 * 00050 * If the Transport Current feature is disabled most methods are 00051 * no-ops and add no overhead on the critical path. 00052 * 00053 * <B>See Also:</B> 00054 * 00055 * https://svn.dre.vanderbilt.edu/viewvc/Middleware/trunk/TAO/docs/transport_current/index.html?revision=HEAD 00056 * 00057 */ 00058 class TAO_Export Transport_Selection_Guard 00059 { 00060 public: 00061 00062 static Transport_Selection_Guard* current (TAO_ORB_Core* core, 00063 size_t tss_slot_id); 00064 00065 public: 00066 00067 /// Ctor 00068 Transport_Selection_Guard (TAO_Transport* t); 00069 00070 /// Dtor 00071 ~Transport_Selection_Guard (void); 00072 00073 /// getter 00074 TAO_Transport* operator-> (void) const 00075 { 00076 return this->get (); 00077 }; 00078 00079 /// getter 00080 TAO_Transport& operator* (void) const 00081 { 00082 return *this->get (); 00083 }; 00084 00085 /// Getter 00086 TAO_Transport* get (void) const 00087 { 00088 return this->curr_; 00089 }; 00090 00091 /// Setter 00092 Transport_Selection_Guard& set (TAO_Transport* t) 00093 { 00094 this->curr_ = t; 00095 return *this; 00096 }; 00097 00098 Transport_Selection_Guard& operator=(const Transport_Selection_Guard& rhs) { 00099 if (this != &rhs) 00100 { 00101 #if TAO_HAS_TRANSPORT_CURRENT == 1 00102 prev_ = rhs.prev_; 00103 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */ 00104 curr_ = rhs.curr_; 00105 } 00106 return *this; 00107 } 00108 00109 00110 private: 00111 ACE_UNIMPLEMENTED_FUNC (Transport_Selection_Guard (const Transport_Selection_Guard&)) 00112 00113 #if TAO_HAS_TRANSPORT_CURRENT == 1 00114 00115 /// This is pointing to the guard that was active prior to 00116 /// instantiating us. 00117 00118 Transport_Selection_Guard* prev_; 00119 00120 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */ 00121 00122 /// The "real" Transport, i.e. the one selected at present 00123 TAO_Transport* curr_; 00124 00125 // Comparison. See Modern C++ Design by A. Alexandrescu for the gory detail. 00126 bool 00127 operator! () const 00128 { 00129 return curr_ == 0; 00130 } 00131 00132 inline friend bool 00133 operator== (const Transport_Selection_Guard& lhs, 00134 const TAO_Transport* rhs) 00135 { 00136 return lhs.curr_ == rhs; 00137 } 00138 00139 inline friend bool 00140 operator== (const TAO_Transport* lhs, 00141 const Transport_Selection_Guard& rhs) 00142 { 00143 return lhs == rhs.curr_; 00144 } 00145 00146 inline friend bool 00147 operator!= (const Transport_Selection_Guard& lhs, 00148 const TAO_Transport* rhs) 00149 { 00150 return lhs.curr_ != rhs; 00151 } 00152 00153 inline friend bool 00154 operator!= (const TAO_Transport* lhs, 00155 const Transport_Selection_Guard& rhs) 00156 { 00157 return lhs != rhs.curr_; 00158 } 00159 00160 template <class U> inline friend bool 00161 operator== (const Transport_Selection_Guard& lhs, 00162 const U* rhs) 00163 { 00164 return lhs.curr_ == rhs; 00165 } 00166 00167 template <class U> inline friend bool 00168 operator== (const U* lhs, 00169 const Transport_Selection_Guard& rhs) 00170 { 00171 return lhs == rhs.curr_; 00172 } 00173 00174 template <class U> inline friend bool 00175 operator!= (const Transport_Selection_Guard& lhs, 00176 const U* rhs) 00177 { 00178 return lhs.curr_ != rhs; 00179 } 00180 00181 template <class U> inline friend bool 00182 operator!= (const U* lhs, 00183 const Transport_Selection_Guard& rhs) 00184 { 00185 return lhs != rhs.curr_; 00186 } 00187 00188 }; 00189 00190 } /* namespace TAO */ 00191 00192 00193 00194 00195 TAO_END_VERSIONED_NAMESPACE_DECL 00196 00197 #include /**/ "ace/post.h" 00198 00199 #endif /* TAO_TRANSPORT_SELECTION_GUARD_H */