00001
00002
00003 #include "tao/Asynch_Reply_Dispatcher_Base.h"
00004 #include "tao/Pluggable_Messaging_Utils.h"
00005 #include "tao/ORB_Core.h"
00006 #include "tao/debug.h"
00007 #include "tao/Transport.h"
00008
00009 #if !defined (__ACE_INLINE__)
00010 #include "tao/Asynch_Reply_Dispatcher_Base.inl"
00011 #endif
00012
00013 ACE_RCSID (tao,
00014 Asynch_Reply_Dispatcher_Base,
00015 "$Id: Asynch_Reply_Dispatcher_Base.cpp 76962 2007-02-08 16:29:30Z johnnyw $")
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019
00020 TAO_Asynch_Reply_Dispatcher_Base::TAO_Asynch_Reply_Dispatcher_Base (
00021 TAO_ORB_Core *orb_core,
00022 ACE_Allocator *allocator
00023 )
00024 : db_ (sizeof buf_,
00025 ACE_Message_Block::MB_DATA,
00026 this->buf_,
00027 orb_core->input_cdr_buffer_allocator (),
00028 orb_core->locking_strategy (),
00029 ACE_Message_Block::DONT_DELETE,
00030 orb_core->input_cdr_dblock_allocator ()),
00031 reply_cdr_ (&db_,
00032 ACE_Message_Block::MB_DATA,
00033 TAO_ENCAP_BYTE_ORDER,
00034 TAO_DEF_GIOP_MAJOR,
00035 TAO_DEF_GIOP_MINOR,
00036 orb_core)
00037 , transport_ (0)
00038 , lock_ (0)
00039 , refcount_ (1)
00040 , is_reply_dispatched_ (false)
00041 , allocator_ (allocator)
00042 {
00043
00044 this->lock_ =
00045 orb_core->resource_factory ()->create_cached_connection_lock ();
00046 }
00047
00048
00049 TAO_Asynch_Reply_Dispatcher_Base::~TAO_Asynch_Reply_Dispatcher_Base (void)
00050 {
00051
00052 if (this->transport_ != 0)
00053 this->transport_->remove_reference ();
00054
00055 if (this->lock_)
00056 delete this->lock_;
00057 }
00058
00059 void
00060 TAO_Asynch_Reply_Dispatcher_Base::transport (TAO_Transport *t)
00061 {
00062 if (this->transport_ != 0)
00063 this->transport_->remove_reference ();
00064
00065 this->transport_ = t;
00066
00067 this->transport_->add_reference ();
00068 }
00069
00070
00071 int
00072 TAO_Asynch_Reply_Dispatcher_Base::dispatch_reply (
00073 TAO_Pluggable_Reply_Params & )
00074 {
00075 return 0;
00076 }
00077
00078 void
00079 TAO_Asynch_Reply_Dispatcher_Base::connection_closed (void)
00080 {
00081 }
00082
00083 void
00084 TAO_Asynch_Reply_Dispatcher_Base::reply_timed_out (void)
00085 {
00086 }
00087
00088 void
00089 TAO_Asynch_Reply_Dispatcher_Base::incr_refcount (void)
00090 {
00091 ACE_GUARD (ACE_Lock,
00092 mutex,
00093 *this->lock_);
00094 ++this->refcount_;
00095 }
00096
00097 void
00098 TAO_Asynch_Reply_Dispatcher_Base::decr_refcount (void)
00099 {
00100 {
00101 ACE_GUARD (ACE_Lock,
00102 mutex,
00103 *this->lock_);
00104 --this->refcount_;
00105
00106 if (this->refcount_ > 0)
00107 return;
00108 }
00109
00110 if (this->allocator_)
00111 {
00112 ACE_DES_FREE (this,
00113 this->allocator_->free,
00114 TAO_Asynch_Reply_Dispatcher_Base);
00115 }
00116 else
00117 {
00118 delete this;
00119 }
00120
00121 return;
00122 }
00123
00124 bool
00125 TAO_Asynch_Reply_Dispatcher_Base::try_dispatch_reply (void)
00126 {
00127 if (this->is_reply_dispatched_)
00128 {
00129 return false;
00130 }
00131 else
00132 {
00133 ACE_GUARD_RETURN (ACE_Lock,
00134 mutex,
00135 *this->lock_,
00136 false);
00137
00138 if (!this->is_reply_dispatched_)
00139 {
00140 this->is_reply_dispatched_ = true;
00141 return true;
00142 }
00143 }
00144
00145 return false;
00146 }
00147
00148 TAO_END_VERSIONED_NAMESPACE_DECL