2 #include "tao/orbconf.h"
4 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
6 #include "tao/ORB_Constants.h"
7 #include "tao/TSS_Resources.h"
8 #include "tao/PortableServer/RequestProcessingStrategyDefaultServant.h"
9 #include "tao/PortableServer/Non_Servant_Upcall.h"
10 #include "tao/PortableServer/Root_POA.h"
11 #include "tao/PortableServer/ServantManagerC.h"
12 #include "tao/PortableServer/Servant_Base.h"
13 #include "tao/PortableServer/POA_Current_Impl.h"
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 namespace Portable_Server
22 RequestProcessingStrategyDefaultServant::strategy_cleanup()
24 this->default_servant_
= nullptr;
27 PortableServer::ServantManager_ptr
28 RequestProcessingStrategyDefaultServant::get_servant_manager ()
30 throw PortableServer::POA::WrongPolicy ();
34 RequestProcessingStrategyDefaultServant::set_servant_manager (
35 PortableServer::ServantManager_ptr
/*imgr*/)
37 throw PortableServer::POA::WrongPolicy ();
40 PortableServer::Servant
41 RequestProcessingStrategyDefaultServant::get_servant ()
43 // This operation returns the default servant associated with the
45 return this->default_servant_
.in ();
49 RequestProcessingStrategyDefaultServant::set_servant (
50 PortableServer::Servant servant
)
52 // This operation registers the specified servant with the POA as
53 // the default servant. This servant will be used for all requests
54 // for which no servant is found in the Active Object Map.
55 this->default_servant_
= servant
;
57 // The implementation of set_servant will invoke _add_ref at least
58 // once on the Servant argument before returning. When the POA no
59 // longer needs the Servant, it will invoke _remove_ref on it the
60 // same number of times.
63 // A recursive thread lock without using a recursive thread
64 // lock. Non_Servant_Upcall has a magic constructor and
65 // destructor. We unlock the Object_Adapter lock for the
66 // duration of the servant activator upcalls; reacquiring once
67 // the upcalls complete. Even though we are releasing the lock,
68 // other threads will not be able to make progress since
69 // <Object_Adapter::non_servant_upcall_in_progress_> has been
71 Non_Servant_Upcall
non_servant_upcall (*this->poa_
);
72 ACE_UNUSED_ARG (non_servant_upcall
);
79 RequestProcessingStrategyDefaultServant::locate_servant (
80 const PortableServer::ObjectId
& system_id
,
81 PortableServer::Servant
& servant
)
83 TAO_Servant_Location location
= TAO_Servant_Location::Not_Found
;
85 location
= this->poa_
->servant_present (system_id
, servant
);
87 if (location
== TAO_Servant_Location::Not_Found
)
89 if (this->default_servant_
.in ())
91 location
= TAO_Servant_Location::Default_Servant
;
98 PortableServer::Servant
99 RequestProcessingStrategyDefaultServant::locate_servant (
100 const char * /*operation*/,
101 const PortableServer::ObjectId
& system_id
,
102 TAO::Portable_Server::Servant_Upcall
&servant_upcall
,
103 TAO::Portable_Server::POA_Current_Impl
&poa_current_impl
,
104 bool & /*wait_occurred_restart_call*/)
106 PortableServer::Servant servant
= nullptr;
108 servant
= this->poa_
->find_servant (system_id
,
114 // If the POA has the USE_DEFAULT_SERVANT policy, a default servant
115 // has been associated with the POA so the POA will invoke the
116 // appropriate method on that servant. If no servant has been
117 // associated with the POA, the POA raises the OBJ_ADAPTER system
119 PortableServer::Servant default_servant
= this->default_servant_
.in ();
120 if (!default_servant
)
122 throw ::CORBA::OBJ_ADAPTER (
124 CORBA::COMPLETED_NO
);
129 servant
= default_servant
;
136 PortableServer::Servant
137 RequestProcessingStrategyDefaultServant::system_id_to_servant (
138 const PortableServer::ObjectId
&system_id
)
140 PortableServer::Servant servant
= this->default_servant_
.in ();
144 servant
= this->poa_
->find_servant (system_id
);
150 PortableServer::Servant
151 RequestProcessingStrategyDefaultServant::id_to_servant (
152 const PortableServer::ObjectId
& /*id*/)
154 PortableServer::Servant servant
= this->default_servant_
.in ();
159 * If using default servant request processing strategy but
160 * no default servant is available, we will raise the
161 * ObjectNotActive system exception.
163 throw PortableServer::POA::ObjectNotActive ();
170 RequestProcessingStrategyDefaultServant::cleanup_servant (
171 PortableServer::Servant servant
,
172 const PortableServer::ObjectId
&user_id
)
176 // ATTENTION: Trick locking here, see class header for details
177 Non_Servant_Upcall
non_servant_upcall (*this->poa_
);
178 ACE_UNUSED_ARG (non_servant_upcall
);
182 servant
->_remove_ref ();
186 // Ignore exceptions from servant cleanup.
190 // This operation causes the association of the Object Id specified
191 // by the oid parameter and its servant to be removed from the
192 // Active Object Map.
193 if (this->poa_
->unbind_using_user_id (user_id
) != 0)
195 throw ::CORBA::OBJ_ADAPTER ();
200 RequestProcessingStrategyDefaultServant::etherealize_objects (
201 CORBA::Boolean
/*etherealize_objects*/)
205 PortableServer::ObjectId
*
206 RequestProcessingStrategyDefaultServant::servant_to_id (
207 PortableServer::Servant servant
)
209 PortableServer::Servant default_servant
= this->default_servant_
.in ();
211 if (default_servant
!= 0 &&
212 default_servant
== servant
)
214 // If they are the same servant, then check if we are in an
216 TAO::Portable_Server::POA_Current_Impl
*poa_current_impl
=
217 static_cast <TAO::Portable_Server::POA_Current_Impl
*>
218 (TAO_TSS_Resources::instance ()->poa_current_impl_
);
219 // If we are in an upcall on the default servant, return the
220 // ObjectId associated with the current invocation.
221 if (poa_current_impl
!= 0 &&
222 servant
== poa_current_impl
->servant ())
224 return poa_current_impl
->get_object_id ();
228 return this->poa_
->servant_to_user_id (servant
);
232 RequestProcessingStrategyDefaultServant::post_invoke_servant_cleanup(
233 const PortableServer::ObjectId
&/*system_id*/,
234 const TAO::Portable_Server::Servant_Upcall
&/*servant_upcall*/)
240 TAO_END_VERSIONED_NAMESPACE_DECL
242 #endif /* TAO_HAS_MINIMUM_POA == 0 */