Transport_Selection_Guard.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ===================================================================
00004 /**
00005  *  @file   Transport_Selection_Guard.h
00006  *
00007  *  $Id: Transport_Selection_Guard.h 79100 2007-07-31 00:33:00Z iliyan $
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 TAO_HAS_TRANSPORT_CURRENT == 1
00100     prev_ = rhs.prev_;
00101 #endif  /* TAO_HAS_TRANSPORT_CURRENT == 1 */
00102     curr_ = rhs.curr_;
00103     return *this;
00104   }
00105 
00106 
00107   private:
00108     ACE_UNIMPLEMENTED_FUNC (Transport_Selection_Guard (const Transport_Selection_Guard&))
00109 
00110 #if TAO_HAS_TRANSPORT_CURRENT == 1
00111 
00112     /// This is pointing to the guard that was active prior to
00113     /// instantiating us.
00114 
00115     Transport_Selection_Guard* prev_;
00116 
00117 #endif  /* TAO_HAS_TRANSPORT_CURRENT == 1 */
00118 
00119     /// The "real" Transport, i.e. the one selected at present
00120     TAO_Transport* curr_;
00121 
00122     // Comparison. See Modern C++ Design by A. Alexandrescu for the gory detail.
00123     bool
00124     operator! () const
00125     {
00126       return curr_ == 0;
00127     }
00128 
00129     inline friend bool
00130     operator== (const Transport_Selection_Guard& lhs,
00131                 const TAO_Transport* rhs)
00132     {
00133       return lhs.curr_ == rhs;
00134     }
00135 
00136     inline friend bool
00137     operator== (const TAO_Transport* lhs,
00138                 const Transport_Selection_Guard& rhs)
00139     {
00140       return lhs == rhs.curr_;
00141     }
00142 
00143     inline friend bool
00144     operator!= (const Transport_Selection_Guard& lhs,
00145                 const TAO_Transport* rhs)
00146     {
00147       return lhs.curr_ != rhs;
00148     }
00149 
00150     inline friend bool
00151     operator!= (const TAO_Transport* lhs,
00152                 const Transport_Selection_Guard& rhs)
00153     {
00154       return lhs != rhs.curr_;
00155     }
00156 
00157     template <class U> inline friend bool
00158     operator== (const Transport_Selection_Guard& lhs,
00159                 const U* rhs)
00160     {
00161       return lhs.curr_ == rhs;
00162     }
00163 
00164     template <class U> inline friend bool
00165     operator== (const U* lhs,
00166                 const Transport_Selection_Guard& rhs)
00167     {
00168       return lhs == rhs.curr_;
00169     }
00170 
00171     template <class U> inline friend bool
00172     operator!= (const Transport_Selection_Guard& lhs,
00173                 const U* rhs)
00174     {
00175       return lhs.curr_ != rhs;
00176     }
00177 
00178     template <class U> inline friend bool
00179     operator!= (const U* lhs,
00180                 const Transport_Selection_Guard& rhs)
00181     {
00182       return lhs != rhs.curr_;
00183     }
00184 
00185   };
00186 
00187 } /* namespace TAO */
00188 
00189 
00190 
00191 
00192 TAO_END_VERSIONED_NAMESPACE_DECL
00193 
00194 #include /**/ "ace/post.h"
00195 
00196 #endif /* TAO_TRANSPORT_SELECTION_GUARD_H */

Generated on Tue Feb 2 17:37:53 2010 for TAO by  doxygen 1.4.7