00001 #include "tao/DynamicInterface/Dynamic_Implementation.h"
00002
00003 ACE_RCSID (DynamicInterface,
00004 Dynamic_Implementation,
00005 "$Id: Dynamic_Implementation.cpp 77480 2007-03-01 14:01:51Z johnnyw $")
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 {
00024 CORBA::RepositoryId_var id = this->get_id_from_primary_interface ();
00025
00026 return ACE_OS::strcmp (logical_type_id, id.in ()) == 0;
00027 }
00028
00029 CORBA::Object_ptr
00030 TAO_DynamicImplementation::_this (void)
00031 {
00032
00033
00034
00035
00036 TAO_Stub *stub = this->_create_stub ();
00037
00038
00039 CORBA::Object_ptr retval = CORBA::Object_ptr ();
00040 ACE_NEW_RETURN (retval,
00041 CORBA::Object (stub,
00042 1,
00043 this),
00044 CORBA::Object::_nil ());
00045
00046 return retval;
00047 }
00048
00049 CORBA::InterfaceDef_ptr
00050 TAO_DynamicImplementation::_get_interface (void)
00051 {
00052 TAO_IFR_Client_Adapter *adapter =
00053 ACE_Dynamic_Service<TAO_IFR_Client_Adapter>::instance (
00054 TAO_ORB_Core::ifr_client_adapter_name ());
00055
00056 if (adapter == 0)
00057 {
00058 throw ::CORBA::INTF_REPOS ();
00059 }
00060
00061 CORBA::RepositoryId_var id = this->get_id_from_primary_interface ();
00062
00063
00064
00065 return adapter->get_interface (TAO_ORB_Core_instance ()->orb (), id.in ());
00066 }
00067
00068 const char *
00069 TAO_DynamicImplementation::_interface_repository_id (void) const
00070 {
00071
00072 return 0;
00073 }
00074
00075 void *
00076 TAO_DynamicImplementation::_downcast (const char *)
00077 {
00078
00079 return this;
00080 }
00081
00082 TAO_Stub *
00083 TAO_DynamicImplementation::_create_stub (void)
00084 {
00085
00086
00087
00088
00089 TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
00090 static_cast <TAO::Portable_Server::POA_Current_Impl *>
00091 (TAO_TSS_Resources::instance ()->poa_current_impl_);
00092
00093 if (poa_current_impl == 0
00094 || this != poa_current_impl->servant ())
00095 {
00096 throw PortableServer::POA::WrongPolicy ();
00097 }
00098
00099 PortableServer::POA_var poa =
00100 poa_current_impl->get_POA ();
00101
00102 CORBA::PolicyList_var client_exposed_policies =
00103 poa_current_impl->poa ()->client_exposed_policies (
00104 poa_current_impl->priority ());
00105
00106 CORBA::RepositoryId_var pinterface =
00107 this->_primary_interface (poa_current_impl->object_id (), poa.in ());
00108
00109 return
00110 poa_current_impl->poa ()->key_to_stub (poa_current_impl->object_key (),
00111 pinterface.in (),
00112 poa_current_impl->priority ());
00113 }
00114
00115 void
00116 TAO_DynamicImplementation::_dispatch (TAO_ServerRequest &request,
00117 void * )
00118 {
00119
00120 if (request.response_expected ())
00121 {
00122 if (!CORBA::is_nil (request.forward_location ()))
00123 {
00124 request.init_reply ();
00125 request.tao_send_reply ();
00126
00127
00128 return;
00129 }
00130 else if (request.sync_with_server ())
00131 {
00132
00133
00134
00135
00136 request.send_no_exception_reply ();
00137 }
00138 }
00139
00140
00141 CORBA::ServerRequest *dsi_request = 0;
00142 ACE_NEW (dsi_request,
00143 CORBA::ServerRequest (request));
00144
00145 try
00146 {
00147
00148 this->invoke (dsi_request);
00149
00150
00151 if (request.response_expected () && !request.sync_with_server ())
00152 {
00153 dsi_request->dsi_marshal ();
00154 }
00155 }
00156 catch (const ::CORBA::Exception& ex)
00157 {
00158
00159 if (request.response_expected () && !request.sync_with_server ())
00160 {
00161 request.tao_send_reply_exception (ex);
00162 }
00163 }
00164
00165 ::CORBA::release (dsi_request);
00166 }
00167
00168 CORBA::RepositoryId
00169 TAO_DynamicImplementation::get_id_from_primary_interface (void)
00170 {
00171
00172
00173
00174
00175 TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
00176 static_cast <TAO::Portable_Server::POA_Current_Impl *>
00177 (TAO_TSS_Resources::instance ()->poa_current_impl_);
00178
00179 if (poa_current_impl == 0
00180 || this != poa_current_impl->servant ())
00181 {
00182 throw PortableServer::POA::WrongPolicy ();
00183 }
00184
00185 PortableServer::POA_var poa = poa_current_impl->get_POA ();
00186
00187 return this->_primary_interface (poa_current_impl->object_id (), poa.in ());
00188 }
00189
00190 TAO_END_VERSIONED_NAMESPACE_DECL