Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PortableServer / ServantRetentionStrategyNonRetain.cpp
blob7fd93860d127b429d30b415fe14d7bc0d9de2fdf
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file ServantRetentionStrategyNonRetain.cpp
6 */
7 //=============================================================================
9 #include "tao/PortableServer/ServantRetentionStrategyNonRetain.h"
10 #include "tao/PortableServer/Non_Servant_Upcall.h"
11 #include "tao/PortableServer/Servant_Upcall.h"
12 #include "tao/PortableServer/POA_Current_Impl.h"
13 #include "tao/PortableServer/Root_POA.h"
14 #include "tao/PortableServer/Servant_Base.h"
15 #include "tao/debug.h"
17 #include "ace/OS_NS_sys_time.h"
18 #include "ace/Time_Value.h"
19 #include "ace/OS_NS_sys_time.h"
21 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
23 namespace TAO
25 namespace Portable_Server
27 void
28 ServantRetentionStrategyNonRetain::strategy_init (TAO_Root_POA *poa)
30 poa_ = poa;
33 void
34 ServantRetentionStrategyNonRetain::strategy_cleanup ()
36 poa_ = nullptr;
39 void
40 ServantRetentionStrategyNonRetain::deactivate_object (
41 const PortableServer::ObjectId &/*id*/)
43 // When using Non_Retain we don't have an active object map and we just
44 // can't deactivate any object
45 throw PortableServer::POA::WrongPolicy ();
48 PortableServer::Servant
49 ServantRetentionStrategyNonRetain::find_servant (
50 const PortableServer::ObjectId &/*system_id*/)
52 throw PortableServer::POA::WrongPolicy ();
55 PortableServer::ObjectId *
56 ServantRetentionStrategyNonRetain::system_id_to_object_id (
57 const PortableServer::ObjectId &system_id)
59 // The system id is the id (and no conversion/transformation is
60 // needed).
61 PortableServer::ObjectId *id = 0;
62 ACE_NEW_THROW_EX (id,
63 PortableServer::ObjectId (system_id),
64 CORBA::NO_MEMORY ());
66 return id;
69 PortableServer::Servant
70 ServantRetentionStrategyNonRetain::user_id_to_servant (
71 const PortableServer::ObjectId &/*id*/)
73 throw PortableServer::POA::WrongPolicy ();
76 CORBA::Object_ptr
77 ServantRetentionStrategyNonRetain::id_to_reference (
78 const PortableServer::ObjectId &/*id*/,
79 bool /*indirect*/)
81 throw PortableServer::POA::WrongPolicy ();
84 TAO_Servant_Location
85 ServantRetentionStrategyNonRetain::servant_present (
86 const PortableServer::ObjectId &/*system_id*/,
87 PortableServer::Servant &/*servant*/)
89 return TAO_Servant_Location::Not_Found;
92 PortableServer::Servant
93 ServantRetentionStrategyNonRetain::find_servant (
94 const PortableServer::ObjectId &system_id,
95 TAO::Portable_Server::Servant_Upcall &servant_upcall,
96 TAO::Portable_Server::POA_Current_Impl &poa_current_impl)
98 // We have the NON_RETAIN policy, user id is the system id.
100 // Smartly copy all the data; <poa_current_impl.object_id_> does
101 // not own the data.
102 poa_current_impl.replace_object_id (system_id);
104 servant_upcall.user_id (&system_id);
106 return 0;
110 ServantRetentionStrategyNonRetain::find_servant_priority (
111 const PortableServer::ObjectId &/*system_id*/,
112 CORBA::Short &/*priority*/)
114 return -1;
118 ServantRetentionStrategyNonRetain::is_servant_in_map (
119 PortableServer::Servant /*servant*/,
120 bool &/*wait_occurred_restart_call*/)
122 return 0;
125 CORBA::ULong
126 ServantRetentionStrategyNonRetain::waiting_servant_deactivation () const
128 return 0;
131 void
132 ServantRetentionStrategyNonRetain::deactivate_all_objects ()
136 PortableServer::ObjectId *
137 ServantRetentionStrategyNonRetain::servant_to_user_id (
138 PortableServer::Servant /*servant*/)
140 throw PortableServer::POA::WrongPolicy ();
143 CORBA::Object_ptr
144 ServantRetentionStrategyNonRetain::servant_to_reference (
145 PortableServer::Servant /*servant*/)
147 throw PortableServer::POA::WrongPolicy ();
150 PortableServer::ObjectId *
151 ServantRetentionStrategyNonRetain::activate_object (
152 PortableServer::Servant /*servant*/,
153 CORBA::Short /*priority*/,
154 bool &/*wait_occurred_restart_call*/)
156 throw PortableServer::POA::WrongPolicy ();
159 void
160 ServantRetentionStrategyNonRetain::activate_object_with_id (
161 const PortableServer::ObjectId &/*id*/,
162 PortableServer::Servant /*servant*/,
163 CORBA::Short /*priority*/,
164 bool &/*wait_occurred_restart_call*/)
166 throw PortableServer::POA::WrongPolicy ();
169 CORBA::Object_ptr
170 ServantRetentionStrategyNonRetain::create_reference (
171 const char *intf,
172 CORBA::Short priority)
174 // This operation creates an object reference that encapsulates a
175 // POA-generated Object Id value and the specified interface
176 // repository id. This operation does not cause an activation to
177 // take place. The resulting reference may be passed to clients, so
178 // that subsequent requests on those references will cause the
179 // appropriate servant manager to be invoked, if one is
180 // available. The generated Object Id value may be obtained by
181 // invoking POA::reference_to_id with the created reference.
183 PortableServer::ObjectId_var system_id;
184 PortableServer::ObjectId user_id;
186 // Otherwise, it is the NON_RETAIN policy. Therefore, any ol'
187 // object id will do (even an empty one). However, to make an
188 // object id useful for discriminating objects in applications
189 // use a simple id of a counter and a time stamp. The use of a
190 // counter by itself is not sufficient for uniqueness over time
191 // and a timestamp isn't sufficient since multiple IDs may be
192 // requested within the same time unit.
194 PortableServer::ObjectId *sys_id = 0;
195 ACE_NEW_THROW_EX (sys_id,
196 PortableServer::ObjectId (8),
197 CORBA::NO_MEMORY ());
199 sys_id->length(8);
201 long count = this->sys_id_count_++;
202 ACE_Time_Value now = ACE_OS::gettimeofday();
204 ACE_UINT32 *id_ptr = reinterpret_cast<ACE_UINT32 *>(sys_id->get_buffer());
206 *(id_ptr++) = count;
207 *id_ptr = static_cast<ACE_UINT32>(now.sec());
209 system_id = sys_id;
211 // User id is the same as system id.
212 user_id = system_id.in ();
214 // Remember params for potentially invoking <key_to_object> later.
215 this->poa_->key_to_object_params_.set (system_id,
216 intf,
219 priority,
220 true);
222 return this->poa_->invoke_key_to_object_helper_i (intf, user_id);
225 #if !defined (CORBA_E_MICRO)
226 CORBA::Object_ptr
227 ServantRetentionStrategyNonRetain::create_reference_with_id (
228 const PortableServer::ObjectId &oid,
229 const char *intf,
230 CORBA::Short priority)
232 // This operation creates an object reference that encapsulates the
233 // specified Object Id and interface repository Id values. This
234 // operation does not cause an activation to take place. The
235 // resulting reference may be passed to clients, so that subsequent
236 // requests on those references will cause the object to be
237 // activated if necessary, or the default servant used, depending on
238 // the applicable policies.
240 PortableServer::Servant servant = 0;
241 PortableServer::ObjectId_var system_id;
243 // Otherwise, it is the NON_RETAIN policy. Therefore, user id
244 // is the same as system id.
245 PortableServer::ObjectId *sys_id = 0;
246 ACE_NEW_THROW_EX (sys_id,
247 PortableServer::ObjectId (oid),
248 CORBA::NO_MEMORY ());
250 system_id = sys_id;
252 // Remember params for potentially invoking <key_to_object> later.
253 this->poa_->key_to_object_params_.set (system_id,
254 intf,
255 servant,
257 priority,
258 true);
260 return this->poa_->invoke_key_to_object_helper_i (intf, oid);
262 #endif
265 ServantRetentionStrategyNonRetain::rebind_using_user_id_and_system_id (
266 PortableServer::Servant /*servant*/,
267 const PortableServer::ObjectId &/*user_id*/,
268 const PortableServer::ObjectId &/*system_id*/,
269 TAO::Portable_Server::Servant_Upcall &/*servant_upcall*/)
271 return -1;
274 CORBA::Boolean
275 ServantRetentionStrategyNonRetain::servant_has_remaining_activations (
276 PortableServer::Servant /*servant*/)
278 return false;
282 ServantRetentionStrategyNonRetain::unbind_using_user_id (
283 const PortableServer::ObjectId &/*user_id*/)
285 return 0;
288 ::PortableServer::ServantRetentionPolicyValue
289 ServantRetentionStrategyNonRetain::type() const
291 return ::PortableServer::NON_RETAIN;
294 TAO_Active_Object_Map *
295 ServantRetentionStrategyNonRetain::get_active_object_map() const
297 return 0;
302 TAO_END_VERSIONED_NAMESPACE_DECL