LifespanStrategyPersistent.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #include "tao/PortableServer/LifespanStrategyPersistent.h"
00004 
00005 ACE_RCSID (PortableServer,
00006            Lifespan_Strategy,
00007            "LifespanStrategyPersistent.cpp,v 1.13 2006/03/10 07:19:13 jtc Exp")
00008 
00009 #include "tao/PortableServer/Root_POA.h"
00010 #include "tao/PortableServer/POAManager.h"
00011 #include "tao/PortableServer/ImR_Client_Adapter.h"
00012 #include "tao/ORB_Core.h"
00013 #include "ace/OS_NS_sys_time.h"
00014 #include "ace/Dynamic_Service.h"
00015 #include "ace/Service_Config.h"
00016 
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018 
00019 namespace TAO
00020 {
00021   namespace Portable_Server
00022   {
00023     void
00024     LifespanStrategyPersistent::strategy_init (
00025       TAO_Root_POA *poa
00026       ACE_ENV_ARG_DECL)
00027     {
00028       LifespanStrategy::strategy_init (poa ACE_ENV_ARG_PARAMETER);
00029       ACE_CHECK;
00030 
00031       this->use_imr_ = this->poa_->orb_core ().use_implrepo ();
00032     }
00033 
00034     bool
00035     LifespanStrategyPersistent::validate (
00036       CORBA::Boolean is_persistent,
00037       const TAO::Portable_Server::Temporary_Creation_Time& /*creation_time*/) const
00038     {
00039       return is_persistent;
00040     }
00041 
00042     char
00043     LifespanStrategyPersistent::key_type (void) const
00044     {
00045       return 'P';
00046     }
00047 
00048     CORBA::Boolean
00049     LifespanStrategyPersistent::is_persistent (void) const
00050     {
00051       return true;
00052     }
00053 
00054     void
00055     LifespanStrategyPersistent::create_key (
00056       CORBA::Octet *buffer,
00057       CORBA::ULong& starting_at)
00058     {
00059       // Copy the persistence byte.
00060       buffer[starting_at] = static_cast<CORBA::Octet> (this->key_type ());
00061       starting_at += this->key_type_length ();
00062     }
00063 
00064     CORBA::ULong
00065     LifespanStrategyPersistent::key_length () const
00066     {
00067       return this->key_type_length ();
00068     }
00069 
00070     void
00071     LifespanStrategyPersistent::notify_startup (ACE_ENV_SINGLE_ARG_DECL)
00072     {
00073       if (this->use_imr_)
00074         {
00075           // The user specified that the ImR should be used.
00076           ImR_Client_Adapter *adapter =
00077             ACE_Dynamic_Service<ImR_Client_Adapter>::instance (
00078               TAO_Root_POA::imr_client_adapter_name ()
00079             );
00080 
00081 #if !defined (TAO_AS_STATIC_LIBS)
00082           // In case we build shared, try to load the ImR Client library, in a
00083           // static build we just can't do this, so don't try it, lower layers
00084           // output an error then.
00085           if (adapter == 0)
00086             {
00087               ACE_Service_Config::process_directive (
00088                 ACE_DYNAMIC_SERVICE_DIRECTIVE(
00089                   "ImR_Client_Adapter", "TAO_ImR_Client",
00090                   "_make_ImR_Client_Adapter_Impl", ""));
00091 
00092               adapter =
00093                 ACE_Dynamic_Service<ImR_Client_Adapter>::instance (
00094                   TAO_Root_POA::imr_client_adapter_name ());
00095             }
00096 #endif /* !TAO_AS_STATIC_LIBS */
00097 
00098           if (adapter != 0)
00099             {
00100               adapter->imr_notify_startup (this->poa_ ACE_ENV_ARG_PARAMETER);
00101               ACE_CHECK;
00102             }
00103           else
00104             {
00105               // When we don't have a ImR_Client adapter, but the user
00106               // has specified that the ImR has to be used we have an
00107               // error situation which has to be reported.
00108               ACE_ERROR ((LM_ERROR,
00109                           ACE_TEXT ("(%P|%t) ERROR: No ImR_Client library ")
00110                           ACE_TEXT ("available but use IMR has been specified.\n")));
00111 
00112               ACE_THROW (CORBA::INTERNAL ());
00113             }
00114         }
00115     }
00116 
00117     void
00118     LifespanStrategyPersistent::notify_shutdown (ACE_ENV_SINGLE_ARG_DECL)
00119     {
00120       ImR_Client_Adapter *adapter =
00121         ACE_Dynamic_Service<ImR_Client_Adapter>::instance (
00122           TAO_Root_POA::imr_client_adapter_name ()
00123         );
00124 
00125       if (adapter != 0)
00126         {
00127           adapter->imr_notify_shutdown (this->poa_ ACE_ENV_ARG_PARAMETER);
00128           ACE_CHECK;
00129         }
00130     }
00131 
00132     LifespanStrategyPersistent::LifespanStrategyPersistent() :
00133       use_imr_ (true)
00134     {
00135     }
00136 
00137     void
00138     LifespanStrategyPersistent::check_state (ACE_ENV_SINGLE_ARG_DECL)
00139     {
00140       this->poa_->tao_poa_manager().check_state (ACE_ENV_SINGLE_ARG_PARAMETER);
00141       ACE_CHECK;
00142     }
00143 
00144     ::PortableServer::LifespanPolicyValue
00145     LifespanStrategyPersistent::type() const
00146     {
00147       return ::PortableServer::PERSISTENT;
00148     }
00149 
00150     bool
00151     LifespanStrategyPersistent::use_imr () const
00152     {
00153       return use_imr_;
00154     }
00155   } /* namespace Portable_Server */
00156 } /* namespace TAO */
00157 
00158 
00159 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 12:40:38 2006 for TAO_PortableServer by doxygen 1.3.6