Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / DSI_AMI_Gateway / test_dsi.cpp
blobfae8cacfd7343d99ad0f6800d3c15e024a64e5ba
1 #include "test_dsi.h"
2 #include "tao/DynamicInterface/Request.h"
3 #include "tao/DynamicInterface/Unknown_User_Exception.h"
4 #include "tao/TAO_Server_Request.h"
5 #include "tao/Transport.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/Thread_Lane_Resources.h"
8 #include "My_DII_Reply_Handler.h"
10 #if !defined(__ACE_INLINE__)
11 #include "test_dsi.inl"
12 #endif /* __ACE_INLINE__ */
14 void
15 DSI_Simple_Server::_dispatch (TAO_ServerRequest &request, TAO::Portable_Server::Servant_Upcall *)
17 // No need to do any of this if the client isn't waiting.
18 if (request.response_expected ())
20 if (!CORBA::is_nil (request.forward_location ()))
22 request.init_reply ();
23 request.tao_send_reply ();
25 // No need to invoke in this case.
26 return;
28 else if (request.sync_with_server ())
30 // The last line before the call to this function
31 // was an ACE_CHECK_RETURN, so if we're here, we
32 // know there is no exception so far, and that's all
33 // a SYNC_WITH_SERVER client request cares about.
34 request.send_no_exception_reply ();
38 // Create DSI request object.
39 CORBA::ServerRequest *dsi_request = 0;
40 ACE_NEW (dsi_request,
41 CORBA::ServerRequest (request));
43 try
45 TAO_AMH_DSI_Response_Handler_ptr rh_ptr;
46 ACE_NEW (rh_ptr, TAO_AMH_DSI_Response_Handler(request));
48 TAO_AMH_DSI_Response_Handler_var rh(rh_ptr);
49 rh->init (request, 0);
50 // Delegate to user.
51 this->invoke (dsi_request, rh.in());
53 catch (const CORBA::Exception& ex)
56 // Only if the client is waiting.
57 if (request.response_expected () && !request.sync_with_server ())
59 request.tao_send_reply_exception (ex);
63 CORBA::release (dsi_request);
66 void
67 DSI_Simple_Server::invoke (CORBA::ServerRequest_ptr)
71 void
72 DSI_Simple_Server::invoke (CORBA::ServerRequest_ptr request,
73 TAO_AMH_DSI_Response_Handler * rph)
75 CORBA::NVList_ptr opList;
76 this->orb_->create_list (0, opList);
78 request->arguments (opList);
80 CORBA::Request_var target_request;
82 this->target_->_create_request (0, // ctx
83 request->operation (),
84 opList,
85 0, // result
86 0, // exception_list,
87 0, // context_list,
88 target_request.inout (),
89 0);
91 target_request->_tao_lazy_evaluation (1);
93 // Outgoing request must have the same byte order as the incoming one.
94 target_request->_tao_byte_order (request->_tao_incoming_byte_order ());
96 try
98 // Updates the byte order state, if necessary.
99 TAO_DII_Reply_Handler_ptr rh_ptr;
100 ACE_NEW (rh_ptr, My_DII_Reply_Handler (rph, this->orb_));
101 TAO_DII_Reply_Handler_var rh(rh_ptr);
102 target_request->sendc (rh.in());
104 catch (const CORBA::UNKNOWN&)
106 // Outgoing reply must have the same byte order as the incoming one.
107 request->_tao_reply_byte_order (target_request->_tao_byte_order ());
109 request->gateway_exception_reply (
110 target_request->raw_user_exception ());
111 return;
114 // Regular replies are handled by the DII AMI/DSI AMH reply handler
115 // combination without further involvement of the request objects.
116 // The DII AMI reply handler must propagate the incoming reply
117 // byte order to the DSI AMH reply handler
119 if (ACE_OS::strcmp ("shutdown", request->operation ()) == 0)
121 this->orb_->shutdown (0);
125 CORBA::RepositoryId
126 DSI_Simple_Server::_primary_interface (const PortableServer::ObjectId &,
127 PortableServer::POA_ptr)
129 return CORBA::string_dup ("IDL:Simple_Server:1.0");
132 PortableServer::POA_ptr
133 DSI_Simple_Server::_default_POA (void)
135 return PortableServer::POA::_duplicate (this->poa_.in ());