Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Synch_Reply_Dispatcher.cpp
bloba63bcad601ca9e555dec9c0682dcbc03e9eec40e
1 #include "tao/Synch_Reply_Dispatcher.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/Pluggable_Messaging_Utils.h"
4 #include "tao/debug.h"
6 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
8 // Constructor.
9 TAO_Synch_Reply_Dispatcher::TAO_Synch_Reply_Dispatcher (
10 TAO_ORB_Core *orb_core,
11 IOP::ServiceContextList &sc
13 : reply_service_info_ (sc),
14 orb_core_ (orb_core),
15 db_ (sizeof buf_,
16 ACE_Message_Block::MB_DATA,
17 this->buf_,
18 this->orb_core_->input_cdr_buffer_allocator (),
19 this->orb_core_->locking_strategy (),
20 ACE_Message_Block::DONT_DELETE,
21 this->orb_core_->input_cdr_dblock_allocator ()),
22 reply_cdr_ (&db_,
23 ACE_Message_Block::DONT_DELETE,
24 TAO_ENCAP_BYTE_ORDER,
25 TAO_DEF_GIOP_MAJOR,
26 TAO_DEF_GIOP_MINOR,
27 orb_core)
29 // As a TAO_LF_Event we start in the active state....
30 this->state_changed_i (TAO_LF_Event::LFS_ACTIVE);
33 // Destructor.
34 TAO_Synch_Reply_Dispatcher::~TAO_Synch_Reply_Dispatcher ()
38 TAO_InputCDR &
39 TAO_Synch_Reply_Dispatcher::reply_cdr ()
41 return this->reply_cdr_;
44 void
45 TAO_Synch_Reply_Dispatcher::reply_timed_out ()
47 // noop
50 int
51 TAO_Synch_Reply_Dispatcher::dispatch_reply (
52 TAO_Pluggable_Reply_Params &params)
54 if (params.input_cdr_ == nullptr)
55 return -1;
57 this->reply_status_ = params.reply_status ();
58 this->locate_reply_status_ = params.locate_reply_status ();
60 // Steal the buffer, that way we don't do any unnecessary copies of
61 // this data.
62 CORBA::ULong const max = params.svc_ctx_.maximum ();
63 CORBA::ULong const len = params.svc_ctx_.length ();
64 IOP::ServiceContext* context_list = params.svc_ctx_.get_buffer (true);
65 this->reply_service_info_.replace (max, len, context_list, true);
67 if (this->reply_service_info_.length() > 0)
69 orb_core_->service_context_registry ().
70 process_service_contexts (this->reply_service_info_, *(params.transport_), nullptr);
73 // Must reset the message state, it is possible that the same reply
74 // dispatcher is used because the request must be re-sent.
75 // this->message_state_.reset (0);
77 // Transfer the <params.input_cdr_>'s content to this->reply_cdr_
78 if (ACE_BIT_DISABLED ((*params.input_cdr_).start()->data_block()->flags(),
79 ACE_Message_Block::DONT_DELETE))
81 // Data block is on the heap, so just duplicate it.
82 this->reply_cdr_ = *params.input_cdr_;
83 this->reply_cdr_.clr_mb_flags (ACE_Message_Block::DONT_DELETE);
85 else
87 ACE_Data_Block *db = this->reply_cdr_.clone_from (*params.input_cdr_);
89 if (db == nullptr)
91 if (TAO_debug_level > 2)
93 TAOLIB_ERROR ((LM_ERROR,
94 "TAO (%P|%t) - Synch_Reply_Dispatcher::dispatch_reply "
95 "clone_from failed\n"));
97 return -1;
100 // See whether we need to delete the data block by checking the
101 // flags. We cannot be happy that we initally allocated the
102 // datablocks of the stack. If this method is called twice, as is in
103 // some cases where the same invocation object is used to make two
104 // invocations like forwarding, the release becomes essential.
105 if (ACE_BIT_DISABLED (db->flags (),
106 ACE_Message_Block::DONT_DELETE))
108 db->release ();
112 this->state_changed (TAO_LF_Event::LFS_SUCCESS,
113 this->orb_core_->leader_follower ());
115 return 1;
118 void
119 TAO_Synch_Reply_Dispatcher::connection_closed ()
121 this->state_changed (TAO_LF_Event::LFS_CONNECTION_CLOSED,
122 this->orb_core_->leader_follower ());
125 TAO_END_VERSIONED_NAMESPACE_DECL