00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Asynch_Reply_Dispatcher_Base.h 00006 * 00007 * Asynch_Reply_Dispatcher_Base.h,v 1.14 2006/04/20 13:36:42 jwillemsen Exp 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 , 00068 const ACE_Time_Value & 00069 ACE_ENV_ARG_DECL) = 0; 00070 00071 /// @name Mutators for refcount 00072 //@{ 00073 void incr_refcount (void); 00074 void decr_refcount (void); 00075 //@} 00076 00077 /// A helper method that can be used by the subclasses 00078 /** 00079 * The semantics of this helper method needs careful attention. A 00080 * call to this method will do the following 00081 * 00082 * - If the reply has already been dispatched, the return value 00083 * will be false to signify not to try. 00084 * 00085 * - If the reply has not been dispatched, this method will set 00086 * the flag to be true and return a true value to signify that 00087 * the caller thread can go ahead and dispatch reply. 00088 * 00089 * Why are we clumping everything in one method. Answer is we need 00090 * atomicity? 00091 */ 00092 bool try_dispatch_reply (void); 00093 00094 protected: 00095 00096 /// Destructor. 00097 virtual ~TAO_Asynch_Reply_Dispatcher_Base (void); 00098 00099 protected: 00100 /// The service context list. 00101 /** 00102 * Note, that this is not a reference as in 00103 * the synchronous case. We own the reply_service_info 00104 * because our TAO_Asynch_Invocation or TAO_DII_Deferred_Invocation 00105 * will go out of scope before we are done. 00106 */ 00107 IOP::ServiceContextList reply_service_info_; 00108 00109 /// The buffer that is used to initialise the data block 00110 char buf_[ACE_CDR::DEFAULT_BUFSIZE]; 00111 00112 /// Datablock that is created on the stack to initialise the CDR 00113 /// stream underneath. 00114 ACE_Data_Block db_; 00115 00116 /// CDR stream which has the reply information that needs to be 00117 /// demarshalled by the stubs 00118 TAO_InputCDR reply_cdr_; 00119 00120 /// This invocation is using this transport, may change... 00121 TAO_Transport *transport_; 00122 00123 private: 00124 /// Lock to protect refcount and @c is_reply_dispatched_ flag. 00125 ACE_Lock *lock_; 00126 00127 /// Refcount paraphernalia for this class 00128 CORBA::ULong refcount_; 00129 00130 /// Has the reply been dispatched? 00131 bool is_reply_dispatched_; 00132 00133 /// Allocator that was used to allocate this reply dispatcher. In case of 00134 /// zero we come from the heap. 00135 ACE_Allocator *allocator_; 00136 }; 00137 00138 namespace TAO 00139 { 00140 /** 00141 * @class ARDB_Refcount_Functor 00142 * 00143 * @brief Functor for refcounting of Asynch_Reply_Dispatcher_Base 00144 * 00145 * This is used to safely handle the destruction of 00146 * Asynch_Reply_Dispatcher_Base objects which are created on the 00147 * heap. We cannot use auto_ptr <> since it calls delete on the 00148 * pointer, and calling delete on Asynch_Reply_Dispatcher_Base * 00149 * will not work. Hence this functor will be used with Auto_Functor 00150 * class to handle the memory safely. 00151 * 00152 * @todo Ideally, this class can be a generic class. But that 00153 * requires quite a bit of cleanup within TAO to be more useful. 00154 */ 00155 class TAO_Export ARDB_Refcount_Functor 00156 { 00157 public: 00158 void operator() (TAO_Asynch_Reply_Dispatcher_Base *ardb) 00159 ACE_THROW_SPEC (()); 00160 }; 00161 00162 } 00163 00164 TAO_END_VERSIONED_NAMESPACE_DECL 00165 00166 #if defined (__ACE_INLINE__) 00167 #include "tao/Asynch_Reply_Dispatcher_Base.i" 00168 #endif /* __ACE_INLINE__ */ 00169 00170 #include /**/ "ace/post.h" 00171 #endif /* TAO_ASYNCH_REPLY_DISPATCHER_BASE_H */