s/Uint/UInt/g
[ACE_TAO.git] / TAO / tao / Exclusive_TMS.cpp
blobf7c3e9c936fe18bd315e5d4a84fa3e627f9110e9
1 #include "tao/Exclusive_TMS.h"
2 #include "tao/Reply_Dispatcher.h"
3 #include "tao/debug.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),
11 request_id_ (0),
12 rd_ (nullptr)
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.
23 CORBA::ULong
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.
50 int
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 ();
57 return 0;
60 bool
61 TAO_Exclusive_TMS::has_request ()
63 return this->rd_ != nullptr;
66 int
67 TAO_Exclusive_TMS::unbind_dispatcher (CORBA::ULong request_id)
69 if (!this->rd_ || this->request_id_ != request_id)
70 return -1;
72 this->rd_.release ();
74 return 0;
77 int
78 TAO_Exclusive_TMS::dispatch_reply (TAO_Pluggable_Reply_Params &params)
80 // Check the ids.
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.
90 return 0;
93 ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> rd (this->rd_.get ());
94 this->request_id_ = 0; // @@ What is a good value???
95 this->rd_.release ();
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)
105 // Check the ids.
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.
115 return 0;
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 ();
124 return 0;
127 bool
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)
134 return false;
136 else
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 ();
145 return true;
149 bool
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 ();
163 return true;
166 void
167 TAO_Exclusive_TMS::connection_closed ()
169 if (this->rd_ != nullptr)
170 this->rd_->connection_closed ();
173 TAO_END_VERSIONED_NAMESPACE_DECL