Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / DynamicInterface / Dynamic_Implementation.cpp
blobe4c14c79d711f9673d53f2c9cdc12818164e34b1
1 // -*- C++ -*-
2 #include "tao/DynamicInterface/Dynamic_Implementation.h"
3 #include "tao/DynamicInterface/Server_Request.h"
4 #include "tao/ORB_Core.h"
5 #include "tao/TSS_Resources.h"
6 #include "tao/IFR_Client_Adapter.h"
7 #include "tao/PortableServer/Root_POA.h"
8 #include "tao/PortableServer/POA_Current_Impl.h"
9 #include "tao/PortableServer/Collocated_Arguments_Converter.h"
10 #include "tao/operation_details.h"
12 #include "ace/Dynamic_Service.h"
13 #include "ace/OS_NS_string.h"
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 CORBA::Boolean
18 TAO_DynamicImplementation::_is_a (const char *logical_type_id)
20 CORBA::RepositoryId_var id = this->get_id_from_primary_interface ();
22 return ACE_OS::strcmp (logical_type_id, id.in ()) == 0;
25 CORBA::Object_ptr
26 TAO_DynamicImplementation::_this ()
28 // The _this() function returns a CORBA::Object_ptr for the target
29 // object. Unlike _this() for static skeletons, its return type is
30 // not interface-specific because a DSI servant may very well
31 // incarnate multiple CORBA objects of different types.
32 TAO_Stub *stub = this->_create_stub ();
34 // Create a object.
35 CORBA::Object_ptr retval = CORBA::Object_ptr ();
36 ACE_NEW_RETURN (retval,
37 CORBA::Object (stub,
39 this),
40 CORBA::Object::_nil ());
42 return retval;
45 CORBA::InterfaceDef_ptr
46 TAO_DynamicImplementation::_get_interface ()
48 TAO_IFR_Client_Adapter *adapter =
49 ACE_Dynamic_Service<TAO_IFR_Client_Adapter>::instance (
50 TAO_ORB_Core::ifr_client_adapter_name ());
52 if (adapter == 0)
54 throw ::CORBA::INTF_REPOS ();
57 CORBA::RepositoryId_var id = this->get_id_from_primary_interface ();
59 // This doesn't take multiple ORBs into account, but it's being
60 // used only to resolve the IFR, so we should be ok.
61 return adapter->get_interface (TAO_ORB_Core_instance ()->orb (), id.in ());
64 const char *
65 TAO_DynamicImplementation::_interface_repository_id () const
67 // This should never be called.
68 return 0;
71 void *
72 TAO_DynamicImplementation::_downcast (const char *)
74 // Don't know enough to do better.
75 return this;
78 TAO_Stub *
79 TAO_DynamicImplementation::_create_stub ()
81 // If DynamicImplementation::_this() is invoked outside of the
82 // context of a request invocation on a target object being served
83 // by the DSI servant, it raises the PortableServer::WrongPolicy
84 // exception. See the CORBA C++ mapping, section 1.38.3.
85 TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
86 static_cast <TAO::Portable_Server::POA_Current_Impl *>
87 (TAO_TSS_Resources::instance ()->poa_current_impl_);
89 if (poa_current_impl == 0
90 || this != poa_current_impl->servant ())
92 throw PortableServer::POA::WrongPolicy ();
95 PortableServer::POA_var poa =
96 poa_current_impl->get_POA ();
98 CORBA::PolicyList_var client_exposed_policies =
99 poa_current_impl->poa ()->client_exposed_policies (
100 poa_current_impl->priority ());
102 CORBA::RepositoryId_var pinterface =
103 this->_primary_interface (poa_current_impl->object_id (), poa.in ());
105 return
106 poa_current_impl->poa ()->key_to_stub (poa_current_impl->object_key (),
107 pinterface.in (),
108 poa_current_impl->priority ());
111 void
112 TAO_DynamicImplementation::_dispatch (
113 TAO_ServerRequest &request,
114 TAO::Portable_Server::Servant_Upcall * /* context */)
116 // No need to do any of this if the client isn't waiting.
117 if (request.response_expected ())
119 if (request.is_forwarded ())
121 request.init_reply ();
122 request.tao_send_reply ();
124 // No need to invoke in this case.
125 return;
127 else if (request.sync_with_server ())
129 // The last line before the call to this function
130 // was an ACE_CHECK_RETURN, so if we're here, we
131 // know there is no exception so far, and that's all
132 // a SYNC_WITH_SERVER client request cares about.
133 request.send_no_exception_reply ();
137 // Create DSI request object.
138 CORBA::ServerRequest *dsi_request = 0;
139 ACE_NEW (dsi_request,
140 CORBA::ServerRequest (request));
144 // Delegate to user.
145 this->invoke (dsi_request);
147 // Only if the client is waiting.
148 if (request.response_expected () && !request.sync_with_server ())
150 dsi_request->dsi_marshal ();
153 catch (::CORBA::Exception& ex)
155 // Only if the client is waiting.
156 if (request.response_expected () && !request.sync_with_server ())
158 if (request.collocated ()
159 && request.operation_details ()->cac () != 0)
161 // If we have a cac it will handle the exception and no
162 // need to do any further processing
163 request.operation_details ()->cac ()->handle_corba_exception (
164 request, &ex);
165 return;
167 else
168 request.tao_send_reply_exception (ex);
172 ::CORBA::release (dsi_request);
175 CORBA::RepositoryId
176 TAO_DynamicImplementation::get_id_from_primary_interface ()
178 // If this method is called outside of the
179 // context of a request invocation on a target object being served
180 // by the DSI servant, it raises the PortableServer::WrongPolicy
181 // exception. See the CORBA C++ mapping, section 1.38.3.
182 TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
183 static_cast <TAO::Portable_Server::POA_Current_Impl *>
184 (TAO_TSS_Resources::instance ()->poa_current_impl_);
186 if (poa_current_impl == 0
187 || this != poa_current_impl->servant ())
189 throw PortableServer::POA::WrongPolicy ();
192 PortableServer::POA_var poa = poa_current_impl->get_POA ();
194 return this->_primary_interface (poa_current_impl->object_id (), poa.in ());
197 TAO_END_VERSIONED_NAMESPACE_DECL