Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / examples / ORT / Gateway_i.cpp
blob075e7306e56badbdb3716329d0a84358f05036f9
1 #include "Gateway_i.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "tao/AnyTypeCode/NVList.h"
5 #include "tao/AnyTypeCode/ExceptionA.h"
7 #include "tao/IFR_Client/IFR_BasicC.h"
9 #include "tao/DynamicInterface/Server_Request.h"
10 #include "tao/DynamicInterface/Request.h"
11 #include "tao/DynamicInterface/Unknown_User_Exception.h"
13 #include "tao/ORB.h"
14 #include "tao/LocalObject.h"
16 Gateway_i::
17 Gateway_i (CORBA::ORB_ptr orb,
18 PortableServer::Current_ptr poa_current)
19 : orb_ (orb),
20 poa_current_ (poa_current)
22 /// Constructor
25 void
26 Gateway_i::invoke (CORBA::ServerRequest_ptr request)
28 PortableServer::ObjectId_var target_id =
29 this->poa_current_->get_object_id ();
31 CORBA::String_var stringified_object_id =
32 PortableServer::ObjectId_to_string (target_id.in ());
34 CORBA::Object_var target_object =
35 this->orb_->string_to_object (stringified_object_id.in ());
37 // Use the IfR interfaces to query the NVList for this object...
38 CORBA::InterfaceDef_var target_interface =
39 target_object->_get_interface ();
41 if (CORBA::is_nil (target_interface.in ()))
43 ///
46 // This is the target operation...
47 CORBA::String_var operation_name =
48 request->operation ();
50 CORBA::Contained_var contained_operation =
51 target_interface->lookup (operation_name.in ());
53 CORBA::OperationDef_var operation =
54 CORBA::OperationDef::_narrow (contained_operation.in ());
56 // Save the result typecode...
57 CORBA::TypeCode_var result_typecode =
58 operation.in ()->result ();
60 CORBA::ParDescriptionSeq_var parameters =
61 operation.in ()->params ();
63 // Build the NVList based on the info from the IfR
64 CORBA::NVList_ptr arguments;
65 this->orb_->create_list (parameters->length (),
66 arguments);
68 CORBA::Flags flags = 0;
70 CORBA::ULong length = parameters->length ();
72 CORBA::ULong i = 0;
74 for (i = 0; i < length; ++i)
76 switch (parameters[i].mode)
78 case CORBA::PARAM_IN:
79 flags = CORBA::ARG_IN;
80 break;
81 case CORBA::PARAM_OUT:
82 flags = CORBA::ARG_OUT;
83 break;
84 case CORBA::PARAM_INOUT:
85 flags = CORBA::ARG_INOUT;
86 break;
90 for (i = 0; i != length; ++i)
92 CORBA::Any any;
93 any._tao_set_typecode (parameters[i].type.in ());
95 arguments->add_value (parameters[i].name,
96 any,
97 flags);
100 // Extract the values of the arguments from the DSI ServerRequest
101 request->arguments (arguments);
103 // Use the NVList (with values) to create a DII Request...
104 CORBA::Request_var dii_request;
106 CORBA::NamedValue *named_value = 0;
108 this->orb_->create_named_value (named_value);
110 CORBA::ContextList *context_list = 0;
111 CORBA::ExceptionList *exceptions = 0;
113 target_object->_create_request (CORBA::Context::_nil (),
114 operation_name.in (),
115 arguments,
116 named_value, /* Result */
117 exceptions,
118 context_list, /* Context List */
119 dii_request.inout (),
120 CORBA::Flags (0));
122 // Set the return type...
123 dii_request->set_return_type (result_typecode.in ());
127 // Make the DII request
128 dii_request->invoke ();
130 // At this point the NVList contains all the out and inout
131 // arguments, but we need to extract the return value...
133 catch (CORBA::UnknownUserException& user_ex)
135 // Pass the exception back to the server request...
136 request->set_exception (user_ex.exception ());
137 return;
139 catch (const CORBA::SystemException& sys_ex)
141 CORBA::Any any;
142 any <<= sys_ex;
143 // Pass the exception back to the server request...
144 request->set_exception (any);
145 return;
147 catch (const CORBA::Exception&)
151 request->set_result (dii_request->return_value ());
152 // Using the same NVList for both the DSI Server Request and the DII
153 // Request takes care of the out and inout arguments (whew!)
156 CORBA::RepositoryId
157 Gateway_i::_primary_interface (const PortableServer::ObjectId &,
158 PortableServer::POA_ptr)
160 return 0;