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 85001 2009-03-31 10:06:45Z msmit $")
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 const bidir_flag = this->transport_->bidirectional_flag ();
00052
00053 if ((bidir_flag == 1 && ACE_ODD (this->request_id_generator_))
00054 || (bidir_flag == 0 && ACE_EVEN (this->request_id_generator_)))
00055 ++this->request_id_generator_;
00056
00057 if (TAO_debug_level > 4)
00058 ACE_DEBUG ((LM_DEBUG,
00059 "TAO (%P|%t) - Muxed_TMS[%d]::request_id, <%d>\n",
00060 this->transport_->id (),
00061 this->request_id_generator_));
00062
00063 return this->request_id_generator_;
00064 }
00065
00066
00067 int
00068 TAO_Muxed_TMS::bind_dispatcher (CORBA::ULong request_id,
00069 ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> rd)
00070 {
00071 ACE_GUARD_RETURN (ACE_Lock,
00072 ace_mon,
00073 *this->lock_,
00074 -1);
00075
00076 if (rd == 0)
00077 {
00078 if (TAO_debug_level > 0)
00079 {
00080 ACE_DEBUG ((LM_DEBUG,
00081 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::bind_dispatcher, ")
00082 ACE_TEXT ("null reply dispatcher\n")));
00083 }
00084 return 0;
00085 }
00086
00087 int const result = this->dispatcher_table_.bind (request_id, rd);
00088
00089 if (result != 0)
00090 {
00091 if (TAO_debug_level > 0)
00092 ACE_DEBUG ((LM_DEBUG,
00093 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::bind_dispatcher, ")
00094 ACE_TEXT ("bind dispatcher failed: result = %d, request id = %d\n"),
00095 result, request_id));
00096
00097 return -1;
00098 }
00099
00100 return 0;
00101 }
00102
00103 int
00104 TAO_Muxed_TMS::unbind_dispatcher (CORBA::ULong request_id)
00105 {
00106 ACE_GUARD_RETURN (ACE_Lock,
00107 ace_mon,
00108 *this->lock_,
00109 -1);
00110
00111 return this->dispatcher_table_.unbind (request_id);
00112 }
00113
00114 bool
00115 TAO_Muxed_TMS::has_request (void)
00116 {
00117 ACE_GUARD_RETURN (ACE_Lock,
00118 ace_mon,
00119 *this->lock_,
00120 false);
00121
00122 return this->dispatcher_table_.current_size () > 0;
00123 }
00124
00125 int
00126 TAO_Muxed_TMS::dispatch_reply (TAO_Pluggable_Reply_Params ¶ms)
00127 {
00128 int result = 0;
00129 ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> rd(0);
00130
00131
00132 {
00133 ACE_GUARD_RETURN (ACE_Lock,
00134 ace_mon,
00135 *this->lock_,
00136 -1);
00137 result = this->dispatcher_table_.unbind (params.request_id_, rd);
00138 }
00139
00140 if (result == 0 && rd)
00141 {
00142 if (TAO_debug_level > 8)
00143 ACE_DEBUG ((LM_DEBUG,
00144 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::dispatch_reply, ")
00145 ACE_TEXT ("id = %d\n"),
00146 params.request_id_));
00147
00148
00149
00150 result = rd->dispatch_reply (params);
00151 }
00152 else
00153 {
00154 if (TAO_debug_level > 0)
00155 ACE_DEBUG ((LM_DEBUG,
00156 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::dispatch_reply, ")
00157 ACE_TEXT ("unbind dispatcher failed, id %d: result = %d\n"),
00158 params.request_id_,
00159 result));
00160
00161
00162
00163
00164
00165 result = 0;
00166 }
00167
00168
00169 return result;
00170 }
00171
00172 int
00173 TAO_Muxed_TMS::reply_timed_out (CORBA::ULong request_id)
00174 {
00175 int result = 0;
00176 ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> rd(0);
00177
00178
00179 {
00180 ACE_GUARD_RETURN (ACE_Lock,
00181 ace_mon,
00182 *this->lock_,
00183 -1);
00184
00185 result = this->dispatcher_table_.unbind (request_id, rd);
00186 }
00187
00188 if (result == 0 && rd)
00189 {
00190 if (TAO_debug_level > 8)
00191 {
00192 ACE_DEBUG ((LM_DEBUG,
00193 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::reply_timed_out, ")
00194 ACE_TEXT ("id = %d\n"),
00195 request_id));
00196 }
00197
00198
00199
00200
00201
00202
00203
00204 rd->reply_timed_out ();
00205 }
00206 else
00207 {
00208 if (TAO_debug_level > 0)
00209 ACE_DEBUG ((LM_DEBUG,
00210 ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::reply_timed_out, ")
00211 ACE_TEXT ("unbind dispatcher failed, id %d: result = %d\n"),
00212 request_id,
00213 result));
00214
00215
00216
00217
00218
00219 result = 0;
00220 }
00221
00222 return result;
00223 }
00224
00225
00226 bool
00227 TAO_Muxed_TMS::idle_after_send (void)
00228 {
00229
00230
00231
00232 if (this->transport_ != 0)
00233 (void) this->transport_->make_idle ();
00234
00235 return true;
00236 }
00237
00238 bool
00239 TAO_Muxed_TMS::idle_after_reply (void)
00240 {
00241 return false;
00242 }
00243
00244 void
00245 TAO_Muxed_TMS::connection_closed (void)
00246 {
00247 ACE_GUARD (ACE_Lock,
00248 ace_mon,
00249 *this->lock_);
00250
00251 int retval = 0;
00252 do
00253 {
00254 retval = this->clear_cache_i ();
00255 }
00256 while (retval != -1);
00257 }
00258
00259 int
00260 TAO_Muxed_TMS::clear_cache_i (void)
00261 {
00262 if (this->dispatcher_table_.current_size () == 0)
00263 return -1;
00264
00265 REQUEST_DISPATCHER_TABLE::ITERATOR const end =
00266 this->dispatcher_table_.end ();
00267
00268 ACE_Unbounded_Stack <ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> > ubs;
00269
00270 for (REQUEST_DISPATCHER_TABLE::ITERATOR i =
00271 this->dispatcher_table_.begin ();
00272 i != end;
00273 ++i)
00274 {
00275 ubs.push ((*i).int_id_);
00276 }
00277
00278 this->dispatcher_table_.unbind_all ();
00279 size_t const sz = ubs.size ();
00280
00281 for (size_t k = 0 ; k != sz ; ++k)
00282 {
00283 ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> rd(0);
00284
00285 if (ubs.pop (rd) == 0)
00286 {
00287 rd->connection_closed ();
00288 }
00289 }
00290
00291 return 0;
00292 }
00293
00294 TAO_END_VERSIONED_NAMESPACE_DECL