00001 #include "tao/DynamicInterface/Dynamic_Implementation.h"
00002
00003 ACE_RCSID (DynamicInterface,
00004 Dynamic_Implementation,
00005 "Dynamic_Implementation.cpp,v 1.23 2006/04/19 09:40:15 jwillemsen Exp")
00006
00007
00008 #include "tao/DynamicInterface/Server_Request.h"
00009 #include "tao/ORB_Core.h"
00010 #include "tao/TSS_Resources.h"
00011 #include "tao/IFR_Client_Adapter.h"
00012 #include "tao/PortableServer/Root_POA.h"
00013 #include "tao/PortableServer/POA_Current_Impl.h"
00014
00015 #include "ace/Dynamic_Service.h"
00016 #include "ace/OS_NS_string.h"
00017
00018
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020
00021 CORBA::Boolean
00022 TAO_DynamicImplementation::_is_a (const char *logical_type_id
00023 ACE_ENV_ARG_DECL)
00024 {
00025 CORBA::RepositoryId_var id =
00026 this->get_id_from_primary_interface (ACE_ENV_SINGLE_ARG_PARAMETER);
00027 ACE_CHECK_RETURN (0);
00028
00029 return ACE_OS::strcmp (logical_type_id, id.in ()) == 0;
00030 }
00031
00032 CORBA::Object_ptr
00033 TAO_DynamicImplementation::_this (ACE_ENV_SINGLE_ARG_DECL)
00034 {
00035
00036
00037
00038
00039 TAO_Stub *stub = this->_create_stub (ACE_ENV_SINGLE_ARG_PARAMETER);
00040 ACE_CHECK_RETURN (CORBA::Object::_nil ());
00041
00042
00043 CORBA::Object_ptr retval = CORBA::Object::_nil ();
00044 ACE_NEW_RETURN (retval,
00045 CORBA::Object (stub,
00046 1,
00047 this),
00048 CORBA::Object::_nil ());
00049
00050 return retval;
00051 }
00052
00053 CORBA::InterfaceDef_ptr
00054 TAO_DynamicImplementation::_get_interface (ACE_ENV_SINGLE_ARG_DECL)
00055 {
00056 TAO_IFR_Client_Adapter *adapter =
00057 ACE_Dynamic_Service<TAO_IFR_Client_Adapter>::instance (
00058 TAO_ORB_Core::ifr_client_adapter_name ()
00059 );
00060
00061 if (adapter == 0)
00062 {
00063 ACE_THROW_RETURN (CORBA::INTF_REPOS (),
00064 0);
00065 }
00066
00067 CORBA::RepositoryId_var id =
00068 this->get_id_from_primary_interface (ACE_ENV_SINGLE_ARG_PARAMETER);
00069 ACE_CHECK_RETURN (0);
00070
00071
00072
00073 return adapter->get_interface (TAO_ORB_Core_instance ()->orb (),
00074 id.in ()
00075 ACE_ENV_ARG_PARAMETER);
00076 }
00077
00078 const char *
00079 TAO_DynamicImplementation::_interface_repository_id (void) const
00080 {
00081
00082 return 0;
00083 }
00084
00085 void *
00086 TAO_DynamicImplementation::_downcast (const char *repository_id)
00087 {
00088 ACE_UNUSED_ARG (repository_id);
00089
00090
00091 return this;
00092 }
00093
00094 TAO_Stub *
00095 TAO_DynamicImplementation::_create_stub (ACE_ENV_SINGLE_ARG_DECL)
00096 {
00097
00098
00099
00100
00101 TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
00102 static_cast <TAO::Portable_Server::POA_Current_Impl *>
00103 (TAO_TSS_Resources::instance ()->poa_current_impl_);
00104
00105 if (poa_current_impl == 0
00106 || this != poa_current_impl->servant ())
00107 {
00108 ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
00109 0);
00110 }
00111
00112 PortableServer::POA_var poa =
00113 poa_current_impl->get_POA ();
00114
00115 CORBA::PolicyList_var client_exposed_policies =
00116 poa_current_impl->poa ()->client_exposed_policies (
00117 poa_current_impl->priority ()
00118 ACE_ENV_ARG_PARAMETER
00119 );
00120 ACE_CHECK_RETURN (0);
00121
00122 CORBA::RepositoryId_var pinterface =
00123 this->_primary_interface (poa_current_impl->object_id (),
00124 poa.in ()
00125 ACE_ENV_ARG_PARAMETER);
00126 ACE_CHECK_RETURN (0);
00127
00128 return
00129 poa_current_impl->poa ()->key_to_stub (poa_current_impl->object_key (),
00130 pinterface.in (),
00131 poa_current_impl->priority ()
00132 ACE_ENV_ARG_PARAMETER);
00133 }
00134
00135 void
00136 TAO_DynamicImplementation::_dispatch (TAO_ServerRequest &request,
00137 void *
00138 ACE_ENV_ARG_DECL)
00139 {
00140
00141 if (request.response_expected ())
00142 {
00143 if (!CORBA::is_nil (request.forward_location ()))
00144 {
00145 request.init_reply ();
00146 request.tao_send_reply ();
00147
00148
00149 return;
00150 }
00151 else if (request.sync_with_server ())
00152 {
00153
00154
00155
00156
00157 request.send_no_exception_reply ();
00158 }
00159 }
00160
00161
00162 CORBA::ServerRequest *dsi_request = 0;
00163 ACE_NEW (dsi_request,
00164 CORBA::ServerRequest (request));
00165
00166 ACE_TRY
00167 {
00168
00169 this->invoke (dsi_request
00170 ACE_ENV_ARG_PARAMETER);
00171 ACE_TRY_CHECK;
00172
00173
00174 if (request.response_expected () && !request.sync_with_server ())
00175 {
00176 dsi_request->dsi_marshal (ACE_ENV_SINGLE_ARG_PARAMETER);
00177 ACE_TRY_CHECK;
00178 }
00179 }
00180 ACE_CATCH (CORBA::Exception, ex)
00181 {
00182
00183 if (request.response_expected () && !request.sync_with_server ())
00184 {
00185 request.tao_send_reply_exception (ex);
00186 }
00187 }
00188 ACE_ENDTRY;
00189
00190 ::CORBA::release (dsi_request);
00191 }
00192
00193 CORBA::RepositoryId
00194 TAO_DynamicImplementation::get_id_from_primary_interface (
00195 ACE_ENV_SINGLE_ARG_DECL
00196 )
00197 {
00198
00199
00200
00201
00202 TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
00203 static_cast <TAO::Portable_Server::POA_Current_Impl *>
00204 (TAO_TSS_Resources::instance ()->poa_current_impl_);
00205
00206 if (poa_current_impl == 0
00207 || this != poa_current_impl->servant ())
00208 {
00209 ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
00210 0);
00211 }
00212
00213 PortableServer::POA_var poa =
00214 poa_current_impl->get_POA ();
00215
00216 return this->_primary_interface (poa_current_impl->object_id (),
00217 poa.in ()
00218 ACE_ENV_ARG_PARAMETER);
00219 }
00220
00221 TAO_END_VERSIONED_NAMESPACE_DECL