Servant_Upcall.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Servant_Upcall.h
00006  *
00007  *  $Id: Servant_Upcall.h 78292 2007-05-09 19:20:32Z johnnyw $
00008  *
00009  *  @author Irfan Pyarali
00010  */
00011 //=============================================================================
00012 
00013 #ifndef TAO_SERVANT_UPCALL_H
00014 #define TAO_SERVANT_UPCALL_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "tao/PortableServer/portableserver_export.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "tao/PortableServer/POA_Current_Impl.h"
00025 
00026 #if defined(_MSC_VER)
00027 #pragma warning(push)
00028 #pragma warning(disable:4250)
00029 #endif /* _MSC_VER */
00030 
00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 // Forward declaration
00034 class TAO_Root_POA;
00035 class TAO_ServerRequest;
00036 class TAO_Object_Adapter;
00037 class TAO_RT_Collocation_Resolver;
00038 struct TAO_Active_Object_Map_Entry;
00039 
00040 namespace CORBA
00041 {
00042   class Object;
00043   typedef Object *Object_ptr;
00044   typedef TAO_Pseudo_Var_T<Object> Object_var;
00045   typedef TAO_Pseudo_Out_T<Object> Object_out;
00046 }
00047 
00048 namespace TAO
00049 {
00050   namespace Portable_Server
00051   {
00052     /**
00053      * @class Servant_Upcall
00054      *
00055      * @brief This class finds out the POA and the servant to perform an
00056      * upcall.  It can only be instantiated without the object
00057      * adapter's lock held. For each upcall a new instance of this
00058      * class is created.
00059      */
00060     class TAO_PortableServer_Export Servant_Upcall
00061     {
00062     public:
00063       friend class ::TAO_RT_Collocation_Resolver;
00064 
00065       /**
00066        * @class Pre_Invoke_State
00067        *
00068        * @brief This struct keeps track of state related to pre- and
00069        * post-invoke operations.
00070        */
00071       class Pre_Invoke_State
00072       {
00073       public:
00074         /// Constructor.
00075         Pre_Invoke_State (void);
00076 
00077         enum State
00078         {
00079           NO_ACTION_REQUIRED,
00080           PRIORITY_RESET_REQUIRED
00081         };
00082 
00083         /// Indicates whether the priority of the thread needs to be
00084         /// reset back to its original value.
00085         State state_;
00086 
00087         /// Original native priority of the thread.
00088         CORBA::Short original_native_priority_;
00089 
00090         /// Original CORBA priority of the thread.
00091         CORBA::Short original_CORBA_priority_;
00092       };
00093 
00094       /// Constructor.
00095       explicit Servant_Upcall (TAO_ORB_Core *orb_core);
00096 
00097       /// Destructor.
00098       ~Servant_Upcall (void);
00099 
00100       /// Locate POA and servant.
00101       int prepare_for_upcall (const TAO::ObjectKey &key,
00102                               const char *operation,
00103                               CORBA::Object_out forward_to);
00104 
00105       /// Helper.
00106       int prepare_for_upcall_i (const TAO::ObjectKey &key,
00107                                 const char *operation,
00108                                 CORBA::Object_out forward_to,
00109                                 bool &wait_occurred_restart_call);
00110 
00111       /// Run pre_invoke for a remote request.
00112       void pre_invoke_remote_request (TAO_ServerRequest &req);
00113 
00114       /// Run pre_invoke for a collocated request.
00115       void pre_invoke_collocated_request (void);
00116 
00117       /// Run post_invoke for a request.
00118       void post_invoke (void);
00119 
00120       /// Locate POA.
00121       ::TAO_Root_POA *lookup_POA (const TAO::ObjectKey &key);
00122 
00123       /// POA accessor.
00124       ::TAO_Root_POA &poa (void) const;
00125 
00126       /// Object Adapter accessor.
00127       TAO_Object_Adapter &object_adapter (void) const;
00128 
00129       /// System ID accessor.
00130       const PortableServer::ObjectId &id (void) const;
00131 
00132       /// User ID accessors.  This is the same value returned by
00133       /// PortableServer::Current::get_object_id().
00134       void user_id (const PortableServer::ObjectId *);
00135       const PortableServer::ObjectId &user_id (void) const;
00136 
00137       /// Servant accessor.
00138       PortableServer::Servant servant (void) const;
00139 
00140   #if (TAO_HAS_MINIMUM_POA == 0)
00141 
00142       /// Get the Servant Locator's cookie
00143       void* locator_cookie (void) const;
00144 
00145       /// Set the Servant Locator's cookie
00146       void locator_cookie (void* cookie);
00147 
00148       /// Get the operation name.
00149       const char *operation (void) const;
00150 
00151       /// Set the operation name.
00152       void operation (const char *);
00153 
00154   #endif /* TAO_HAS_MINIMUM_POA == 0 */
00155 
00156       /// Set the active_object_map_entry.
00157       void active_object_map_entry (TAO_Active_Object_Map_Entry *entry);
00158 
00159       /// Get the active_object_map_entry.
00160       TAO_Active_Object_Map_Entry *active_object_map_entry (void) const;
00161 
00162       /// Get the priority for the current upcall.
00163       CORBA::Short priority (void) const;
00164 
00165       enum State
00166       {
00167         INITIAL_STAGE,
00168         OBJECT_ADAPTER_LOCK_ACQUIRED,
00169         POA_CURRENT_SETUP,
00170         OBJECT_ADAPTER_LOCK_RELEASED,
00171         SERVANT_LOCK_ACQUIRED
00172       };
00173 
00174       /// Get the state.
00175       State state (void) const;
00176 
00177       /// Set the state.
00178       void state (State);
00179 
00180       /// Increment the refcount
00181       void increment_servant_refcount (void);
00182 
00183     protected:
00184 
00185       void post_invoke_servant_cleanup (void);
00186       void single_threaded_poa_setup (void);
00187       void single_threaded_poa_cleanup (void);
00188       void servant_cleanup (void);
00189       void poa_cleanup (void);
00190 
00191       /// Clean-up / reset state of this Servant_Upcall object.
00192       void upcall_cleanup (void);
00193 
00194     protected:
00195 
00196       TAO_Object_Adapter *object_adapter_;
00197 
00198       ::TAO_Root_POA *poa_;
00199 
00200       PortableServer::Servant servant_;
00201 
00202       State state_;
00203 
00204       CORBA::Octet system_id_buf_[TAO_POA_OBJECT_ID_BUF_SIZE];
00205       PortableServer::ObjectId system_id_;
00206 
00207       const PortableServer::ObjectId *user_id_;
00208 
00209       POA_Current_Impl current_context_;
00210 
00211   #if (TAO_HAS_MINIMUM_POA == 0)
00212 
00213       /// Servant Locator's cookie
00214       void* cookie_;
00215 
00216       /// Operation name for this current.
00217       const char *operation_;
00218 
00219   #endif /* TAO_HAS_MINIMUM_POA == 0 */
00220 
00221       /// Pointer to the entry in the TAO_Active_Object_Map corresponding
00222       /// to the servant for this request.
00223       TAO_Active_Object_Map_Entry *active_object_map_entry_;
00224 
00225       /// Preinvoke data for the upcall.
00226       Pre_Invoke_State pre_invoke_state_;
00227 
00228     private:
00229       Servant_Upcall (const Servant_Upcall &);
00230       void operator= (const Servant_Upcall &);
00231     };
00232   }
00233 }
00234 
00235 TAO_END_VERSIONED_NAMESPACE_DECL
00236 
00237 #if defined(_MSC_VER)
00238 #pragma warning(pop)
00239 #endif /* _MSC_VER */
00240 
00241 #if defined (__ACE_INLINE__)
00242 # include "tao/PortableServer/Servant_Upcall.inl"
00243 #endif /* __ACE_INLINE__ */
00244 
00245 #include /**/ "ace/post.h"
00246 
00247 #endif /* TAO_SERVANT_UPCALL_H */

Generated on Tue Feb 2 17:40:54 2010 for TAO_PortableServer by  doxygen 1.4.7