object_adapter.cpp

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

CPP
2,061
字号
  // <Object_Adapter::non_servant_upcall_in_progress_> has been set.
  Non_Servant_Upcall non_servant_upcall (*parent);
  ACE_UNUSED_ARG (non_servant_upcall);

  for (;
       iterator != end;
       ++iterator)
    {
      TAO_POA *current = 0;

      ACE_TRY
        {
          current = parent->find_POA_i (*iterator,
                                        1
                                        ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
        }
      ACE_CATCH (PortableServer::POA::AdapterNonExistent, ex)
        {
          return -1;
        }
      ACE_ENDTRY;
      ACE_CHECK_RETURN (-1);

      parent = current;
    }

  poa = parent;
  result = 0;
#else
  ACE_UNUSED_ARG (folded_name);
  ACE_UNUSED_ARG (poa);
  ACE_ENV_ARG_NOT_USED; // FUZZ: ignore check_for_ace_check
#endif /* TAO_HAS_MINIMUM_POA == 0 */

  return result;
}

int
TAO_Object_Adapter::find_transient_poa (const poa_name &system_name,
                                        CORBA::Boolean root,
                                        const TAO_Temporary_Creation_Time &poa_creation_time,
                                        TAO_POA *&poa
                                        ACE_ENV_ARG_DECL_NOT_USED)
{
  int result = 0;

  if (root)
    {
      poa = this->root_;
    }
  else
    {
      result = this->transient_poa_map_->find (system_name,
                                               poa);
    }

  if (poa == 0
      || (result == 0 && poa->creation_time () != poa_creation_time))
    result = -1;

  return result;
}

int
TAO_Object_Adapter::bind_poa (const poa_name &folded_name,
                              TAO_POA *poa,
                              poa_name_out system_name)
{
  if (poa->persistent ())
    return this->bind_persistent_poa (folded_name,
                                      poa,
                                      system_name);
  else
    return this->bind_transient_poa (poa,
                                     system_name);
}

int
TAO_Object_Adapter::unbind_poa (TAO_POA *poa,
                                const poa_name &folded_name,
                                const poa_name &system_name)
{
  if (poa->persistent ())
    return this->unbind_persistent_poa (folded_name,
                                        system_name);
  else
    return this->unbind_transient_poa (system_name);
}

