Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PortableServer / Servant_Upcall.h
blob1f28b6d106e25955a79c938322464b43871f74ae
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Servant_Upcall.h
7 * @author Irfan Pyarali
8 */
9 //=============================================================================
11 #ifndef TAO_SERVANT_UPCALL_H
12 #define TAO_SERVANT_UPCALL_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/POA_Current_Impl.h"
24 #if defined(_MSC_VER)
25 #pragma warning(push)
26 #pragma warning(disable:4250)
27 #endif /* _MSC_VER */
29 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
31 // Forward declaration
32 class TAO_Root_POA;
33 class TAO_ServerRequest;
34 class TAO_Object_Adapter;
35 class TAO_RT_Collocation_Resolver;
36 struct TAO_Active_Object_Map_Entry;
38 namespace CORBA
40 class Object;
41 typedef Object *Object_ptr;
42 typedef TAO_Pseudo_Var_T<Object> Object_var;
43 typedef TAO_Pseudo_Out_T<Object> Object_out;
46 namespace TAO
48 namespace Portable_Server
50 /**
51 * @class Servant_Upcall
53 * @brief This class finds out the POA and the servant to perform an
54 * upcall. It can only be instantiated without the object
55 * adapter's lock held. For each upcall a new instance of this
56 * class is created.
58 class TAO_PortableServer_Export Servant_Upcall
60 public:
61 friend class ::TAO_RT_Collocation_Resolver;
63 /**
64 * @class Pre_Invoke_State
66 * @brief This struct keeps track of state related to pre- and
67 * post-invoke operations.
69 class Pre_Invoke_State
71 public:
72 /// Constructor.
73 Pre_Invoke_State ();
75 enum State
77 NO_ACTION_REQUIRED,
78 PRIORITY_RESET_REQUIRED
81 /// Indicates whether the priority of the thread needs to be
82 /// reset back to its original value.
83 State state_;
85 /// Original native priority of the thread.
86 CORBA::Short original_native_priority_;
88 /// Original CORBA priority of the thread.
89 CORBA::Short original_CORBA_priority_;
92 /// Constructor.
93 explicit Servant_Upcall (TAO_ORB_Core *orb_core);
95 /// Destructor.
96 ~Servant_Upcall ();
98 /// Locate POA and servant.
99 int prepare_for_upcall (const TAO::ObjectKey &key,
100 const char *operation,
101 CORBA::Object_out forward_to);
103 /// Helper.
104 int prepare_for_upcall_i (const TAO::ObjectKey &key,
105 const char *operation,
106 CORBA::Object_out forward_to,
107 bool &wait_occurred_restart_call);
109 /// Run pre_invoke for a remote request.
110 void pre_invoke_remote_request (TAO_ServerRequest &req);
112 /// Run pre_invoke for a collocated request.
113 void pre_invoke_collocated_request ();
115 /// Run post_invoke for a request.
116 void post_invoke ();
118 /// Locate POA.
119 ::TAO_Root_POA *lookup_POA (const TAO::ObjectKey &key);
121 /// POA accessor.
122 ::TAO_Root_POA &poa () const;
124 /// Object Adapter accessor.
125 TAO_Object_Adapter &object_adapter () const;
127 /// System ID accessor.
128 const PortableServer::ObjectId &id () const;
130 /// User ID accessors. This is the same value returned by
131 /// PortableServer::Current::get_object_id().
132 void user_id (const PortableServer::ObjectId *);
133 const PortableServer::ObjectId &user_id () const;
135 /// Servant accessor.
136 PortableServer::Servant servant () const;
138 #if (TAO_HAS_MINIMUM_POA == 0)
140 /// Get the Servant Locator's cookie
141 void* locator_cookie () const;
143 /// Set the Servant Locator's cookie
144 void locator_cookie (void* cookie);
146 /// Get the operation name.
147 const char *operation () const;
149 /// Set the operation name.
150 void operation (const char *);
152 #endif /* TAO_HAS_MINIMUM_POA == 0 */
154 /// Set the active_object_map_entry.
155 void active_object_map_entry (TAO_Active_Object_Map_Entry *entry);
157 /// Get the active_object_map_entry.
158 TAO_Active_Object_Map_Entry *active_object_map_entry () const;
160 /// Get the priority for the current upcall.
161 CORBA::Short priority () const;
163 enum State
165 INITIAL_STAGE,
166 OBJECT_ADAPTER_LOCK_ACQUIRED,
167 POA_CURRENT_SETUP,
168 OBJECT_ADAPTER_LOCK_RELEASED,
169 SERVANT_LOCK_ACQUIRED
172 /// Get the state.
173 State state () const;
175 /// Set the state.
176 void state (State);
178 /// Increment the refcount
179 void increment_servant_refcount ();
181 protected:
182 void post_invoke_servant_cleanup ();
183 void single_threaded_poa_setup ();
184 void single_threaded_poa_cleanup ();
185 void servant_cleanup ();
186 void poa_cleanup ();
188 /// Clean-up / reset state of this Servant_Upcall object.
189 void upcall_cleanup ();
191 protected:
192 TAO_Object_Adapter *object_adapter_;
194 ::TAO_Root_POA *poa_;
196 PortableServer::Servant servant_;
198 State state_;
200 CORBA::Octet system_id_buf_[TAO_POA_OBJECT_ID_BUF_SIZE];
201 PortableServer::ObjectId system_id_;
203 const PortableServer::ObjectId *user_id_;
205 POA_Current_Impl current_context_;
207 #if (TAO_HAS_MINIMUM_POA == 0)
209 /// Servant Locator's cookie
210 void* cookie_;
212 /// Operation name for this current.
213 const char *operation_;
215 #endif /* TAO_HAS_MINIMUM_POA == 0 */
217 /// Pointer to the entry in the TAO_Active_Object_Map corresponding
218 /// to the servant for this request.
219 TAO_Active_Object_Map_Entry *active_object_map_entry_;
221 /// Preinvoke data for the upcall.
222 Pre_Invoke_State pre_invoke_state_;
224 private:
225 Servant_Upcall (const Servant_Upcall &);
226 void operator= (const Servant_Upcall &);
231 TAO_END_VERSIONED_NAMESPACE_DECL
233 #if defined(_MSC_VER)
234 #pragma warning(pop)
235 #endif /* _MSC_VER */
237 #if defined (__ACE_INLINE__)
238 # include "tao/PortableServer/Servant_Upcall.inl"
239 #endif /* __ACE_INLINE__ */
241 #include /**/ "ace/post.h"
243 #endif /* TAO_SERVANT_UPCALL_H */