Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PortableServer / Object_Adapter.h
blob4f534d8471b11f0f96c4f6981677adddb2c88c0f
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Object_Adapter.h
7 * @author Irfan Pyarali
8 */
9 //=============================================================================
11 #ifndef TAO_OBJECT_ADAPTER_H
12 #define TAO_OBJECT_ADAPTER_H
14 #include /**/ "ace/pre.h"
16 #include "tao/PortableServer/portableserver_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "tao/PortableServer/Key_Adapters.h"
23 #include "tao/PortableServer/poa_macros.h"
24 #include "tao/PortableServer/Servant_Location.h"
25 #include "tao/PortableServer/Default_Policy_Validator.h"
26 #include "tao/PortableServer/POA_Policy_Set.h"
27 #include "tao/PortableServer/POAManagerC.h"
29 #include "tao/Adapter.h"
30 #include "tao/Adapter_Factory.h"
31 #include "tao/Server_Strategy_Factory.h"
32 #include "tao/LocalObject.h"
34 #include "ace/Reverse_Lock_T.h"
35 #include "ace/Condition_Thread_Mutex.h"
36 #include "ace/Map_T.h"
38 #include "tao/PortableServer/Servant_Location.h"
40 #if defined(_MSC_VER)
41 #pragma warning(push)
42 #pragma warning(disable:4250)
43 #endif /* _MSC_VER */
45 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
47 class TAO_Root_POA;
48 class TAO_POA_Manager;
49 class TAO_TSS_Resources;
50 class TAO_Transport;
51 class TAO_Servant_Dispatcher;
52 class TAO_POAManager_Factory;
54 namespace TAO
56 namespace Portable_Server
58 class Non_Servant_Upcall;
59 class Servant_Upcall;
60 class POA_Current_Impl;
61 class Temporary_Creation_Time;
65 /**
66 * @class TAO_Object_Adapter
68 * @brief Defines the Object Adapter abstraction.
70 * This class will be used as a facade for the POAs in a server
72 class TAO_PortableServer_Export TAO_Object_Adapter
73 : public TAO_Adapter
75 public:
76 friend class TAO_Root_POA;
78 typedef PortableServer::ObjectId poa_name;
79 typedef PortableServer::ObjectId_var poa_name_var;
80 typedef PortableServer::ObjectId_out poa_name_out;
82 /// Constructor.
83 TAO_Object_Adapter (const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters,
84 TAO_ORB_Core &orb_core);
86 /// Destructor.
87 ~TAO_Object_Adapter ();
89 int dispatch_servant (const TAO::ObjectKey &key,
90 TAO_ServerRequest &req,
91 CORBA::Object_out forward_to);
93 int locate_servant (const TAO::ObjectKey &key);
95 TAO_Servant_Location find_servant (const TAO::ObjectKey &key,
96 PortableServer::Servant &servant);
98 int find_poa (const poa_name &system_name,
99 CORBA::Boolean activate_it,
100 CORBA::Boolean root,
101 const TAO::Portable_Server::Temporary_Creation_Time &poa_creation_time,
102 TAO_Root_POA *&poa);
104 int bind_poa (const poa_name &folded_name,
105 TAO_Root_POA *poa,
106 poa_name_out system_name);
108 int unbind_poa (TAO_Root_POA *poa,
109 const poa_name &folded_name,
110 const poa_name &system_name);
112 int activate_poa (const poa_name &folded_name,
113 TAO_Root_POA *&poa);
115 ACE_Lock &lock ();
117 TAO_SYNCH_MUTEX &thread_lock ();
119 ACE_Reverse_Lock<ACE_Lock> &reverse_lock ();
121 /// Access the root poa.
122 TAO_Root_POA *root_poa () const;
124 /// Access to ORB Core.
125 TAO_ORB_Core &orb_core () const;
127 /// Wait for non-servant upcalls to complete.
128 void wait_for_non_servant_upcalls_to_complete ();
130 /// Non-exception throwing version.
131 void wait_for_non_servant_upcalls_to_complete_no_throw ();
133 static CORBA::ULong transient_poa_name_size ();
135 /// Return the validator.
136 TAO_Policy_Validator &validator ();
138 /// Return the set of default policies.
139 TAO_POA_Policy_Set &default_poa_policies ();
141 /// Set the servant dispatcher method. Ownership is transferred to
142 /// this Object Adapter. Note: This should only be called
143 /// at initialization.
144 void servant_dispatcher (TAO_Servant_Dispatcher *dispatcher);
146 /// Initialize the default set of POA policies.
147 void init_default_policies (TAO_POA_Policy_Set &policies);
149 // = The TAO_Adapter methods, please check tao/Adapter.h for the
150 // documentation
151 virtual void open ();
152 virtual void close (int wait_for_completion);
153 virtual void check_close (int wait_for_completion);
154 virtual int priority () const;
155 virtual int dispatch (TAO::ObjectKey &key,
156 TAO_ServerRequest &request,
157 CORBA::Object_out forward_to);
158 virtual const char *name () const;
159 virtual CORBA::Object_ptr root ();
160 virtual CORBA::Object_ptr create_collocated_object (TAO_Stub *,
161 const TAO_MProfile &);
163 virtual CORBA::Long initialize_collocated_object (TAO_Stub *);
165 protected:
166 int locate_servant_i (const TAO::ObjectKey &key);
168 TAO_Servant_Location find_servant_i (const TAO::ObjectKey &key,
169 PortableServer::Servant &servant);
171 void dispatch_servant_i (const TAO::ObjectKey &key,
172 TAO_ServerRequest &req,
173 void *context);
175 void locate_poa (const TAO::ObjectKey &key,
176 PortableServer::ObjectId &id,
177 TAO_Root_POA *&poa);
179 int find_transient_poa (const poa_name &system_name,
180 CORBA::Boolean root,
181 const TAO::Portable_Server::Temporary_Creation_Time &poa_creation_time,
182 TAO_Root_POA *&poa);
184 int find_persistent_poa (const poa_name &system_name, TAO_Root_POA *&poa);
186 int bind_transient_poa (TAO_Root_POA *poa, poa_name_out system_name);
188 int bind_persistent_poa (const poa_name &folded_name,
189 TAO_Root_POA *poa,
190 poa_name_out system_name);
192 int unbind_transient_poa (const poa_name &system_name);
194 int unbind_persistent_poa (const poa_name &folded_name,
195 const poa_name &system_name);
197 static ACE_Lock *create_lock (TAO_SYNCH_MUTEX &thread_lock);
199 virtual void do_dispatch (TAO_ServerRequest& req,
200 TAO::Portable_Server::Servant_Upcall& upcall);
202 public:
204 * @class Hint_Strategy
206 * @brief Base class for POA active hint strategy.
208 * This class also provides for common structures used by all
209 * the derived classes.
211 class TAO_PortableServer_Export Hint_Strategy
213 public:
214 virtual ~Hint_Strategy ();
216 virtual int find_persistent_poa (const poa_name &system_name,
217 TAO_Root_POA *&poa) = 0;
219 virtual int bind_persistent_poa (const poa_name &folded_name,
220 TAO_Root_POA *poa,
221 poa_name_out system_name) = 0;
223 virtual int unbind_persistent_poa (const poa_name &folded_name,
224 const poa_name &system_name) = 0;
226 void object_adapter (TAO_Object_Adapter *oa);
228 protected:
229 TAO_Object_Adapter *object_adapter_;
233 * @class Active_Hint_Strategy
235 * @brief This class uses active demux hint for POA active hint
236 * strategy.
238 * This class will append an active hint to the POA name,
239 * making the POA lookups fast and predictable.
241 class TAO_PortableServer_Export Active_Hint_Strategy : public Hint_Strategy
243 public:
244 Active_Hint_Strategy (CORBA::ULong map_size);
246 virtual ~Active_Hint_Strategy ();
248 virtual int find_persistent_poa (const poa_name &system_name,
249 TAO_Root_POA *&poa);
251 virtual int bind_persistent_poa (const poa_name &folded_name,
252 TAO_Root_POA *poa,
253 poa_name_out system_name);
255 virtual int unbind_persistent_poa (const poa_name &folded_name,
256 const poa_name &system_name);
258 protected:
259 typedef ACE_Active_Map_Manager_Adapter<
260 poa_name,
261 TAO_Root_POA *,
262 TAO_Preserve_Original_Key_Adapter> persistent_poa_system_map;
264 persistent_poa_system_map persistent_poa_system_map_;
267 friend class Active_Hint_Strategy;
270 * @class No_Hint_Strategy
272 * @brief This class doesn't use any hints for POA active hint
273 * strategy.
275 * This class will simply use the POA names as is. And since
276 * no hint is added, the IORs will be smaller.
278 class TAO_PortableServer_Export No_Hint_Strategy : public Hint_Strategy
280 public:
281 virtual ~No_Hint_Strategy ();
283 virtual int find_persistent_poa (const poa_name &system_name,
284 TAO_Root_POA *&poa);
286 virtual int bind_persistent_poa (const poa_name &folded_name,
287 TAO_Root_POA *poa,
288 poa_name_out system_name);
290 virtual int unbind_persistent_poa (const poa_name &folded_name,
291 const poa_name &system_name);
294 friend class No_Hint_Strategy;
296 protected:
297 Hint_Strategy *hint_strategy_;
299 /// Base class of the id map.
300 typedef ACE_Map<
301 poa_name,
302 TAO_Root_POA *> transient_poa_map;
304 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
305 /// Id hash map.
306 typedef ACE_Hash_Map_Manager_Ex_Adapter<
307 poa_name,
308 TAO_Root_POA *,
309 TAO_ObjectId_Hash,
310 ACE_Equal_To<poa_name>,
311 TAO_Incremental_Key_Generator> transient_poa_hash_map;
312 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
314 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
315 /// Id linear map.
316 typedef ACE_Map_Manager_Adapter<
317 poa_name,
318 TAO_Root_POA *,
319 TAO_Incremental_Key_Generator> transient_poa_linear_map;
320 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
322 /// Id active map.
323 typedef ACE_Active_Map_Manager_Adapter<
324 poa_name,
325 TAO_Root_POA *,
326 TAO_Ignore_Original_Key_Adapter> transient_poa_active_map;
328 /// Base class of the name map.
329 typedef ACE_Map<
330 poa_name,
331 TAO_Root_POA *> persistent_poa_name_map;
333 /// Id hash map.
334 typedef ACE_Hash_Map_Manager_Ex_Adapter<
335 poa_name,
336 TAO_Root_POA *,
337 TAO_ObjectId_Hash,
338 ACE_Equal_To<PortableServer::ObjectId>,
339 ACE_Noop_Key_Generator<poa_name> > persistent_poa_name_hash_map;
341 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
342 /// Id linear map.
343 typedef ACE_Map_Manager_Adapter<
344 poa_name,
345 TAO_Root_POA *,
346 ACE_Noop_Key_Generator<poa_name> > persistent_poa_name_linear_map;
347 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
349 /// Strategy for dispatching a request to a servant.
350 TAO_Servant_Dispatcher *servant_dispatcher_;
352 /// Persistent POA map
353 persistent_poa_name_map *persistent_poa_name_map_;
355 /// Transient POA map
356 transient_poa_map *transient_poa_map_;
358 protected:
359 static CORBA::ULong transient_poa_name_size_;
361 static void set_transient_poa_name_size (const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters);
363 TAO_ORB_Core &orb_core_;
365 TAO_SYNCH_MUTEX thread_lock_;
367 ACE_Lock *lock_;
369 ACE_Reverse_Lock<ACE_Lock> reverse_lock_;
371 public:
373 * @class poa_name_iterator
375 * @brief Iterator for a folded poa name.
377 class poa_name_iterator
379 public:
380 /// Constructor.
381 poa_name_iterator (int begin,
382 CORBA::ULong size,
383 const CORBA::Octet *folded_buffer);
385 /// Comparison operators.
386 bool operator== (const poa_name_iterator &rhs) const;
387 bool operator!= (const poa_name_iterator &rhs) const;
389 /// Dereference operator.
390 ACE_CString operator* () const;
392 /// Prefix advance.
393 poa_name_iterator &operator++ ();
395 protected:
396 CORBA::ULong size_;
397 CORBA::ULong position_;
398 const CORBA::Octet *folded_buffer_;
399 CORBA::ULong last_separator_;
403 * @class iteratable_poa_name
405 * @brief This class allows iteration over a folded poa name.
407 class iteratable_poa_name
409 public:
410 typedef poa_name_iterator iterator;
412 iteratable_poa_name (const poa_name &folded_name);
414 iterator begin () const;
415 iterator end () const;
417 protected:
418 const poa_name &folded_name_;
421 friend class TAO::Portable_Server::Non_Servant_Upcall;
423 friend class TAO::Portable_Server::Servant_Upcall;
425 public:
426 /// Pointer to the non-servant upcall in progress. If no non-servant
427 /// upcall is in progress, this pointer is zero.
428 TAO::Portable_Server::Non_Servant_Upcall *non_servant_upcall_in_progress () const;
430 private:
431 /// Helper method to get collocated servant
432 TAO_ServantBase *get_collocated_servant (const TAO_MProfile &mp);
434 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
435 static void release_poa_manager_factory (TAO_POAManager_Factory *factory);
436 #endif
437 private:
438 /// Condition variable for waiting on non-servant upcalls to end.
439 TAO_SYNCH_CONDITION non_servant_upcall_condition_;
441 /// Pointer to the non-servant upcall in progress. If no non-servant
442 /// upcall is in progress, this pointer is zero.
443 TAO::Portable_Server::Non_Servant_Upcall *non_servant_upcall_in_progress_;
445 /// Current nesting level of non_servant_upcalls.
446 unsigned int non_servant_upcall_nesting_level_;
448 /// Id of thread making the non-servant upcall.
449 ACE_thread_t non_servant_upcall_thread_;
451 /// The Root POA
452 TAO_Root_POA *root_;
454 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
455 /// The POAManager factory.
456 TAO_POAManager_Factory *poa_manager_factory_;
457 #else
458 /// The POAManager object reference.
459 PortableServer::POAManager_var the_poa_manager_;
460 #endif
462 /// The default validator and the beginning of the chain of
463 /// policy validators.
464 TAO_POA_Default_Policy_Validator default_validator_;
466 /// Save a list of default policies that should be included in
467 /// every POA (unless overridden).
468 TAO_POA_Policy_Set default_poa_policies_;
471 TAO_END_VERSIONED_NAMESPACE_DECL
473 #if defined(_MSC_VER)
474 #pragma warning(pop)
475 #endif /* _MSC_VER */
477 #if defined (__ACE_INLINE__)
478 # include "tao/PortableServer/Object_Adapter.inl"
479 #endif /* __ACE_INLINE__ */
481 #include /**/ "ace/post.h"
483 #endif /* TAO_OBJECT_ADAPTER_H */