int
TAO_Object_Adapter::locate_servant_i (const TAO::ObjectKey &key
                                      ACE_ENV_ARG_DECL)
{
  PortableServer::ObjectId id;
  TAO_POA *poa = 0;

  this->locate_poa (key,
                    id,
                    poa
                    ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  PortableServer::Servant servant = 0;
  TAO_SERVANT_LOCATION servant_location =
    poa->locate_servant_i (id,
                           servant
                           ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  switch (servant_location)
    {
    case TAO_SERVANT_FOUND:
      // Optimistic attitude
    case TAO_DEFAULT_SERVANT:
    case TAO_SERVANT_MANAGER:
      return 0;

    case TAO_SERVANT_NOT_FOUND:
      return -1;
    }

  return -1;
}

TAO_SERVANT_LOCATION
TAO_Object_Adapter::find_servant_i (const TAO::ObjectKey &key,
                                    PortableServer::Servant &servant
                                    ACE_ENV_ARG_DECL)
{
  PortableServer::ObjectId id;
  TAO_POA *poa = 0;

  this->locate_poa (key,
                    id,
                    poa
                    ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (TAO_SERVANT_NOT_FOUND);

  TAO_SERVANT_LOCATION servant_location = poa->locate_servant_i (id,
                                                                 servant
                                                                 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (TAO_SERVANT_NOT_FOUND);

  return servant_location;
}

void
TAO_Object_Adapter::open (ACE_ENV_SINGLE_ARG_DECL)
{
  // Add in the default POA policies to the default list.
  this->init_default_policies (this->default_poa_policies ()
                               ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // If a POA extension hasn't changed the servant dispatcher, initialize the
  // default one.
  if (this->servant_dispatcher_ == 0)
    {
      ACE_NEW (this->servant_dispatcher_,
               TAO_Default_Servant_Dispatcher);
    }

  TAO_POA_Manager *poa_manager;
  ACE_NEW_THROW_EX (poa_manager,
                    TAO_POA_Manager (*this),
                    CORBA::NO_MEMORY ());
  ACE_CHECK;

  PortableServer::POAManager_var safe_poa_manager = poa_manager;

  // This makes sure that the default resources are open when the Root
  // POA is created.
  this->orb_core_.thread_lane_resources_manager ().open_default_resources (TAO_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  // Set the default Server Protocol Policy.
  this->set_default_server_protocol_policy (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  TAO_POA_Policy_Set policies (this->default_poa_policies ());

#if (TAO_HAS_MINIMUM_POA == 0)
  // Specify the implicit activation policy since it should
  // be different from the default.  Note that merge_policy
  // takes a const reference and makes its own copy of the
  // policy.  (Otherwise, we'd have to allocate the policy
  // on the heap.)
  TAO_Implicit_Activation_Policy
    implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION);

  policies.merge_policy (&implicit_activation_policy
                         ACE_ENV_ARG_PARAMETER);
#endif /* TAO_HAS_MINIMUM_POA == 0 */

  // Merge policies from the ORB level.
  this->validator ().merge_policies (policies.policies ()
                                     ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // Construct a new POA
  TAO_POA::String root_poa_name (TAO_DEFAULT_ROOTPOA_NAME);
  this->root_ =
    this->servant_dispatcher_->create_POA (root_poa_name,
                                           *poa_manager,
                                           policies,
                                           0,
                                           this->lock (),
                                           this->thread_lock (),
                                           this->orb_core_,
                                           this
                                           ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // The Object_Adapter will keep a reference to the Root POA so that
  // on its destruction, it can check whether the Root POA has been
  // destroyed yet or not.
  this->root_->_add_ref ();

  // Lock access for the duration of this transaction.
  TAO_POA_Guard poa_guard (*this->root_ ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // Iterate over the registered IOR interceptors so that they may be
  // given the opportunity to add tagged components to the profiles
  // for this servant.
  this->root_->establish_components (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  // Release the POA_Manager_var since we got here without error.  The
  // TAO_POA object takes ownership of the POA_Manager object
  // (actually it shares the ownership with its peers).
  (void) safe_poa_manager._retn ();
}

void
TAO_Object_Adapter::set_default_server_protocol_policy (ACE_ENV_SINGLE_ARG_DECL)
{
  TAO_Thread_Lane_Resources &default_lane_resources =
    this->orb_core_.thread_lane_resources_manager ().default_lane_resources ();

  TAO_Acceptor_Registry &acceptor_registry =
    default_lane_resources.acceptor_registry ();

  TAO_Protocols_Hooks *protocols_hooks =
    this->orb_core_.get_protocols_hooks (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  protocols_hooks->set_default_server_protocol_policy (acceptor_registry
                                                       ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;
}

void
TAO_Object_Adapter::close (int wait_for_completion
                           ACE_ENV_ARG_DECL)
{
  this->check_close (wait_for_completion ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // Shutting down the ORB causes all object adapters to be destroyed,
  // since they cannot exist in the absence of an ORB. Shut down is
  // complete when all ORB processing (including request processing
  // and object deactivation or other operations associated with
  // object adapters) has completed and the object adapters have been
  // destroyed. In the case of the POA, this means that all object
  // etherealizations have finished and root POA has been destroyed
  // (implying that all descendent POAs have also been destroyed).

  TAO_POA *root;
  {
    ACE_GUARD (ACE_Lock, ace_mon, this->lock ());
    if (this->root_ == 0)
      return;
    root = this->root_;
    this->root_ = 0;
  }
  CORBA::Boolean etherealize_objects = 1;
  root->destroy (etherealize_objects,
                 wait_for_completion
                 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;
  CORBA::release (root);
}

void
TAO_Object_Adapter::check_close (int wait_for_completion
                                 ACE_ENV_ARG_DECL)
{
  TAO_POA::check_for_valid_wait_for_completions (this->orb_core (),
                                                 wait_for_completion
                                                 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;
}

int
TAO_Object_Adapter::priority (void) const
{
  return 0;
}

int
TAO_Object_Adapter::dispatch (TAO::ObjectKey &key,
                              TAO_ServerRequest &request,
                              CORBA::Object_out forward_to
                              ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (ACE_OS::memcmp (key.get_buffer (),
                      &TAO_POA::objectkey_prefix[0],
                      TAO_POA::TAO_OBJECTKEY_PREFIX_SIZE) != 0)
    {
      return TAO_Adapter::DS_MISMATCHED_KEY;
    }

  int result = 0;

#if TAO_HAS_INTERCEPTORS == 1
  TAO_ServerRequestInterceptor_Adapter sri_adapter (
    this->orb_core_.server_request_interceptors (),
    request.interceptor_count ());

  TAO_ServerRequestInfo ri (request, 0);

  ACE_TRY
    {
#if TAO_HAS_EXTENDED_FT_INTERCEPTORS == 1
      CORBA::OctetSeq_var ocs;
      sri_adapter.tao_ft_interception_point (&ri,
                                             ocs.out ()
                                             ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      /// If we have a cached result, just go ahead and send the reply
      /// and let us  return
      if (ocs.ptr () != 0)
        {
          // request.result_seq (
          request.send_cached_reply (ocs.inout ());

          return TAO_Adapter::DS_OK;
        }
#endif /*TAO_HAS_EXTENDED_FT_INTERCEPTORS*/

      // The receive_request_service_contexts() interception point
      // must be invoked before the operation is dispatched to the
      // servant.
      sri_adapter.receive_request_service_contexts (&ri ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // If a PortableInterceptor::ForwardRequest exception was
      // thrown, then set the forward_to object reference and return
      // with the appropriate return status.
      if (sri_adapter.location_forwarded ())
        {
          forward_to = ri.forward_reference (ACE_ENV_SINGLE_ARG_PARAMETER);
          ACE_TRY_CHECK;

          return TAO_Adapter::DS_FORWARD;
        }
#endif  /* TAO_HAS_INTERCEPTORS == 1 */

      result = this->dispatch_servant (key,
                                       request,
                                       forward_to
                                       ACE_ENV_ARG_PARAMETER);

#if TAO_HAS_INTERCEPTORS == 1
      ACE_TRY_CHECK;

      if (result == TAO_Adapter::DS_FORWARD)
        {
          ri.forward_reference (forward_to.ptr ());
          sri_adapter.send_other (&ri
                                  ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
        }
    }
  ACE_CATCHANY
    {
      ri.exception (&ACE_ANY_EXCEPTION);

      sri_adapter.send_exception (&ri
                                  ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      PortableInterceptor::ReplyStatus status =
        ri.reply_status (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Only re-throw the exception if it hasn't been transformed by
      // the send_exception() interception point (e.g. to a
      // LOCATION_FORWARD).
      if (status == PortableInterceptor::SYSTEM_EXCEPTION
          || status == PortableInterceptor::USER_EXCEPTION)
        ACE_RE_THROW;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (result);
#endif  /* TAO_HAS_INTERCEPTORS == 1 */

  return result;
}

const char *
TAO_Object_Adapter::name (void) const
{
  return TAO_OBJID_ROOTPOA;
}

CORBA::Object_ptr
TAO_Object_Adapter::root (void)
{

⌨️ 快捷键说明

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