00001 // $Id: CSD_Strategy_Base.cpp 81882 2008-06-10 14:59:20Z johnc $ 00002 00003 #include "tao/CSD_Framework/CSD_Strategy_Base.h" 00004 #include "tao/CSD_Framework/CSD_POA.h" 00005 #include "tao/CSD_Framework/CSD_Strategy_Proxy.h" 00006 #include "tao/PortableServer/Root_POA.h" 00007 #include "tao/PortableServer/POAManager.h" 00008 #include "tao/PortableServer/Servant_Base.h" 00009 #include "tao/TAO_Server_Request.h" 00010 00011 ACE_RCSID (CSD_Framework, 00012 CSD_Strategy_Base, 00013 "$Id: CSD_Strategy_Base.cpp 81882 2008-06-10 14:59:20Z johnc $") 00014 00015 #if !defined (__ACE_INLINE__) 00016 # include "tao/CSD_Framework/CSD_Strategy_Base.inl" 00017 #endif /* ! __ACE_INLINE__ */ 00018 00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00020 00021 TAO::CSD::Strategy_Base::~Strategy_Base() 00022 { 00023 } 00024 00025 CORBA::Boolean 00026 TAO::CSD::Strategy_Base::apply_to (PortableServer::POA_ptr poa) 00027 { 00028 if (CORBA::is_nil(poa)) 00029 { 00030 if (TAO_debug_level > 0) 00031 ACE_ERROR((LM_ERROR, 00032 ACE_TEXT("(%P|%t) CSD Strategy cannot ") 00033 ACE_TEXT("be applied to a nil POA.\n"))); 00034 return false; 00035 } 00036 00037 if (!CORBA::is_nil(this->poa_.in())) 00038 { 00039 if (TAO_debug_level > 0) 00040 ACE_ERROR((LM_ERROR, 00041 ACE_TEXT("(%P|%t) CSD Strategy already ") 00042 ACE_TEXT("applied to a POA.\n"))); 00043 return false; 00044 } 00045 00046 // The POA is a local interface (IDL terminology), and thus we know that 00047 // we can downcast the POA_ptr to its (TAO) implementation type. 00048 TAO_CSD_POA* poa_impl = dynamic_cast<TAO_CSD_POA*>(poa); 00049 00050 if (poa_impl == 0) 00051 { 00052 if (TAO_debug_level > 0) 00053 ACE_ERROR((LM_ERROR, 00054 ACE_TEXT("(%P|%t) CSD Strategy cannot ") 00055 ACE_TEXT("be applied to a non CSD POA.\n"))); 00056 return false; 00057 } 00058 00059 // We need to check to see if the POA is already "active". If this is 00060 // the case, then we need to handle the poa_activated_event() right now. 00061 // If the POA is not already "active", then we can just wait until it 00062 // does get activated, and we (the strategy) will be informed of the 00063 // poa_activated_event() at that time. 00064 if (poa_impl->tao_poa_manager().get_state() == 00065 PortableServer::POAManager::ACTIVE) 00066 { 00067 // The POA is already "active" (since its POAManager is active). 00068 // We need to "raise" the poa_activated_event() now. Otherwise, 00069 // the event will be raised when the POAManager does become active. 00070 if (!this->poa_activated_event( poa_impl->orb_core() )) 00071 { 00072 // An error has been already been reported to the log with 00073 // the detailed reason for the failure to handle the event. 00074 return false; 00075 } 00076 } 00077 00078 // Set the CSD Strategy_Base on the strategy proxy object owned by the POA. 00079 bool strategy_set = false; 00080 try 00081 { 00082 poa_impl->set_csd_strategy (this); 00083 strategy_set = true; 00084 } 00085 catch (const ::CORBA::Exception&) 00086 { 00087 } 00088 00089 if (! strategy_set) 00090 { 00091 // We need to make sure that we raise a poa_deactivated_event() if 00092 // we earlier raised a poa_activated_event(). 00093 this->poa_deactivated_event(); 00094 00095 // An error has been already been reported to the log with 00096 // the detailed reason why the proxy will not accept the 00097 // custom strategy. 00098 return false; 00099 } 00100 00101 // Save a duplicate of the poa into our data member. 00102 this->poa_ = PortableServer::POA::_duplicate (poa); 00103 00104 // Success 00105 return true; 00106 } 00107 00108 00109 void 00110 TAO::CSD::Strategy_Base::servant_activated_event_i 00111 (PortableServer::Servant , 00112 const PortableServer::ObjectId&) 00113 { 00114 // do nothing. 00115 } 00116 00117 00118 void 00119 TAO::CSD::Strategy_Base::servant_deactivated_event_i 00120 (PortableServer::Servant, 00121 const PortableServer::ObjectId&) 00122 { 00123 // do nothing. 00124 } 00125 00126 TAO_END_VERSIONED_NAMESPACE_DECL