1 #include "tao/DynamicInterface/Server_Request.h"
2 #include "tao/AnyTypeCode/TypeCode_Constants.h"
3 #include "tao/AnyTypeCode/NVList.h"
4 #include "tao/AnyTypeCode/SystemExceptionA.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/Thread_Lane_Resources.h"
11 Roundtrip::Roundtrip (CORBA::ORB_ptr orb
)
12 : orb_ (CORBA::ORB::_duplicate (orb
))
17 Roundtrip::invoke (CORBA::ServerRequest_ptr request
,
18 TAO_AMH_DSI_Response_Handler_ptr rh
)
20 if (ACE_OS::strcmp ("shutdown", request
->operation ()) == 0)
22 this->orb_
->shutdown (false);
27 else if (ACE_OS::strcmp ("_is_a", request
->operation ()) == 0)
29 CORBA::NVList_ptr list
;
30 this->orb_
->create_list (0, list
);
33 type_id
._tao_set_typecode (CORBA::_tc_string
);
34 list
->add_value ("type_id", type_id
, CORBA::ARG_IN
);
36 request
->arguments (list
);
38 // list still has ownership of the item
39 CORBA::NamedValue_ptr nv
= list
->item (0);
42 *(nv
->value ()) >>= arg
;
44 CORBA::Boolean type_matches
= false;
45 if (ACE_OS::strcmp (arg
, "IDL:Test/Roundtrip:1.0") == 0
46 || ACE_OS::strcmp (arg
, "IDL:omg.org/CORBA/Object:1.0") == 0
47 || ACE_OS::strcmp (arg
, "") == 0)
50 CORBA::Any result_any
;
51 result_any
<<= CORBA::Any::from_boolean (type_matches
);
53 // AMH way of replying
54 CORBA::NamedValue_var result
= 0;
55 this->orb_
->create_named_value (result
.out());
56 *(result
->value()) = result_any
;
57 rh
->invoke_reply (list
, result
.in ());
62 else if (ACE_OS::strcmp ("test_method", request
->operation ()) == 0)
64 CORBA::NVList_ptr list
; // will become property of the arguments list
65 this->orb_
->create_list (0, list
);
68 send_time
._tao_set_typecode (CORBA::_tc_ulonglong
);
69 list
->add_value ("send_time", send_time
, CORBA::ARG_IN
);
71 request
->arguments (list
);
73 CORBA::NamedValue_ptr nv
= list
->item (0);
75 // AMH way of replying
76 rh
->invoke_reply (list
, nv
);
81 CORBA::Any bad_operation
;
82 CORBA::BAD_OPERATION exception
;
83 bad_operation
<<= exception
;
84 request
->set_exception (bad_operation
);
88 Roundtrip::_primary_interface (const PortableServer::ObjectId
&,
89 PortableServer::POA_ptr
)
91 return CORBA::string_dup ("IDL:Test/Roundtrip:1.0");
95 Roundtrip::_dispatch (TAO_ServerRequest
&request
,
96 TAO::Portable_Server::Servant_Upcall
* /* context */)
98 // No need to do any of this if the client isn't waiting.
99 if (request
.response_expected ())
101 if (!CORBA::is_nil (request
.forward_location ()))
103 request
.init_reply ();
104 request
.tao_send_reply ();
106 // No need to invoke in this case.
109 else if (request
.sync_with_server ())
111 // The last line before the call to this function
112 // was an ACE_CHECK_RETURN, so if we're here, we
113 // know there is no exception so far, and that's all
114 // a SYNC_WITH_SERVER client request cares about.
115 request
.send_no_exception_reply ();
119 // Create DSI request object.
120 CORBA::ServerRequest
*dsi_request
= 0;
121 ACE_NEW (dsi_request
,
122 CORBA::ServerRequest (request
));
126 TAO_AMH_DSI_Response_Handler_ptr rh_ptr
;
127 ACE_NEW (rh_ptr
, TAO_AMH_DSI_Response_Handler(request
));
128 TAO_AMH_DSI_Response_Handler_var
rh(rh_ptr
);
129 rh
->init (request
, 0);
131 this->invoke (dsi_request
, rh
.in());
133 catch (const CORBA::Exception
& ex
)
136 // Only if the client is waiting.
137 if (request
.response_expected () && !request
.sync_with_server ())
139 request
.tao_send_reply_exception (ex
);
143 CORBA::release (dsi_request
);
147 Roundtrip::invoke (CORBA::ServerRequest_ptr
)
149 throw CORBA::NO_IMPLEMENT();