Dynamic_Implementation.cpp

Go to the documentation of this file.
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   // The _this() function returns a CORBA::Object_ptr for the target
00036   // object. Unlike _this() for static skeletons, its return type is
00037   // not interface-specific because a DSI servant may very well
00038   // incarnate multiple CORBA objects of different types.
00039   TAO_Stub *stub = this->_create_stub (ACE_ENV_SINGLE_ARG_PARAMETER);
00040   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00041 
00042   // Create a object.
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   // This doesn't take multiple ORBs into account, but it's being
00072   // used only to resolve the IFR, so we should be ok.
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   // This should never be called.
00082   return 0;
00083 }
00084 
00085 void *
00086 TAO_DynamicImplementation::_downcast (const char *repository_id)
00087 {
00088   ACE_UNUSED_ARG (repository_id);
00089 
00090   // Don't know enough to do better.
00091   return this;
00092 }
00093 
00094 TAO_Stub *
00095 TAO_DynamicImplementation::_create_stub (ACE_ENV_SINGLE_ARG_DECL)
00096 {
00097   // If DynamicImplementation::_this() is invoked outside of the
00098   // context of a request invocation on a target object being served
00099   // by the DSI servant, it raises the PortableServer::WrongPolicy
00100   // exception. See the CORBA C++ mapping, section 1.38.3.
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 * /* context */
00138                                       ACE_ENV_ARG_DECL)
00139 {
00140   // No need to do any of this if the client isn't waiting.
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           // No need to invoke in this case.
00149           return;
00150         }
00151       else if (request.sync_with_server ())
00152         {
00153           // The last line before the call to this function
00154           // was an ACE_CHECK_RETURN, so if we're here, we
00155           // know there is no exception so far, and that's all
00156           // a SYNC_WITH_SERVER client request cares about.
00157           request.send_no_exception_reply ();
00158         }
00159     }
00160 
00161   // Create DSI request object.
00162   CORBA::ServerRequest *dsi_request = 0;
00163   ACE_NEW (dsi_request,
00164            CORBA::ServerRequest (request));
00165 
00166   ACE_TRY
00167     {
00168       // Delegate to user.
00169       this->invoke (dsi_request
00170                     ACE_ENV_ARG_PARAMETER);
00171       ACE_TRY_CHECK;
00172 
00173       // Only if the client is waiting.
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       // Only if the client is waiting.
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   // If this method is called outside of the
00199   // context of a request invocation on a target object being served
00200   // by the DSI servant, it raises the PortableServer::WrongPolicy
00201   // exception. See the CORBA C++ mapping, section 1.38.3.
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

Generated on Thu Nov 9 13:04:21 2006 for TAO_DynamicInterface by doxygen 1.3.6