⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rt_protocols_hooks.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "RT_Protocols_Hooks.h"

#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0

#include "RT_Policy_i.h"
#include "Priority_Mapping_Manager.h"
#include "RT_Stub.h"

#include "tao/Stub.h"
#include "tao/ORB_Core.h"
#include "tao/MProfile.h"
#include "tao/Service_Context.h"
#include "tao/Acceptor_Registry.h"
#include "tao/Thread_Lane_Resources.h"
#include "tao/Protocol_Factory.h"
#include "tao/Transport_Acceptor.h"
#include "tao/Transport_Connector.h"
#include "tao/Policy_Set.h"
#include "tao/IIOP_Transport.h"
#include "tao/debug.h"

#include "ace/Dynamic_Service.h"


ACE_RCSID (RTCORBA,
           RT_Protocols_Hooks,
           "RT_Protocols_Hooks.cpp,v 1.24 2003/10/28 18:29:32 bala Exp")


TAO_RT_Protocols_Hooks::Client_Protocols_Hook 
  TAO_RT_Protocols_Hooks::client_protocols_hook_ = 0;
TAO_RT_Protocols_Hooks::Server_Protocols_Hook 
  TAO_RT_Protocols_Hooks::server_protocols_hook_ = 0;

TAO_RT_Protocols_Hooks::TAO_RT_Protocols_Hooks (void)
{
}

TAO_RT_Protocols_Hooks::~TAO_RT_Protocols_Hooks (void)
{
}

