00001 // -*- C++ -*- 00002 00003 #include "tao/PortableServer/LifespanStrategyTransient.h" 00004 00005 ACE_RCSID (PortableServer, 00006 Lifespan_Strategy, 00007 "$Id: LifespanStrategyTransient.cpp 76569 2007-01-24 18:54:26Z johnnyw $") 00008 00009 #include "ace/OS_NS_sys_time.h" 00010 #include "ace/OS_NS_string.h" 00011 #include "tao/PortableServer/POAManager.h" 00012 #include "tao/PortableServer/Root_POA.h" 00013 #include "tao/ORB_Constants.h" 00014 #include "tao/PortableServer/Creation_Time.h" 00015 00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 namespace TAO 00019 { 00020 namespace Portable_Server 00021 { 00022 LifespanStrategyTransient::LifespanStrategyTransient () : 00023 creation_time_ (ACE_OS::gettimeofday ()) 00024 { 00025 } 00026 00027 void 00028 LifespanStrategyTransient::notify_startup (void) 00029 { 00030 } 00031 00032 void 00033 LifespanStrategyTransient::notify_shutdown (void) 00034 { 00035 } 00036 00037 CORBA::Boolean 00038 LifespanStrategyTransient::is_persistent (void) const 00039 { 00040 return false; 00041 } 00042 00043 bool 00044 LifespanStrategyTransient::validate (CORBA::Boolean is_persistent, 00045 const TAO::Portable_Server:: 00046 Temporary_Creation_Time 00047 &creation_time) const 00048 { 00049 return (!is_persistent && this->creation_time_ == creation_time); 00050 } 00051 00052 CORBA::ULong 00053 LifespanStrategyTransient::key_length (void) const 00054 { 00055 CORBA::ULong keylength = sizeof (char); 00056 00057 #if (POA_NO_TIMESTAMP == 0) 00058 // Calculate the space required for the timestamp. 00059 keylength += TAO::Portable_Server::Creation_Time::creation_time_length 00060 (); 00061 #endif /* POA_NO_TIMESTAMP */ 00062 00063 return keylength; 00064 } 00065 00066 void 00067 LifespanStrategyTransient::create_key (CORBA::Octet *buffer, 00068 CORBA::ULong &starting_at) 00069 { 00070 // Copy the persistence byte. 00071 buffer[starting_at] = (CORBA::Octet)this->key_type (); 00072 starting_at += this->key_type_length (); 00073 00074 #if (POA_NO_TIMESTAMP == 0) 00075 // Then copy the timestamp for transient POAs. 00076 ACE_OS::memcpy (&buffer[starting_at], 00077 this->creation_time_.creation_time (), 00078 TAO::Portable_Server::Creation_Time::creation_time_length 00079 ()); 00080 starting_at += TAO::Portable_Server::Creation_Time::creation_time_length 00081 (); 00082 #endif /* POA_NO_TIMESTAMP */ 00083 } 00084 00085 char 00086 LifespanStrategyTransient::key_type (void) const 00087 { 00088 return 'T'; 00089 } 00090 00091 void 00092 LifespanStrategyTransient::check_state (void) 00093 { 00094 if (this->poa_->tao_poa_manager ().get_state_i () == 00095 PortableServer::POAManager::INACTIVE) 00096 { 00097 throw ::CORBA::OBJECT_NOT_EXIST (CORBA::OMGVMCID | 4, CORBA::COMPLETED_NO); 00098 } 00099 else 00100 { 00101 this->poa_->tao_poa_manager ().check_state (); 00102 } 00103 } 00104 00105 bool 00106 LifespanStrategyTransient::use_imr () const 00107 { 00108 return false; 00109 } 00110 00111 ::PortableServer::LifespanPolicyValue 00112 LifespanStrategyTransient::type () const 00113 { 00114 return ::PortableServer::TRANSIENT; 00115 } 00116 } /* namespace Portable_Server */ 00117 } /* namespace TAO */ 00118 00119 TAO_END_VERSIONED_NAMESPACE_DECL