object_adapter.h

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C头文件 代码 · 共 913 行 · 第 1/2 页

H
913
字号
   * @class No_Hint_Strategy
   *
   * @brief This class doesn't use any hints for POA active hint
   * strategy.
   *
   * This class will simply use the POA names as is. And since
   * no hint is added, the IORs will be smaller.
   */
  class TAO_PortableServer_Export No_Hint_Strategy : public Hint_Strategy
  {
  public:

    virtual ~No_Hint_Strategy (void);

    virtual int find_persistent_poa (const poa_name &system_name,
                                     TAO_POA *&poa
                                     ACE_ENV_ARG_DECL);

    virtual int bind_persistent_poa (const poa_name &folded_name,
                                     TAO_POA *poa,
                                     poa_name_out system_name);

    virtual int unbind_persistent_poa (const poa_name &folded_name,
                                       const poa_name &system_name);

  };

protected:

  Hint_Strategy *hint_strategy_;

  /// Base class of the id map.
  typedef ACE_Map<
  poa_name,
    TAO_POA *> transient_poa_map;

#if (TAO_HAS_MINIMUM_POA_MAPS == 0)
  /// Id hash map.
  typedef ACE_Hash_Map_Manager_Ex_Adapter<
  poa_name,
    TAO_POA *,
    TAO_ObjectId_Hash,
    ACE_Equal_To<poa_name>,
    TAO_Incremental_Key_Generator> transient_poa_hash_map;
#endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */

#if (TAO_HAS_MINIMUM_POA_MAPS == 0)
  /// Id linear map.
  typedef ACE_Map_Manager_Adapter<
  poa_name,
    TAO_POA *,
    TAO_Incremental_Key_Generator> transient_poa_linear_map;
#endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */

  /// Id active map.
  typedef ACE_Active_Map_Manager_Adapter<
  poa_name,
    TAO_POA *,
    TAO_Ignore_Original_Key_Adapter> transient_poa_active_map;

  /// Base class of the name map.
  typedef ACE_Map<
  poa_name,
    TAO_POA *> persistent_poa_name_map;

  /// Id hash map.
  typedef ACE_Hash_Map_Manager_Ex_Adapter<
  poa_name,
    TAO_POA *,
    TAO_ObjectId_Hash,
    ACE_Equal_To<PortableServer::ObjectId>,
    ACE_Noop_Key_Generator<poa_name> > persistent_poa_name_hash_map;

#if (TAO_HAS_MINIMUM_POA_MAPS == 0)
  /// Id linear map.
  typedef ACE_Map_Manager_Adapter<
  poa_name,
    TAO_POA *,
    ACE_Noop_Key_Generator<poa_name> > persistent_poa_name_linear_map;
#endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */

  /// Strategy for dispatching a request to a servant.
  TAO_Servant_Dispatcher *servant_dispatcher_;

public:

  persistent_poa_name_map *persistent_poa_name_map_;
  transient_poa_map *transient_poa_map_;

protected:

  static CORBA::ULong transient_poa_name_size_;

  static void set_transient_poa_name_size (const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters);

  TAO_ORB_Core &orb_core_;

  int enable_locking_;

  TAO_SYNCH_MUTEX thread_lock_;

  ACE_Lock *lock_;

  ACE_Reverse_Lock<ACE_Lock> reverse_lock_;

