00001
00002
00003 #include "tao/Muxed_TMS.h"
00004 #include "tao/Reply_Dispatcher.h"
00005 #include "tao/debug.h"
00006 #include "tao/Transport.h"
00007 #include "tao/ORB_Core.h"
00008 #include "tao/Client_Strategy_Factory.h"
00009
00010 ACE_RCSID (tao,
00011 Muxed_TMS,
00012 "$Id: Muxed_TMS.cpp 79169 2007-08-02 08:41:23Z johnnyw $")
00013
00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00015
00016 TAO_Muxed_TMS::TAO_Muxed_TMS (TAO_Transport *transport)
00017 : TAO_Transport_Mux_Strategy (transport)
00018 , lock_ (0)
00019 , request_id_generator_ (0)
00020 , orb_core_ (transport->orb_core ())
00021 , dispatcher_table_ (this->orb_core_->client_factory ()->reply_dispatcher_table_size ())
00022 {
00023 this->lock_ =
00024 this->orb_core_->client_factory ()->create_transport_mux_strategy_lock ();
00025 }
00026
00027 TAO_Muxed_TMS::~TAO_Muxed_TMS (void)
00028 {
00029 delete this->lock_;
00030 }
00031
00032
00033
00034 CORBA::ULong
00035 TAO_Muxed_TMS::request_id (void)
00036 {
00037
00038 ACE_GUARD_RETURN (ACE_Lock,
00039 ace_mon,
00040 *this->lock_,
00041 0);
00042
00043 ++this->request_id_generator_;
00044
00045
00046
00047
00048
00049
00050
00051 int bidir_flag =
00052 this->transport_->bidirectional_flag ();
00053
00054 if ((bidir_flag == 1 && ACE_ODD (this->request_id_generator_))
00055 || (bidir_flag == 0 && ACE_EVEN (this->request_id_generator_)))
00056 ++this->request_id_generator_;
00057
00058 if (TAO_debug_level > 4)
00059 ACE_DEBUG ((LM_DEBUG,
00060 "TAO (%P|%t) - Muxed_TMS[%d]::request_id, <%d>\n",
00061 this->transport_->id (),
00062 this->request_id_generator_));
00063
00064 return this->request_id_generator_;
00065 }
00066
00067
00068 int
00069 TAO_Muxed_TMS::bind_dispatcher (CORBA::ULong request_id,
00070 TAO_Reply_Dispatcher *rd)
00071 {
00072 ACE_GUARD_RETURN (ACE_Lock,
00073 ace_mon,
00074 *this->lock_,
00075 -1);
00076
00077 if (TAO_debug_level > 0 && rd == 0)
00078 ACE_DEBUG ((LM_DEBUG,
00079 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::bind_dispatcher, ")
00080 ACE_TEXT ("null reply dispatcher\n")));
00081
00082 if (rd == 0)
00083 return 0;
00084
00085 int const result = this->dispatcher_table_.bind (request_id, rd);
00086
00087 if (result != 0)
00088 {
00089 if (TAO_debug_level > 0)
00090 ACE_DEBUG ((LM_DEBUG,
00091 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::bind_dispatcher, ")
00092 ACE_TEXT ("bind dispatcher failed: result = %d, request id = %d \n"),
00093 result, request_id));
00094
00095 return -1;
00096 }
00097
00098 return 0;
00099 }
00100
00101 int
00102 TAO_Muxed_TMS::unbind_dispatcher (CORBA::ULong request_id)
00103 {
00104 ACE_GUARD_RETURN (ACE_Lock,
00105 ace_mon,
00106 *this->lock_,
00107 -1);
00108 TAO_Reply_Dispatcher *rd = 0;
00109
00110
00111
00112 return this->dispatcher_table_.unbind (request_id, rd);
00113 }
00114
00115 int
00116 TAO_Muxed_TMS::dispatch_reply (TAO_Pluggable_Reply_Params ¶ms)
00117 {
00118 int result = 0;
00119 TAO_Reply_Dispatcher *rd = 0;
00120
00121
00122 {
00123 ACE_GUARD_RETURN (ACE_Lock,
00124 ace_mon,
00125 *this->lock_,
00126 -1);
00127
00128 result = this->dispatcher_table_.unbind (params.request_id_, rd);
00129
00130 if (TAO_debug_level > 8)
00131 ACE_DEBUG ((LM_DEBUG,
00132 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::dispatch_reply, ")
00133 ACE_TEXT ("id = %d\n"),
00134 params.request_id_));
00135
00136 if (result != 0)
00137 {
00138 if (TAO_debug_level > 0)
00139 ACE_DEBUG ((LM_DEBUG,
00140 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::dispatch_reply, ")
00141 ACE_TEXT ("unbind dispatcher failed: result = %d\n"),
00142 result));
00143
00144
00145
00146
00147
00148 return 0;
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158 result = rd->dispatch_reply (params);
00159 }
00160
00161 return result;
00162 }
00163
00164 bool
00165 TAO_Muxed_TMS::idle_after_send (void)
00166 {
00167
00168
00169
00170 if (this->transport_ != 0)
00171 (void) this->transport_->make_idle ();
00172
00173 return true;
00174 }
00175
00176 bool
00177 TAO_Muxed_TMS::idle_after_reply (void)
00178 {
00179 return false;
00180 }
00181
00182 void
00183 TAO_Muxed_TMS::connection_closed (void)
00184 {
00185 ACE_GUARD (ACE_Lock,
00186 ace_mon,
00187 *this->lock_);
00188
00189 int retval = 0;
00190 do
00191 {
00192 retval = this->clear_cache ();
00193 }
00194 while (retval != -1);
00195 }
00196
00197 int
00198 TAO_Muxed_TMS::clear_cache (void)
00199 {
00200 if (this->dispatcher_table_.current_size () == 0)
00201 return -1;
00202
00203 REQUEST_DISPATCHER_TABLE::ITERATOR const end =
00204 this->dispatcher_table_.end ();
00205
00206 ACE_Unbounded_Stack <TAO_Reply_Dispatcher *> ubs;
00207
00208 for (REQUEST_DISPATCHER_TABLE::ITERATOR i =
00209 this->dispatcher_table_.begin ();
00210 i != end;
00211 ++i)
00212 ubs.push ((*i).int_id_);
00213
00214 this->dispatcher_table_.unbind_all ();
00215 size_t const sz = ubs.size ();
00216
00217 for (size_t k = 0 ; k != sz ; ++k)
00218 {
00219 TAO_Reply_Dispatcher *rd = 0;
00220
00221 ubs.pop (rd);
00222
00223 rd->connection_closed ();
00224 }
00225
00226 return 0;
00227 }
00228
00229 TAO_END_VERSIONED_NAMESPACE_DECL