Exclusive_TMS.cpp

Go to the documentation of this file.
00001 // Exclusive_TMS.cpp,v 1.17 2006/03/30 11:45:46 jwillemsen Exp
00002 
00003 #include "tao/Exclusive_TMS.h"
00004 #include "tao/Reply_Dispatcher.h"
00005 #include "tao/debug.h"
00006 #include "tao/Transport.h"
00007 
00008 ACE_RCSID (tao,
00009            Exclusive_TMS,
00010            "Exclusive_TMS.cpp,v 1.17 2006/03/30 11:45:46 jwillemsen Exp")
00011 
00012 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00013 
00014 TAO_Exclusive_TMS::TAO_Exclusive_TMS (TAO_Transport *transport)
00015   : TAO_Transport_Mux_Strategy (transport),
00016     request_id_generator_ (0),
00017     has_request_ (0),
00018     request_id_ (0),
00019     rd_ (0)
00020 {
00021 }
00022 
00023 TAO_Exclusive_TMS::~TAO_Exclusive_TMS (void)
00024 {
00025 }
00026 
00027 // Generate and return an unique request id for the current
00028 // invocation. We can actually return a predecided ULong, since we
00029 // allow only one invocation over this connection at a time.
00030 CORBA::ULong
00031 TAO_Exclusive_TMS::request_id (void)
00032 {
00033   ++this->request_id_generator_;
00034 
00035   // if TAO_Transport::bidirectional_flag_
00036   //  ==  1 --> originating side
00037   //  ==  0 --> other side
00038   //  == -1 --> no bi-directional connection was negotiated
00039   // The originating side must have an even request ID, and the other
00040   // side must have an odd request ID.  Make sure that is the case.
00041   int bidir_flag =
00042     this->transport_->bidirectional_flag ();
00043 
00044   if ((bidir_flag == 1 && ACE_ODD (this->request_id_generator_))
00045        || (bidir_flag == 0 && ACE_EVEN (this->request_id_generator_)))
00046     ++this->request_id_generator_;
00047 
00048   if (TAO_debug_level > 4)
00049     ACE_DEBUG ((LM_DEBUG,
00050                 ACE_TEXT ("TAO (%P|%t) - Exclusive_TMS::request_id - <%d>\n"),
00051                 this->request_id_generator_));
00052 
00053   return this->request_id_generator_;
00054 }
00055 
00056 // Bind the handler with the request id.
00057 int
00058 TAO_Exclusive_TMS::bind_dispatcher (CORBA::ULong request_id,
00059                                     TAO_Reply_Dispatcher *rd)
00060 {
00061   this->has_request_ = 1;
00062   this->request_id_ = request_id;
00063   this->rd_ = rd;
00064 
00065   return 0;
00066 }
00067 
00068 int
00069 TAO_Exclusive_TMS::unbind_dispatcher (CORBA::ULong request_id)
00070 {
00071   if (!this->has_request_ || this->request_id_ != request_id)
00072     return -1;
00073   this->has_request_ = 0;
00074   this->request_id_ = 0;
00075   this->rd_ = 0;
00076 
00077   return 0;
00078 }
00079 
00080 int
00081 TAO_Exclusive_TMS::dispatch_reply (TAO_Pluggable_Reply_Params &params)
00082 {
00083   // Check the ids.
00084   if (!this->has_request_ || this->request_id_ != params.request_id_)
00085     {
00086       if (TAO_debug_level > 0)
00087         ACE_DEBUG ((LM_DEBUG,
00088                     ACE_TEXT ("(%P|%t) TAO_Exclusive_TMS::dispatch_reply - <%d != %d>\n"),
00089                     this->request_id_, params.request_id_));
00090 
00091       // The return value 0 informs the transport that the mux strategy
00092       // did not find the right reply handler.
00093       return 0;
00094     }
00095 
00096   TAO_Reply_Dispatcher *rd = this->rd_;
00097   this->has_request_ = 0;
00098   this->request_id_ = 0; // @@ What is a good value???
00099   this->rd_ = 0;
00100 
00101   // Dispatch the reply.
00102   // Returns 1 on success, -1 on failure.
00103   return rd->dispatch_reply (params);
00104 }
00105 
00106 bool
00107 TAO_Exclusive_TMS::idle_after_send (void)
00108 {
00109   return false;
00110 }
00111 
00112 bool
00113 TAO_Exclusive_TMS::idle_after_reply (void)
00114 {
00115   // Irrespective of whether we are successful or not we need to
00116   // return true. If *this* class is not successfull in idling the
00117   // transport no one can.
00118   if (this->transport_ != 0)
00119     (void) this->transport_->make_idle ();
00120 
00121   return true;
00122 }
00123 
00124 void
00125 TAO_Exclusive_TMS::connection_closed (void)
00126 {
00127   if (this->rd_ != 0)
00128     this->rd_->connection_closed ();
00129 }
00130 
00131 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:11 2006 for TAO by doxygen 1.3.6