00001
00002 #include "tao/Messaging/Asynch_Invocation_Adapter.h"
00003 #include "tao/Messaging/Asynch_Reply_Dispatcher.h"
00004 #include "tao/Messaging/Asynch_Invocation.h"
00005 #include "tao/Messaging/AMI_Arguments_Converter_Impl.h"
00006
00007 #include "tao/Profile_Transport_Resolver.h"
00008 #include "tao/operation_details.h"
00009 #include "tao/Stub.h"
00010 #include "tao/Transport.h"
00011 #include "tao/Muxed_TMS.h"
00012 #include "tao/ORB_Constants.h"
00013 #include "tao/debug.h"
00014 #include "tao/ORB_Core.h"
00015 #include "tao/Thread_Lane_Resources.h"
00016 #include "tao/GIOP_Utils.h"
00017
00018
00019 ACE_RCSID (Messaging,
00020 Asynch_Invocation_Adapter,
00021 "$Id: Asynch_Invocation_Adapter.cpp 82596 2008-08-11 18:01:34Z johnnyw $")
00022
00023
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025
00026 namespace TAO
00027 {
00028 Asynch_Invocation_Adapter::Asynch_Invocation_Adapter (
00029 CORBA::Object *target,
00030 Argument **args,
00031 int arg_number,
00032 const char *operation,
00033 size_t op_len,
00034 Collocation_Proxy_Broker *p,
00035 Invocation_Mode m)
00036 : Invocation_Adapter (target,
00037 args,
00038 arg_number,
00039 operation,
00040 op_len,
00041 p,
00042 TAO_TWOWAY_INVOCATION,
00043 m)
00044 , safe_rd_ ()
00045 {
00046 }
00047
00048 void
00049 Asynch_Invocation_Adapter::invoke (
00050 Messaging::ReplyHandler_ptr reply_handler_ptr,
00051 const TAO_Reply_Handler_Stub &reply_handler_stub)
00052 {
00053 TAO_Stub * stub =
00054 this->get_stub ();
00055
00056 if (TAO_debug_level >= 4)
00057 {
00058 ACE_DEBUG ((LM_DEBUG,
00059 "TAO_Messaging (%P|%t) - Asynch_Invocation_Adapter::"
00060 "invoke\n"));
00061 }
00062
00063
00064
00065
00066 if (!CORBA::is_nil (reply_handler_ptr))
00067 {
00068
00069
00070
00071 TAO_Asynch_Reply_Dispatcher *rd = 0;
00072
00073
00074 ACE_Allocator* ami_allocator =
00075 stub->orb_core ()->lane_resources().ami_response_handler_allocator();
00076
00077
00078 if (ami_allocator)
00079 {
00080 ACE_NEW_MALLOC (
00081 rd,
00082 static_cast<TAO_Asynch_Reply_Dispatcher *> (
00083 ami_allocator->malloc (sizeof (TAO_Asynch_Reply_Dispatcher))),
00084 TAO_Asynch_Reply_Dispatcher (reply_handler_stub,
00085 reply_handler_ptr,
00086 stub->orb_core (),
00087 ami_allocator));
00088 }
00089 else
00090 {
00091 ACE_NEW (rd,
00092 TAO_Asynch_Reply_Dispatcher (reply_handler_stub,
00093 reply_handler_ptr,
00094 stub->orb_core (),
00095 0));
00096 }
00097
00098 if (rd == 0)
00099 {
00100 throw ::CORBA::NO_MEMORY ();
00101 }
00102
00103 this->safe_rd_.reset (rd);
00104 }
00105
00106 Invocation_Adapter::invoke (0, 0);
00107 }
00108
00109 void
00110 Asynch_Invocation_Adapter::invoke (
00111 TAO::Exception_Data *ex,
00112 unsigned long ex_count
00113 )
00114 {
00115 Invocation_Adapter::invoke (ex, ex_count );
00116 }
00117
00118 Invocation_Status
00119 Asynch_Invocation_Adapter::invoke_collocated_i (
00120 TAO_Stub *stub,
00121 TAO_Operation_Details &details,
00122 CORBA::Object_var &effective_target,
00123 Collocation_Strategy strat)
00124 {
00125 if (stub->orb_core ()->orb_params ()->ami_collication ())
00126 {
00127
00128
00129 details.use_stub_args (false);
00130
00131 TAO_AMI_Arguments_Converter_Impl* ami_arguments_converter
00132 = ACE_Dynamic_Service<TAO_AMI_Arguments_Converter_Impl>::instance (
00133 "AMI_Arguments_Converter");
00134 details.cac (ami_arguments_converter);
00135
00136
00137 details.reply_dispatcher (this->safe_rd_.release ());
00138
00139 return Invocation_Adapter::invoke_collocated_i (stub,
00140 details,
00141 effective_target,
00142 strat);
00143 }
00144 else
00145 {
00146 ACE_Time_Value *max_wait_time = 0;
00147 return Invocation_Adapter::invoke_remote_i (stub,
00148 details,
00149 effective_target,
00150 max_wait_time);
00151 }
00152 }
00153
00154 Invocation_Status
00155 Asynch_Invocation_Adapter::invoke_twoway (
00156 TAO_Operation_Details &op,
00157 CORBA::Object_var &effective_target,
00158 Profile_Transport_Resolver &r,
00159 ACE_Time_Value *&max_wait_time)
00160 {
00161
00162 if (this->mode_ != TAO_ASYNCHRONOUS_CALLBACK_INVOCATION
00163 || this->type_ != TAO_TWOWAY_INVOCATION)
00164 {
00165 throw ::CORBA::INTERNAL (
00166 CORBA::SystemException::_tao_minor_code (
00167 TAO::VMCID,
00168 EINVAL),
00169 CORBA::COMPLETED_NO);
00170 }
00171
00172 if (this->safe_rd_.get () && r.transport ())
00173 {
00174 this->safe_rd_->transport (r.transport ());
00175
00176 ACE_Time_Value tmp;
00177
00178 if (this->get_timeout (r.stub (), tmp))
00179 {
00180 this->safe_rd_->schedule_timer (op.request_id (), *max_wait_time);
00181 }
00182 }
00183
00184
00185 TAO::Asynch_Remote_Invocation asynch (
00186 effective_target.in (),
00187 r,
00188 op,
00189 this->safe_rd_.release ());
00190
00191 Invocation_Status const s = asynch.remote_invocation (max_wait_time);
00192
00193 if (s == TAO_INVOKE_RESTART &&
00194 (asynch.reply_status () == GIOP::LOCATION_FORWARD ||
00195 asynch.reply_status () == GIOP::LOCATION_FORWARD_PERM))
00196 {
00197 CORBA::Boolean const permanent_forward =
00198 (asynch.reply_status () == GIOP::LOCATION_FORWARD_PERM);
00199
00200 effective_target = asynch.steal_forwarded_reference ();
00201
00202 this->object_forwarded (effective_target, r.stub (), permanent_forward);
00203 }
00204
00205 return s;
00206 }
00207
00208 }
00209
00210 TAO_END_VERSIONED_NAMESPACE_DECL