Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / tao / Messaging / Asynch_Invocation_Adapter.cpp
blob81a643b90ecdea36ec7cd3fd66bd2edddc9443ae
1 // -*- C++ -*-
2 #include "tao/Messaging/Asynch_Invocation_Adapter.h"
3 #include "tao/Messaging/Asynch_Reply_Dispatcher.h"
4 #include "tao/Messaging/Asynch_Invocation.h"
5 #include "tao/Messaging/AMI_Arguments_Converter_Impl.h"
7 #include "tao/Profile_Transport_Resolver.h"
8 #include "tao/operation_details.h"
9 #include "tao/Stub.h"
10 #include "tao/Transport.h"
11 #include "tao/Muxed_TMS.h"
12 #include "tao/ORB_Constants.h"
13 #include "tao/debug.h"
14 #include "tao/ORB_Core.h"
15 #include "tao/Thread_Lane_Resources.h"
16 #include "tao/GIOP_Utils.h"
18 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
20 namespace TAO
22 Asynch_Invocation_Adapter::Asynch_Invocation_Adapter (
23 CORBA::Object *target,
24 Argument **args,
25 int arg_number,
26 const char *operation,
27 size_t op_len,
28 int collocation_opportunity,
29 Invocation_Mode m,
30 bool has_in_args)
31 : Invocation_Adapter (target,
32 args,
33 arg_number,
34 operation,
35 op_len,
36 collocation_opportunity,
37 TAO_TWOWAY_INVOCATION,
39 has_in_args)
40 , safe_rd_ ()
44 void
45 Asynch_Invocation_Adapter::invoke (
46 Messaging::ReplyHandler_ptr reply_handler_ptr,
47 const TAO_Reply_Handler_Stub &reply_handler_stub)
49 TAO_Stub * stub =
50 this->get_stub ();
52 if (TAO_debug_level >= 4)
54 TAOLIB_DEBUG ((LM_DEBUG,
55 "TAO_Messaging (%P|%t) - Asynch_Invocation_Adapter::"
56 "invoke\n"));
59 // If the reply handler is nil, we do not create a reply dispatcher.
60 // The ORB will drop replies to which it cannot associate a reply
61 // dispatcher.
62 if (!CORBA::is_nil (reply_handler_ptr))
64 // New reply dispatcher on the heap or allocator, because
65 // we will go out of scope and hand over the reply dispatcher
66 // to the ORB.
67 TAO_Asynch_Reply_Dispatcher *rd = 0;
69 // Get the allocator we could use.
70 ACE_Allocator* ami_allocator =
71 stub->orb_core ()->lane_resources().ami_response_handler_allocator();
73 // If we have an allocator, use it, else use the heap.
74 if (ami_allocator)
76 ACE_NEW_MALLOC (
77 rd,
78 static_cast<TAO_Asynch_Reply_Dispatcher *> (
79 ami_allocator->malloc (sizeof (TAO_Asynch_Reply_Dispatcher))),
80 TAO_Asynch_Reply_Dispatcher (reply_handler_stub,
81 reply_handler_ptr,
82 stub->orb_core (),
83 ami_allocator));
85 else
87 ACE_NEW (rd,
88 TAO_Asynch_Reply_Dispatcher (reply_handler_stub,
89 reply_handler_ptr,
90 stub->orb_core (),
91 0));
94 if (rd == 0)
96 throw ::CORBA::NO_MEMORY ();
99 this->safe_rd_.reset (rd);
102 Invocation_Adapter::invoke (0, 0);
105 void
106 Asynch_Invocation_Adapter::invoke (
107 const TAO::Exception_Data *ex,
108 unsigned long ex_count)
110 Invocation_Adapter::invoke (ex, ex_count );
113 Invocation_Status
114 Asynch_Invocation_Adapter::invoke_collocated_i (
115 TAO_Stub *stub,
116 TAO_Operation_Details &details,
117 CORBA::Object_var &effective_target,
118 Collocation_Strategy strat)
120 if (stub->orb_core ()->orb_params ()->ami_collication ())
122 // When doing a collocation asynch invocation we shouldn't use the
123 // stub args but use the skel args
124 details.use_stub_args (false);
126 TAO_AMI_Arguments_Converter_Impl* ami_arguments_converter
127 = ACE_Dynamic_Service<TAO_AMI_Arguments_Converter_Impl>::instance (
128 "AMI_Arguments_Converter");
129 details.cac (ami_arguments_converter);
131 // Release the owner ship of the reply dispatcher
132 details.reply_dispatcher (this->safe_rd_.release ());
134 return Invocation_Adapter::invoke_collocated_i (stub,
135 details,
136 effective_target,
137 strat);
139 else
141 ACE_Time_Value *max_wait_time = 0;
142 return Invocation_Adapter::invoke_remote_i (stub,
143 details,
144 effective_target,
145 max_wait_time);
149 Invocation_Status
150 Asynch_Invocation_Adapter::invoke_twoway (
151 TAO_Operation_Details &op,
152 CORBA::Object_var &effective_target,
153 Profile_Transport_Resolver &r,
154 ACE_Time_Value *&max_wait_time,
155 Invocation_Retry_State *retry_state)
157 ACE_UNUSED_ARG (retry_state);
159 // Simple sanity check
160 if (this->mode_ != TAO_ASYNCHRONOUS_CALLBACK_INVOCATION
161 || this->type_ != TAO_TWOWAY_INVOCATION)
163 throw ::CORBA::INTERNAL (
164 CORBA::SystemException::_tao_minor_code (
165 TAO::VMCID,
166 EINVAL),
167 CORBA::COMPLETED_NO);
170 if (this->safe_rd_.get () && r.transport ())
172 this->safe_rd_->transport (r.transport ());
173 // AMI Timeout Handling Begin
174 ACE_Time_Value tmp;
176 if (this->get_timeout (r.stub (), tmp))
178 this->safe_rd_->schedule_timer (op.request_id (), *max_wait_time);
182 // Loose ownership of the reply dispatcher
183 TAO::Asynch_Remote_Invocation asynch (
184 effective_target.in (),
187 this->safe_rd_.release ());
189 // forward requested byte order
190 asynch._tao_byte_order (this->_tao_byte_order ());
192 Invocation_Status const s = asynch.remote_invocation (max_wait_time);
194 if (s == TAO_INVOKE_RESTART &&
195 (asynch.reply_status () == GIOP::LOCATION_FORWARD ||
196 asynch.reply_status () == GIOP::LOCATION_FORWARD_PERM))
198 CORBA::Boolean const permanent_forward =
199 (asynch.reply_status () == GIOP::LOCATION_FORWARD_PERM);
201 effective_target = asynch.steal_forwarded_reference ();
203 this->object_forwarded (effective_target, r.stub (), permanent_forward);
206 return s;
209 } // End namespace TAO
211 TAO_END_VERSIONED_NAMESPACE_DECL