summaryrefslogtreecommitdiff
path: root/TAO/tao/PortableServer/Servant_Upcall.h
blob: 13a4cb096d1beb6be040bb35e9e1ca14c9019dd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Servant_Upcall.h
 *
 *  $Id$
 *
 *  @author Irfan Pyarali
 */
//=============================================================================

#ifndef TAO_SERVANT_UPCALL_H
#define TAO_SERVANT_UPCALL_H

#include /**/ "ace/pre.h"

#include "tao/PortableServer/portableserver_export.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/PortableServer/POA_Current_Impl.h"

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4250)
#endif /* _MSC_VER */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

// Forward declaration
class TAO_Root_POA;
class TAO_ServerRequest;
class TAO_Object_Adapter;
class TAO_RT_Collocation_Resolver;
struct TAO_Active_Object_Map_Entry;

namespace CORBA
{
  class Object;
  typedef Object *Object_ptr;
  typedef TAO_Pseudo_Var_T<Object> Object_var;
  typedef TAO_Pseudo_Out_T<Object> Object_out;
}

namespace TAO
{
  namespace Portable_Server
  {
    /**
     * @class Servant_Upcall
     *
     * @brief This class finds out the POA and the servant to perform an
     * upcall.  It can only be instantiated without the object
     * adapter's lock held. For each upcall a new instance of this
     * class is created.
     */
    class TAO_PortableServer_Export Servant_Upcall
    {
    public:
      friend class ::TAO_RT_Collocation_Resolver;

      /**
       * @class Pre_Invoke_State
       *
       * @brief This struct keeps track of state related to pre- and
       * post-invoke operations.
       */
      class Pre_Invoke_State
      {
      public:
        /// Constructor.
        Pre_Invoke_State (void);

        enum State
        {
          NO_ACTION_REQUIRED,
          PRIORITY_RESET_REQUIRED
        };

        /// Indicates whether the priority of the thread needs to be
        /// reset back to its original value.
        State state_;

        /// Original native priority of the thread.
        CORBA::Short original_native_priority_;

        /// Original CORBA priority of the thread.
        CORBA::Short original_CORBA_priority_;
      };

      /// Constructor.
      explicit Servant_Upcall (TAO_ORB_Core *orb_core);

      /// Destructor.
      ~Servant_Upcall (void);

      /// Locate POA and servant.
      int prepare_for_upcall (const TAO::ObjectKey &key,
                              const char *operation,
                              CORBA::Object_out forward_to
                              );

      /// Helper.
      int prepare_for_upcall_i (const TAO::ObjectKey &key,
                                const char *operation,
                                CORBA::Object_out forward_to,
                                bool &wait_occurred_restart_call
                                );

      /// Run pre_invoke for a remote request.
      void pre_invoke_remote_request (TAO_ServerRequest &req
                                     );

      /// Run pre_invoke for a collocated request.
      void pre_invoke_collocated_request (void);

      /// Run post_invoke for a request.
      void post_invoke (void);

      /// Locate POA.
      ::TAO_Root_POA *lookup_POA (const TAO::ObjectKey &key
                                 );

      /// POA accessor.
      ::TAO_Root_POA &poa (void) const;

      /// Object Adapter accessor.
      TAO_Object_Adapter &object_adapter (void) const;

      /// System ID accessor.
      const PortableServer::ObjectId &id (void) const;

      /// User ID accessors.  This is the same value returned by
      /// PortableServer::Current::get_object_id().
      void user_id (const PortableServer::ObjectId *);
      const PortableServer::ObjectId &user_id (void) const;

      /// Servant accessor.
      PortableServer::Servant servant (void) const;

  #if (TAO_HAS_MINIMUM_POA == 0)

      /// Get the Servant Locator's cookie
      void* locator_cookie (void) const;

      /// Set the Servant Locator's cookie
      void locator_cookie (void* cookie);

      /// Get the operation name.
      const char *operation (void) const;

      /// Set the operation name.
      void operation (const char *);

  #endif /* TAO_HAS_MINIMUM_POA == 0 */

      /// Set the active_object_map_entry.
      void active_object_map_entry (TAO_Active_Object_Map_Entry *entry);

      /// Get the active_object_map_entry.
      TAO_Active_Object_Map_Entry *active_object_map_entry (void) const;

      /// Get the priority for the current upcall.
      CORBA::Short priority (void) const;

      enum State
      {
        INITIAL_STAGE,
        OBJECT_ADAPTER_LOCK_ACQUIRED,
        POA_CURRENT_SETUP,
        OBJECT_ADAPTER_LOCK_RELEASED,
        SERVANT_LOCK_ACQUIRED
      };

      /// Get the state.
      State state (void) const;

      /// Set the state.
      void state (State);

      /// Increment the refcount
      void increment_servant_refcount (void);

    protected:

      void post_invoke_servant_cleanup (void);
      void single_threaded_poa_setup (void);
      void single_threaded_poa_cleanup (void);
      void servant_cleanup (void);
      void poa_cleanup (void);

      /// Clean-up / reset state of this Servant_Upcall object.
      void upcall_cleanup (void);

    protected:

      TAO_Object_Adapter *object_adapter_;

      ::TAO_Root_POA *poa_;

      PortableServer::Servant servant_;

      State state_;

      CORBA::Octet system_id_buf_[TAO_POA_OBJECT_ID_BUF_SIZE];
      PortableServer::ObjectId system_id_;

      const PortableServer::ObjectId *user_id_;

      POA_Current_Impl current_context_;

  #if (TAO_HAS_MINIMUM_POA == 0)

      /// Servant Locator's cookie
      void* cookie_;

      /// Operation name for this current.
      const char *operation_;

  #endif /* TAO_HAS_MINIMUM_POA == 0 */

      /// Pointer to the entry in the TAO_Active_Object_Map corresponding
      /// to the servant for this request.
      TAO_Active_Object_Map_Entry *active_object_map_entry_;

      /// Preinvoke data for the upcall.
      Pre_Invoke_State pre_invoke_state_;

    private:
      Servant_Upcall (const Servant_Upcall &);
      void operator= (const Servant_Upcall &);
    };
  }
}

TAO_END_VERSIONED_NAMESPACE_DECL

#if defined(_MSC_VER)
#pragma warning(pop)
#endif /* _MSC_VER */

#if defined (__ACE_INLINE__)
# include "tao/PortableServer/Servant_Upcall.inl"
#endif /* __ACE_INLINE__ */

#include /**/ "ace/post.h"

#endif /* TAO_SERVANT_UPCALL_H */