1 #include "tao/Exclusive_TMS.h"
2 #include "tao/Reply_Dispatcher.h"
4 #include "tao/Transport.h"
6 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
8 TAO_Exclusive_TMS::TAO_Exclusive_TMS (TAO_Transport
*transport
)
9 : TAO_Transport_Mux_Strategy (transport
),
10 request_id_generator_ (0),
16 TAO_Exclusive_TMS::~TAO_Exclusive_TMS ()
20 // Generate and return an unique request id for the current
21 // invocation. We can actually return a predecided ULong, since we
22 // allow only one invocation over this connection at a time.
24 TAO_Exclusive_TMS::request_id ()
26 ++this->request_id_generator_
;
28 // if TAO_Transport::bidirectional_flag_
29 // == 1 --> originating side
30 // == 0 --> other side
31 // == -1 --> no bi-directional connection was negotiated
32 // The originating side must have an even request ID, and the other
33 // side must have an odd request ID. Make sure that is the case.
34 int const bidir_flag
=
35 this->transport_
->bidirectional_flag ();
37 if ((bidir_flag
== 1 && ACE_ODD (this->request_id_generator_
))
38 || (bidir_flag
== 0 && ACE_EVEN (this->request_id_generator_
)))
39 ++this->request_id_generator_
;
41 if (TAO_debug_level
> 4)
42 TAOLIB_DEBUG ((LM_DEBUG
,
43 ACE_TEXT ("TAO (%P|%t) - Exclusive_TMS::request_id - [%d]\n"),
44 this->request_id_generator_
));
46 return this->request_id_generator_
;
49 // Bind the handler with the request id.
51 TAO_Exclusive_TMS::bind_dispatcher (CORBA::ULong request_id
,
52 ACE_Intrusive_Auto_Ptr
<TAO_Reply_Dispatcher
> rd
)
54 this->request_id_
= request_id
;
55 this->rd_
= rd
.get ();
61 TAO_Exclusive_TMS::has_request ()
63 return this->rd_
!= nullptr;
67 TAO_Exclusive_TMS::unbind_dispatcher (CORBA::ULong request_id
)
69 if (!this->rd_
|| this->request_id_
!= request_id
)
78 TAO_Exclusive_TMS::dispatch_reply (TAO_Pluggable_Reply_Params
¶ms
)
81 if (!this->rd_
|| this->request_id_
!= params
.request_id_
)
83 if (TAO_debug_level
> 0)
84 TAOLIB_DEBUG ((LM_DEBUG
,
85 ACE_TEXT ("TAO (%P|%t) - Exclusive_TMS::dispatch_reply - [%d] != [%d]\n"),
86 this->request_id_
, params
.request_id_
));
88 // The return value 0 informs the transport that the mux strategy
89 // did not find the right reply handler.
93 ACE_Intrusive_Auto_Ptr
<TAO_Reply_Dispatcher
> rd (this->rd_
.get ());
94 this->request_id_
= 0; // @@ What is a good value???
97 // Dispatch the reply.
98 // Returns 1 on success, -1 on failure.
99 return rd
->dispatch_reply (params
);
103 TAO_Exclusive_TMS::reply_timed_out (CORBA::ULong request_id
)
106 if (!this->rd_
|| this->request_id_
!= request_id
)
108 if (TAO_debug_level
> 0)
109 TAOLIB_DEBUG ((LM_DEBUG
,
110 ACE_TEXT ("TAO (%P|%t) - Exclusive_TMS::reply_timed_out - [%d] != [%d]\n"),
111 this->request_id_
, request_id
));
113 // The return value 0 informs the transport that the mux strategy
114 // did not find the right reply handler.
118 ACE_Intrusive_Auto_Ptr
<TAO_Reply_Dispatcher
> rd (this->rd_
.get ());
119 this->request_id_
= 0; // @@ What is a good value???
120 this->rd_
.release ();
122 rd
->reply_timed_out ();
128 TAO_Exclusive_TMS::idle_after_send ()
130 // if there is no reply dispatcher (possible in case of AMI requests)
131 // release the transport now
132 if (this->rd_
!= nullptr)
138 if (this->transport_
!= nullptr)
140 // let WS know we're finished
141 this->transport_
->wait_strategy ()->finished_request ();
143 (void) this->transport_
->make_idle ();
150 TAO_Exclusive_TMS::idle_after_reply ()
152 // Irrespective of whether we are successful or not we need to
153 // return true. If *this* class is not successful in idling the
154 // transport no one can.
155 if (this->transport_
!= nullptr)
157 // let WS know we're finished
158 this->transport_
->wait_strategy ()->finished_request ();
160 (void) this->transport_
->make_idle ();
167 TAO_Exclusive_TMS::connection_closed ()
169 if (this->rd_
!= nullptr)
170 this->rd_
->connection_closed ();
173 TAO_END_VERSIONED_NAMESPACE_DECL