void
TAO_RT_Protocols_Hooks::init_hooks (TAO_ORB_Core *orb_core
                                    ACE_ENV_ARG_DECL)
{
  this->orb_core_ = orb_core;

  // Save a reference to the priority mapping manager.
  CORBA::Object_var obj =
    orb_core->object_ref_table ().resolve_initial_references (
                                      TAO_OBJID_PRIORITYMAPPINGMANAGER
                                      ACE_ENV_ARG_PARAMETER
                                    );
  ACE_CHECK;

  this->mapping_manager_ =
    TAO_Priority_Mapping_Manager::_narrow (obj.in ()
                                           ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // Save a reference to the priority mapping manager.
  CORBA::Object_var object =
    orb_core->object_ref_table ().resolve_initial_references (
                                      TAO_OBJID_NETWORKPRIORITYMAPPINGMANAGER
                                      ACE_ENV_ARG_PARAMETER
                                    );
  ACE_CHECK;

  this->network_mapping_manager_ =
    TAO_Network_Priority_Mapping_Manager::_narrow (object.in ()
                                                   ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  object =
    this->orb_core_->object_ref_table ().resolve_initial_references (
                                             "RTCurrent"
                                             ACE_ENV_ARG_PARAMETER
                                           );
  ACE_CHECK;

  this->current_ =
    RTCORBA::Current::_narrow (object.in ()
                               ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

}

int
TAO_RT_Protocols_Hooks::call_client_protocols_hook (
    int &send_buffer_size,
    int &recv_buffer_size,
    int &no_delay,
    int &enable_network_priority,
    const char *protocol_type
  )
{
  if (TAO_RT_Protocols_Hooks::client_protocols_hook_ == 0)
    return -1;

  (*TAO_RT_Protocols_Hooks::client_protocols_hook_) (this->orb_core_,
                                                     send_buffer_size,
                                                     recv_buffer_size,
                                                     no_delay,
                                                     enable_network_priority,
                                                     protocol_type);

  return 0;
}

void
TAO_RT_Protocols_Hooks::set_client_protocols_hook (Client_Protocols_Hook hook)
{
  TAO_RT_Protocols_Hooks::client_protocols_hook_ = hook;
  // Saving the hook pointer so that we can use it later when needed.
}

int
TAO_RT_Protocols_Hooks::call_server_protocols_hook (
    int &send_buffer_size,
    int &recv_buffer_size,
    int &no_delay,
    int &enable_network_priority,
    const char *protocol_type
  )
{
  if (TAO_RT_Protocols_Hooks::server_protocols_hook_ == 0)
    {
      return -1;
    }

  int result_value =
    (*TAO_RT_Protocols_Hooks::server_protocols_hook_) (this->orb_core_,
                                                       send_buffer_size,
                                                       recv_buffer_size,
                                                       no_delay,
                                                       enable_network_priority,
                                                       protocol_type);

  if (result_value != 0)
    {
      return -1;
    }

  return 0;
}

void
TAO_RT_Protocols_Hooks::set_server_protocols_hook (Server_Protocols_Hook hook)
{
  TAO_RT_Protocols_Hooks::server_protocols_hook_ = hook;
  // Saving the hook pointer so that we can use it later when needed.
}

int
TAO_RT_Protocols_Hooks::update_client_protocol_properties (
    TAO_Stub *stub,
    TAO_Transport *transport,
    const char *protocol_type
  )
{
  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG,
                "TAO_RT_Protocols_Hooks::"
                "get_effective_client_protocol_properties\n"));

  ACE_TRY_NEW_ENV
    {
      RTCORBA::ProtocolProperties_var properties =
        RTCORBA::ProtocolProperties::_nil ();

      TAO_RT_Stub *rt_stub = ACE_dynamic_cast (TAO_RT_Stub *,
                                               stub);

      CORBA::Policy* policy = rt_stub->client_protocol ();

      RTCORBA::ClientProtocolPolicy_var client_protocols_policy;
      TAO_ClientProtocolPolicy *client_protocols = 0;

      if (!CORBA::is_nil (policy))
        {
          client_protocols_policy =
            RTCORBA::ClientProtocolPolicy::_narrow (policy
                                                    ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          client_protocols =
            ACE_dynamic_cast (TAO_ClientProtocolPolicy *,
                              client_protocols_policy.in ());

          if (client_protocols != 0)
            {
              // TAO_ClientProtocolPolicy
              RTCORBA::ProtocolList & protocols =
                client_protocols->protocols_rep ();

              for (CORBA::ULong j = 0; j < protocols.length (); ++j)
                {
                  if (protocols[j].protocol_type == IOP::TAG_INTERNET_IOP)
                    {
                      properties =
                        RTCORBA::ProtocolProperties::_narrow (
                            protocols[j].transport_protocol_properties.in ()
                            ACE_ENV_ARG_PARAMETER
                          );
                      ACE_TRY_CHECK;

                      if (ACE_OS::strcmp (protocol_type, "iiop") == 0)
                        {
                          break;
                        }
                    }
                }
            }

          if (ACE_OS::strcmp (protocol_type, "iiop") == 0)
            {
              if (!CORBA::is_nil (properties.in ()))
                {
                  RTCORBA::TCPProtocolProperties_var tcp_properties =
                    RTCORBA::TCPProtocolProperties::_narrow (
                        properties.in ()
                        ACE_ENV_ARG_PARAMETER
                      );
                  ACE_TRY_CHECK;

                  int send_buffer_size =
                    tcp_properties->send_buffer_size (
                                        ACE_ENV_SINGLE_ARG_PARAMETER
                                      );
                  ACE_TRY_CHECK;

                  int recv_buffer_size =
                    tcp_properties->recv_buffer_size (
                                        ACE_ENV_SINGLE_ARG_PARAMETER
                                      );
                  ACE_TRY_CHECK;

                  int no_delay = 
                    tcp_properties->no_delay (
                                        ACE_ENV_SINGLE_ARG_PARAMETER
                                      );
                  ACE_TRY_CHECK;

                  int enable_network_priority =
                    tcp_properties->enable_network_priority (
                                        ACE_ENV_SINGLE_ARG_PARAMETER
                                      );
                  ACE_TRY_CHECK;

                  TAO_IIOP_Transport *iiop_transport =
                    ACE_dynamic_cast (TAO_IIOP_Transport *,
                                      transport);

                  iiop_transport->update_protocol_properties (
                                      send_buffer_size,
                                      recv_buffer_size,
                                      no_delay,
                                      enable_network_priority
                                    );
                }
            }
        }
    }
  ACE_CATCHANY
    {
      if (TAO_debug_level > 4)
        ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                             "TAO_RT_Protocols_Hooks::"
                             "get_effective_client_protocol_properties");

      return -1;
    }
  ACE_ENDTRY;

  return 0;
}

int
TAO_RT_Protocols_Hooks::update_server_protocol_properties (
    CORBA::Policy *policy,
    TAO_Transport *transport,
    const char *protocol_type
  )
{

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG,
                "TAO_RT_Protocols_Hooks::"
                "get_effective_server_protocol_properties\n"));

  ACE_TRY_NEW_ENV
    {
      RTCORBA::ProtocolProperties_var properties =
        RTCORBA::ProtocolProperties::_nil ();

      RTCORBA::ServerProtocolPolicy_var server_protocols_policy;
      TAO_ServerProtocolPolicy *server_protocols = 0;

      if (!CORBA::is_nil (policy))
        {
          server_protocols_policy =
            RTCORBA::ServerProtocolPolicy::_narrow (policy
                                                    ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          server_protocols =
            ACE_dynamic_cast (TAO_ServerProtocolPolicy *,
                              server_protocols_policy.in ());

          if (server_protocols != 0)
            {
              // TAO_ServerProtocolPolicy
              RTCORBA::ProtocolList & protocols =
                server_protocols->protocols_rep ();

              for (CORBA::ULong j = 0; j < protocols.length (); ++j)
                {
                  if (protocols[j].protocol_type == IOP::TAG_INTERNET_IOP)
                    {
                      properties =
                        RTCORBA::ProtocolProperties::_narrow (
                          protocols[j].transport_protocol_properties.in ()
                          ACE_ENV_ARG_PARAMETER);
                      ACE_TRY_CHECK;

                      if (ACE_OS::strcmp (protocol_type, "iiop") == 0)
                        {
                          break;
                        }
                    }
                }
            }

          if (ACE_OS::strcmp (protocol_type, "iiop") == 0)
            {
              if (!CORBA::is_nil (properties.in ()))
                {
                  RTCORBA::TCPProtocolProperties_var tcp_properties =
                    RTCORBA::TCPProtocolProperties::_narrow (
                        properties.in ()
                        ACE_ENV_ARG_PARAMETER
                      );
                  ACE_TRY_CHECK;

                  int send_buffer_size =
                    tcp_properties->send_buffer_size (
                                        ACE_ENV_SINGLE_ARG_PARAMETER
                                      );
                  ACE_TRY_CHECK;

                  int recv_buffer_size =
                    tcp_properties->recv_buffer_size (
                                        ACE_ENV_SINGLE_ARG_PARAMETER
                                      );
                  ACE_TRY_CHECK;

                  int no_delay = 
                    tcp_properties->no_delay (
                                        ACE_ENV_SINGLE_ARG_PARAMETER
                                      );
                  ACE_TRY_CHECK;

                  int enable_network_priority =
                    tcp_properties->enable_network_priority (
                                        ACE_ENV_SINGLE_ARG_PARAMETER
                                      );
                  ACE_TRY_CHECK;

                  TAO_IIOP_Transport *iiop_transport =
                    ACE_dynamic_cast (TAO_IIOP_Transport *,
                                      transport);

                  iiop_transport->update_protocol_properties (
                                      send_buffer_size,
                                      recv_buffer_size,
                                      no_delay,
                                      enable_network_priority
                                    );
                }
            }
        }
    }
  ACE_CATCHANY
    {
      if (TAO_debug_level > 4)
        ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                             "TAO_RT_Protocols_Hooks::"
                             "get_effective_client_protocol_properties");

      return -1;
    }
  ACE_ENDTRY;

  return 0;
}

CORBA::Long
TAO_RT_Protocols_Hooks::get_dscp_codepoint (void)
{
  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG,
                "TAO_RT_Protocols_Hooks::get_dscp_codepoint\n"));

  CORBA::Long codepoint = 0;

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // Make several invocation, changing the priority of this thread
      // for each.

      RTCORBA::NetworkPriorityMapping *pm =
        this->network_mapping_manager_->mapping ();

      CORBA::Short priority =
        this->current_->the_priority (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (pm->to_network (priority, codepoint) == 0)
        {
          if (TAO_debug_level > 0)
            {
              ACE_ERROR ((LM_ERROR,
                          "Cannot convert corba priority %d "
                          "to network priority\n",

⌨️ 快捷键说明

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