summaryrefslogtreecommitdiff
path: root/ACE/TAO/tests/Collocated_Forwarding/Server_Request_Interceptor.cpp
blob: 409984578b0e7a77576b02df64749475bbf7fcb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// -*- C++ -*-

#include "Server_Request_Interceptor.h"
#include "tao/PI_Server/PI_Server.h"
#include "tao/ORB_Constants.h"
#include "tao/CDR.h"
#include "testS.h"

ACE_RCSID (Collocated_Forwarding,
           Server_Request_Interceptor,
           "$Id$")

//static const CORBA::ULong expected_version = 5;

Server_Request_Interceptor::Server_Request_Interceptor (CORBA::ULong request_pass_count)
  : request_pass_count_ (request_pass_count)
  , request_count_ (0)
  , to_ (CORBA::Object::_nil ())
{
}

void
Server_Request_Interceptor::forward (
  CORBA::Object_ptr to)
{
  if (CORBA::is_nil (to))
    throw CORBA::INV_OBJREF (
      CORBA::SystemException::_tao_minor_code (
        TAO::VMCID,
        EINVAL),
      CORBA::COMPLETED_NO);

  ACE_TCHAR *argv[] = {NULL};
  int   argc = 0;

  // Fetch the ORB having been initialized in main()
  CORBA::ORB_var orb =
    CORBA::ORB_init (argc, argv, "Server ORB");

  CORBA::String_var s_to = orb->object_to_string (to);

  this->to_ = orb->string_to_object (s_to.in ());
}

char *
Server_Request_Interceptor::name (void)
{
  return CORBA::string_dup ("Server_Request_Interceptor");
}

void
Server_Request_Interceptor::destroy (void)
{
  CORBA::release (this->to_);
}

void
Server_Request_Interceptor::receive_request_service_contexts (
    PortableInterceptor::ServerRequestInfo_ptr)
{
  this->request_count_++;
}

void
Server_Request_Interceptor::receive_request (
    PortableInterceptor::ServerRequestInfo_ptr)
{
  if (this->request_count_ == this->request_pass_count_)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "SERVER: Request %d will be forwarded "
                  "to object 'to'\nSERVER: via "
                  "receive_request_service_contexts().\n",
                  this->request_count_));

      // Throw forward exception
      throw PortableInterceptor::ForwardRequest (this->to_);
    }

  return;
}

void
Server_Request_Interceptor::send_reply (
    PortableInterceptor::ServerRequestInfo_ptr)
{
}

void
Server_Request_Interceptor::send_exception (
    PortableInterceptor::ServerRequestInfo_ptr)
{
}

void
Server_Request_Interceptor::send_other (
    PortableInterceptor::ServerRequestInfo_ptr)
{
}