Asynch_Reply_Dispatcher_Base.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file Asynch_Reply_Dispatcher_Base.h
00006  *
00007  *  $Id: Asynch_Reply_Dispatcher_Base.h 77151 2007-02-15 13:24:41Z johnnyw $
00008  *
00009  *  @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
00010  *  @author Jeff Parsons <parsons@cs.wustl.edu>
00011  */
00012 //=============================================================================
00013 
00014 #ifndef TAO_ASYNCH_REPLY_DISPATCHER_BASE_H
00015 #define TAO_ASYNCH_REPLY_DISPATCHER_BASE_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "tao/Reply_Dispatcher.h"
00020 #include "tao/CDR.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #include "tao/IOP_IORC.h"
00027 
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029 class ACE_Time_Value;
00030 class ACE_Lock;
00031 class ACE_Allocator;
00032 ACE_END_VERSIONED_NAMESPACE_DECL
00033 
00034 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00035 
00036 class TAO_Pluggable_Reply_Params;
00037 class TAO_ORB_Core;
00038 class TAO_Transport;
00039 /**
00040  * @class TAO_Asynch_Reply_Dispatcher_Base
00041  *
00042  * @brief Base class for TAO_Asynch_Reply_Dispatcher and
00043  *  TAO_DII_Deferred_Reply_Dispatcher
00044  */
00045 class TAO_Export TAO_Asynch_Reply_Dispatcher_Base
00046   : public TAO_Reply_Dispatcher
00047 {
00048 public:
00049   /// Default constructor.
00050   TAO_Asynch_Reply_Dispatcher_Base (TAO_ORB_Core *orb_core,
00051                                     ACE_Allocator *allocator = 0);
00052 
00053   /// Sets the transport for this invocation.
00054   void transport (TAO_Transport *t);
00055 
00056   /// @name The Reply Dispatcher methods
00057   //@{
00058   virtual int dispatch_reply (TAO_Pluggable_Reply_Params &) = 0;
00059 
00060   virtual void connection_closed (void) = 0;
00061   //@}
00062 
00063   /// Inform that the reply timed out
00064   virtual void reply_timed_out (void) = 0;
00065 
00066   /// Install the timeout handler
00067   virtual long schedule_timer (CORBA::ULong , const ACE_Time_Value &) = 0;
00068 
00069   /// @name Mutators for refcount
00070   //@{
00071   void incr_refcount (void);
00072   void decr_refcount (void);
00073   //@}
00074 
00075   /// A helper method that can be used by the subclasses
00076   /**
00077    * The semantics of this helper method needs careful attention. A
00078    * call to this method will do the following
00079    *
00080    *   - If the reply has already been dispatched, the return value
00081    *     will be false to signify not to try.
00082    *
00083    *   - If the reply has not been dispatched, this method will set
00084    *     the flag to be true and return a true value to signify that
00085    *     the caller thread can go ahead and dispatch reply.
00086    *
00087    * Why are we clumping everything in one method. Answer is we need
00088    * atomicity?
00089    */
00090   bool try_dispatch_reply (void);
00091 
00092 protected:
00093 
00094   /// Destructor.
00095   virtual ~TAO_Asynch_Reply_Dispatcher_Base (void);
00096 
00097 protected:
00098   /// The service context list.
00099   /**
00100    * Note, that this is not a reference as in
00101    * the synchronous case. We own the reply_service_info
00102    * because our TAO_Asynch_Invocation or TAO_DII_Deferred_Invocation
00103    * will go out of scope before we are done.
00104    */
00105   IOP::ServiceContextList reply_service_info_;
00106 
00107   /// The buffer that is used to initialise the data block
00108   char buf_[ACE_CDR::DEFAULT_BUFSIZE];
00109 
00110   /// Datablock that is created on the stack to initialise the CDR
00111   /// stream underneath.
00112   ACE_Data_Block db_;
00113 
00114   /// CDR stream which has the reply information that needs to be
00115   /// demarshalled by the stubs
00116   TAO_InputCDR reply_cdr_;
00117 
00118   /// This invocation is using this transport, may change...
00119   TAO_Transport *transport_;
00120 
00121 private:
00122   /// Lock to protect refcount and @c is_reply_dispatched_ flag.
00123   ACE_Lock *lock_;
00124 
00125   /// Refcount paraphernalia for this class
00126   CORBA::ULong refcount_;
00127 
00128   /// Has the reply been dispatched?
00129   bool is_reply_dispatched_;
00130 
00131   /// Allocator that was used to allocate this reply dispatcher. In case of
00132   /// zero we come from the heap.
00133   ACE_Allocator *allocator_;
00134 };
00135 
00136 namespace TAO
00137 {
00138   /**
00139    * @class ARDB_Refcount_Functor
00140    *
00141    * @brief Functor for refcounting of Asynch_Reply_Dispatcher_Base
00142    *
00143    * This is used to safely handle the destruction of
00144    * Asynch_Reply_Dispatcher_Base objects which are created on the
00145    * heap. We cannot use auto_ptr <> since it calls delete on the
00146    * pointer, and calling delete on Asynch_Reply_Dispatcher_Base *
00147    * will not work. Hence this functor will be used with Auto_Functor
00148    * class to handle the memory safely.
00149    *
00150    * @todo Ideally, this class can be a generic class. But that
00151    * requires quite a bit of cleanup within TAO to be more useful.
00152    */
00153   class TAO_Export ARDB_Refcount_Functor
00154   {
00155   public:
00156     void operator() (TAO_Asynch_Reply_Dispatcher_Base *ardb) throw ();
00157   };
00158 
00159 }
00160 
00161 TAO_END_VERSIONED_NAMESPACE_DECL
00162 
00163 #if defined (__ACE_INLINE__)
00164 #include "tao/Asynch_Reply_Dispatcher_Base.inl"
00165 #endif /* __ACE_INLINE__ */
00166 
00167 #include /**/ "ace/post.h"
00168 #endif /* TAO_ASYNCH_REPLY_DISPATCHER_BASE_H */

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