public:

  /**
   * @class poa_name_iterator
   *
   * @brief Iterator for a folded poa name.
   */
  class TAO_PortableServer_Export poa_name_iterator
  {
  public:

    /// Constructor.
    poa_name_iterator (int begin,
                       CORBA::ULong size,
                       const CORBA::Octet *folded_buffer);

    /// Comparison operators.
    int operator== (const poa_name_iterator &rhs) const;
    int operator!= (const poa_name_iterator &rhs) const;

    /// Dereference operator.
    ACE_CString operator* () const;

    /// Prefix advance.
    poa_name_iterator &operator++ (void);

  protected:

    CORBA::ULong size_;
    CORBA::ULong position_;
    const CORBA::Octet *folded_buffer_;
    CORBA::ULong last_separator_;
  };

  /**
   * @class iteratable_poa_name
   *
   * @brief This class allows iteration over a folded poa name.
   */
  class TAO_PortableServer_Export iteratable_poa_name
  {
  public:

    typedef poa_name_iterator iterator;

    iteratable_poa_name (const poa_name &folded_name);

    iterator begin (void) const;
    iterator end (void) const;

  protected:

    const poa_name &folded_name_;
  };

  /**
   * @class Non_Servant_Upcall
   *
   * @brief This class helps us with a recursive thread lock without
   * using a recursive thread lock.  Non_Servant_Upcall has a
   * magic constructor and destructor.  We unlock the
   * Object_Adapter lock for the duration of the non-servant
   * (i.e., adapter activator and servant activator) upcalls;
   * reacquiring once the upcalls complete.  Even though we are
   * releasing the lock, other threads will not be able to make
   * progress since
   * <Object_Adapter::non_servant_upcall_in_progress_> has been
   * set.
   */
  class TAO_PortableServer_Export Non_Servant_Upcall
  {
  public:

    /// Constructor.
    Non_Servant_Upcall (TAO_POA &poa);

    /// Destructor.
    ~Non_Servant_Upcall (void);

    TAO_POA &poa (void) const;

  protected:

    TAO_Object_Adapter &object_adapter_;
    TAO_POA &poa_;
    Non_Servant_Upcall *previous_;
  };

  friend class Non_Servant_Upcall;

  /**
   * @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.
   */
  class TAO_PortableServer_Export Servant_Upcall
  {
  public:

    friend class TAO_POA;
    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_;
    };

    // @@ POA: Servant_Upcall (TAO_Object_Adapter &object_adapter);
    /// Constructor.
    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
                            ACE_ENV_ARG_DECL_WITH_DEFAULTS);

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

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

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

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

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

    /// POA accessor.
    TAO_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
    PortableServer::ServantLocator::Cookie locator_cookie (void) const;

    /// Set the Servant Locator's cookie
    void locator_cookie (PortableServer::ServantLocator::Cookie 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::Map_Entry *entry);

    /// Get the <active_object_map_entry>.
    TAO_Active_Object_Map::Map_Entry *active_object_map_entry (void) const;

    /// We are using the servant locator for this upcall.
    void using_servant_locator (void);

    /// 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
    };

    // State accessors.
    State state (void) const;
    void state (State);

  protected:

    void servant_locator_cleanup (void);
    void single_threaded_poa_setup (ACE_ENV_SINGLE_ARG_DECL);
    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_POA *poa_;

    PortableServer::Servant servant_;

    State state_;

    PortableServer::ObjectId system_id_;

    const PortableServer::ObjectId *user_id_;

    TAO_POA_Current_Impl current_context_;

#if (TAO_HAS_MINIMUM_POA == 0)

    /// Servant Locator's cookie
    PortableServer::ServantLocator::Cookie 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::Map_Entry *active_object_map_entry_;

    /// Are we using the servant locator?
    int using_servant_locator_;

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

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

  friend class Servant_Upcall;

public:

  /// Pointer to the non-servant upcall in progress.  If no non-servant
  /// upcall is in progress, this pointer is zero.
  Non_Servant_Upcall *non_servant_upcall_in_progress (void) const;

private:

  /// Helper method to get collocated servant
  TAO_ServantBase *get_collocated_servant (const TAO_MProfile &mp
                                           ACE_ENV_ARG_DECL);

private:

  /// Condition variable for waiting on non-servant upcalls to end.
  TAO_SYNCH_CONDITION non_servant_upcall_condition_;

  /// Pointer to the non-servant upcall in progress.  If no non-servant
  /// upcall is in progress, this pointer is zero.
  Non_Servant_Upcall *non_servant_upcall_in_progress_;

  /// Current nesting level of non_servant_upcalls.
  unsigned int non_servant_upcall_nesting_level_;

  /// Id of thread making the non-servant upcall.
  ACE_thread_t non_servant_upcall_thread_;

  /// The Root POA
  TAO_POA *root_;

  /// The default validator and the beginning of the chain of
  /// policy validators.
  TAO_POA_Default_Policy_Validator default_validator_;

  /// Save a list of default policies that should be included in
  /// every POA (unless overridden).
  TAO_POA_Policy_Set default_poa_policies_;
};

// ****************************************************************

class TAO_PortableServer_Export TAO_Object_Adapter_Factory : public TAO_Adapter_Factory
{
public:
  /// Constructor
  TAO_Object_Adapter_Factory (void);

  // = The TAO_Adapter_Factory methods, please read tao/Adapter.h for
  // details.
  virtual TAO_Adapter *create (TAO_ORB_Core *orb_core);

  virtual int init (int argc,
                    ACE_TCHAR* argv[]);
};

ACE_STATIC_SVC_DECLARE (TAO_Object_Adapter_Factory)
ACE_FACTORY_DECLARE (TAO_PortableServer, TAO_Object_Adapter_Factory)

// ****************************************************************

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(pop)
#endif /* _MSC_VER */

#if defined (__ACE_INLINE__)
# include "Object_Adapter.i"
#endif /* __ACE_INLINE__ */

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

#endif /* TAO_OBJECT_ADAPTER_H */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?