00001
00002
00003 #include "tao/orbconf.h"
00004
00005 ACE_RCSID (PortableServer,
00006 Request_Processing,
00007 "$Id: RequestProcessingStrategyDefaultServant.cpp 76995 2007-02-11 12:51:42Z johnnyw $")
00008
00009 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00010
00011 #include "tao/ORB_Constants.h"
00012 #include "tao/TSS_Resources.h"
00013 #include "tao/PortableServer/RequestProcessingStrategyDefaultServant.h"
00014 #include "tao/PortableServer/Non_Servant_Upcall.h"
00015 #include "tao/PortableServer/Root_POA.h"
00016 #include "tao/PortableServer/ServantManagerC.h"
00017 #include "tao/PortableServer/Servant_Base.h"
00018 #include "tao/PortableServer/POA_Current_Impl.h"
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 namespace TAO
00023 {
00024 namespace Portable_Server
00025 {
00026 RequestProcessingStrategyDefaultServant::RequestProcessingStrategyDefaultServant (void)
00027 : default_servant_ (0)
00028 {
00029 }
00030
00031 void
00032 RequestProcessingStrategyDefaultServant::strategy_cleanup(void)
00033 {
00034 this->default_servant_ = 0;
00035 }
00036
00037 PortableServer::ServantManager_ptr
00038 RequestProcessingStrategyDefaultServant::get_servant_manager (void)
00039 {
00040 throw PortableServer::POA::WrongPolicy ();
00041 }
00042
00043 void
00044 RequestProcessingStrategyDefaultServant::set_servant_manager (
00045 PortableServer::ServantManager_ptr )
00046 {
00047 throw PortableServer::POA::WrongPolicy ();
00048 }
00049
00050 PortableServer::Servant
00051 RequestProcessingStrategyDefaultServant::get_servant (void)
00052 {
00053
00054
00055 return this->default_servant_.in ();
00056 }
00057
00058 void
00059 RequestProcessingStrategyDefaultServant::set_servant (
00060 PortableServer::Servant servant
00061 )
00062 {
00063
00064
00065
00066 this->default_servant_ = servant;
00067
00068
00069
00070
00071
00072 if (servant != 0)
00073 {
00074
00075
00076
00077
00078
00079
00080
00081
00082 Non_Servant_Upcall non_servant_upcall (*this->poa_);
00083 ACE_UNUSED_ARG (non_servant_upcall);
00084
00085 servant->_add_ref ();
00086 }
00087 }
00088
00089 TAO_SERVANT_LOCATION
00090 RequestProcessingStrategyDefaultServant::locate_servant (
00091 const PortableServer::ObjectId & system_id,
00092 PortableServer::Servant & servant
00093 )
00094 {
00095 TAO_SERVANT_LOCATION location = TAO_SERVANT_NOT_FOUND;
00096
00097 location = this->poa_->servant_present (system_id, servant);
00098
00099 if (location == TAO_SERVANT_NOT_FOUND)
00100 {
00101 if (this->default_servant_.in () != 0)
00102 {
00103 location = TAO_DEFAULT_SERVANT;
00104 }
00105 }
00106
00107 return location;
00108 }
00109
00110 PortableServer::Servant
00111 RequestProcessingStrategyDefaultServant::locate_servant (
00112 const char * ,
00113 const PortableServer::ObjectId & system_id,
00114 TAO::Portable_Server::Servant_Upcall &servant_upcall,
00115 TAO::Portable_Server::POA_Current_Impl &poa_current_impl,
00116 bool &
00117 )
00118 {
00119 PortableServer::Servant servant = 0;
00120
00121 servant = this->poa_->find_servant (system_id,
00122 servant_upcall,
00123 poa_current_impl);
00124
00125 if (servant == 0)
00126 {
00127
00128
00129
00130
00131
00132 PortableServer::Servant default_servant = this->default_servant_.in ();
00133 if (default_servant == 0)
00134 {
00135 throw ::CORBA::OBJ_ADAPTER (
00136 CORBA::OMGVMCID | 3,
00137 CORBA::COMPLETED_NO);
00138 }
00139 else
00140 {
00141
00142 servant = default_servant;
00143 }
00144 }
00145
00146 return servant;
00147 }
00148
00149 PortableServer::Servant
00150 RequestProcessingStrategyDefaultServant::system_id_to_servant (
00151 const PortableServer::ObjectId &system_id)
00152 {
00153 PortableServer::Servant servant = this->default_servant_.in ();
00154
00155 if (servant == 0)
00156 {
00157 servant = this->poa_->find_servant (system_id);
00158 }
00159
00160 return servant;
00161 }
00162
00163 PortableServer::Servant
00164 RequestProcessingStrategyDefaultServant::id_to_servant (
00165 const PortableServer::ObjectId & )
00166 {
00167 PortableServer::Servant servant = this->default_servant_.in ();
00168
00169 if (servant == 0)
00170 {
00171
00172
00173
00174
00175
00176 throw PortableServer::POA::ObjectNotActive ();
00177 }
00178
00179 return servant;
00180 }
00181
00182 void
00183 RequestProcessingStrategyDefaultServant::cleanup_servant (
00184 PortableServer::Servant servant,
00185 const PortableServer::ObjectId &user_id
00186 )
00187 {
00188 if (servant)
00189 {
00190
00191 Non_Servant_Upcall non_servant_upcall (*this->poa_);
00192 ACE_UNUSED_ARG (non_servant_upcall);
00193
00194 servant->_remove_ref ();
00195 }
00196
00197
00198
00199
00200 if (this->poa_->unbind_using_user_id (user_id) != 0)
00201 {
00202 throw ::CORBA::OBJ_ADAPTER ();
00203 }
00204 }
00205
00206 void
00207 RequestProcessingStrategyDefaultServant::etherealize_objects (
00208 CORBA::Boolean )
00209 {
00210 }
00211
00212 PortableServer::ObjectId *
00213 RequestProcessingStrategyDefaultServant::servant_to_id (
00214 PortableServer::Servant servant
00215 )
00216 {
00217 PortableServer::Servant default_servant = this->default_servant_.in ();
00218
00219 if (default_servant != 0 &&
00220 default_servant == servant)
00221 {
00222
00223
00224 TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
00225 static_cast <TAO::Portable_Server::POA_Current_Impl *>
00226 (TAO_TSS_Resources::instance ()->poa_current_impl_);
00227
00228
00229 if (poa_current_impl != 0 &&
00230 servant == poa_current_impl->servant ())
00231 {
00232 return poa_current_impl->get_object_id ();
00233 }
00234 }
00235
00236 return this->poa_->servant_to_user_id (servant);
00237 }
00238
00239 void
00240 RequestProcessingStrategyDefaultServant::post_invoke_servant_cleanup(
00241 const PortableServer::ObjectId &,
00242 const TAO::Portable_Server::Servant_Upcall &)
00243 {
00244 }
00245
00246 ::PortableServer::RequestProcessingPolicyValue
00247 RequestProcessingStrategyDefaultServant::type() const
00248 {
00249 return ::PortableServer::USE_DEFAULT_SERVANT;
00250 }
00251 }
00252 }
00253
00254 TAO_END_VERSIONED_NAMESPACE_DECL
00255
00256 #endif
00257