// $Id$ #include "tao/Muxed_TMS.h" #include "tao/Reply_Dispatcher.h" #include "tao/Pluggable.h" #include "tao/GIOP_Message_State.h" #include "tao/debug.h" ACE_RCSID(tao, Muxed_TMS, "$Id$") TAO_Muxed_TMS::TAO_Muxed_TMS (TAO_Transport *transport) : TAO_Transport_Mux_Strategy (transport), request_id_generator_ (0), orb_core_ (transport->orb_core ()), message_state_ (0) { } TAO_Muxed_TMS::~TAO_Muxed_TMS (void) { } // Generate and return an unique request id for the current // invocation. CORBA::ULong TAO_Muxed_TMS::request_id (void) { // @@ What is a good error return value? ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0); return this->request_id_generator_++; } // Bind the dispatcher with the request id. int TAO_Muxed_TMS::bind_dispatcher (CORBA::ULong request_id, TAO_Reply_Dispatcher *rd) { int result = this->dispatcher_table_.bind (request_id, rd); if (result != 0) { if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P | %t):TAO_Muxed_TMS::bind_dispatcher: ") ACE_TEXT ("bind dispatcher failed: result = %d\n"), result)); return -1; } return TAO_Transport_Mux_Strategy::bind_dispatcher (request_id, rd); } void TAO_Muxed_TMS::unbind_dispatcher (CORBA::ULong request_id) { ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->lock_); TAO_Reply_Dispatcher *rd = 0; (void) this->dispatcher_table_.unbind (request_id, rd); } int TAO_Muxed_TMS::dispatch_reply (CORBA::ULong request_id, CORBA::ULong reply_status, const TAO_GIOP_Version &version, IOP::ServiceContextList &reply_ctx, TAO_GIOP_Message_State *message_state) { // This message state should be the same as the one we have here, // which we gave to the Transport to read the message. Just a sanity // check here. ACE_ASSERT (message_state == this->message_state_); int result = 0; TAO_Reply_Dispatcher *rd = 0; // Grab the reply dispatcher for this id. { ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1); result = this->dispatcher_table_.unbind (request_id, rd); } if (result != 0) { if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P | %t):TAO_Muxed_TMS::dispatch_reply: ") ACE_TEXT ("unbind dispatcher failed: result = %d\n"), result)); return -1; } // Dispatch the reply. return rd->dispatch_reply (reply_status, version, reply_ctx, message_state); // No need for idling Transport, it would have got idle'd soon after // sending the request. } TAO_GIOP_Message_State * TAO_Muxed_TMS::get_message_state (void) { if (this->message_state_ == 0) { // Create the next message state. ACE_NEW_RETURN (this->message_state_, TAO_GIOP_Message_State (this->transport_->orb_core ()), 0); } return this->message_state_; } void TAO_Muxed_TMS::destroy_message_state (TAO_GIOP_Message_State *) { delete this->message_state_; this->message_state_ = 0; } int TAO_Muxed_TMS::idle_after_send (void) { if (this->transport_ != 0) return this->transport_->idle (); return 0; } int TAO_Muxed_TMS::idle_after_reply (void) { // No op. return 0; } void TAO_Muxed_TMS::connection_closed (void) { ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->lock_); // @@ This should be done using a mutex, the table REQUEST_DISPATCHER_TABLE::ITERATOR end = this->dispatcher_table_.begin (); for (REQUEST_DISPATCHER_TABLE::ITERATOR i = this->dispatcher_table_.begin (); i != end; ++i) { (*i).int_id_->connection_closed (); } this->dispatcher_table_.unbind_all (); } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template class ACE_Hash_Map_Manager_Ex , ACE_Equal_To , ACE_Null_Mutex>; template class ACE_Hash_Map_Entry; template class ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, ACE_Null_Mutex>; template class ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex>; template class ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex>; template class ACE_Equal_To ; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) #pragma instantiate ACE_Hash_Map_Manager_Ex , ACE_Equal_To , ACE_Null_Mutex> #pragma instantiate ACE_Hash_Map_Entry #pragma instantiate ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, ACE_Null_Mutex> #pragma instantiate ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex> #pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex> #pragma instantiate ACE_Equal_To #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */