client_interceptor.cpp

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

CPP
152
字号
/**
 * @file Client_Interceptor.cpp
 *
 * Client_Interceptor.cpp,v 1.3 2003/11/04 08:13:00 dhinton Exp
 *
 * @author Carlos O'Ryan <coryan@atdesk.com>
 */

#include "Client_Interceptor.h"
#include "Shared_Interceptor.h"
#include "tao/OctetSeqC.h"

#include "ace/Log_Msg.h"
#include "ace/OS_NS_string.h"


ACE_RCSID (AMI,
           Client_Interceptor,
           "Client_Interceptor.cpp,v 1.3 2003/11/04 08:13:00 dhinton Exp")


unsigned long Echo_Client_Request_Interceptor::request_count = 0;
unsigned long Echo_Client_Request_Interceptor::reply_count = 0;
unsigned long Echo_Client_Request_Interceptor::other_count = 0;
unsigned long Echo_Client_Request_Interceptor::exception_count = 0;

Echo_Client_Request_Interceptor::
Echo_Client_Request_Interceptor (void)
{
}

char *
Echo_Client_Request_Interceptor::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return CORBA::string_dup ("Echo_Client_Interceptor");
}

void
Echo_Client_Request_Interceptor::destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
}

void
Echo_Client_Request_Interceptor::send_poll (
    PortableInterceptor::ClientRequestInfo_ptr
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_ERROR((LM_ERROR,
             "ERROR, unexpected interception point called send_poll()\n"));
  ACE_THROW(CORBA::BAD_PARAM ());
}

void
Echo_Client_Request_Interceptor::send_request (
    PortableInterceptor::ClientRequestInfo_ptr ri
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ForwardRequest))
{
  IOP::ServiceContext sc;
  sc.context_id = ::service_id;

  CORBA::Octet *buf = CORBA::OctetSeq::allocbuf(magic_cookie_len);
  ACE_OS::memcpy(buf, magic_cookie, magic_cookie_len);
  sc.context_data.replace (magic_cookie_len, magic_cookie_len, buf, 1);

  // Add this context to the service context list.
  ri->add_request_service_context (sc,
                                   0
                                   ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // Check that the request service context can be retrieved.
  IOP::ServiceContext_var rc =
    ri->get_request_service_context (::service_id
                                     ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  if (rc->context_data.length() != magic_cookie_len
      || ACE_OS::memcmp(
             magic_cookie, rc->context_data.get_buffer(),
             magic_cookie_len) != 0
      )
    {
      ACE_THROW(CORBA::BAD_PARAM());
    }

  Echo_Client_Request_Interceptor::request_count++;
}

void
Echo_Client_Request_Interceptor::receive_reply (
    PortableInterceptor::ClientRequestInfo_ptr ri
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // Check that the request service context can be retrieved.
  IOP::ServiceContext_var rc =
    ri->get_request_service_context (::service_id
                                     ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  if (rc->context_data.length() != magic_cookie_len
      || ACE_OS::memcmp(
             magic_cookie, rc->context_data.get_buffer(),
             magic_cookie_len) != 0
      )
    {
      ACE_THROW(CORBA::BAD_PARAM());
    }

  Echo_Client_Request_Interceptor::reply_count++;
}

void
Echo_Client_Request_Interceptor::receive_other (
    PortableInterceptor::ClientRequestInfo_ptr ri
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ForwardRequest))
{
  // Check that the request service context can be retrieved.
  IOP::ServiceContext_var rc =
    ri->get_request_service_context (::service_id
                                     ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  if (rc->context_data.length() != magic_cookie_len
      || ACE_OS::memcmp(
             magic_cookie, rc->context_data.get_buffer(),
             magic_cookie_len) != 0
      )
    {
      ACE_THROW (CORBA::BAD_PARAM ());
    }

  Echo_Client_Request_Interceptor::other_count++;
}

void
Echo_Client_Request_Interceptor::receive_exception (
    PortableInterceptor::ClientRequestInfo_ptr
    ACE_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ForwardRequest))
{
  Echo_Client_Request_Interceptor::exception_count++;
}

⌨️ 快捷键说明

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