summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/FaultTolerance/Replay_Reply/Server_Request_Interceptor.cpp
blob: e9e70026077e2a1587cbbce5f452efc54a9e7d24 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// -*- C++ -*-

#include "Server_Request_Interceptor.h"
#include "testS.h"

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

Server_Request_Interceptor::Server_Request_Interceptor (void)
  : reply_ (0)
  , last_id_ (-45)
{

}

Server_Request_Interceptor::~Server_Request_Interceptor (void)
{
}

void
Server_Request_Interceptor::tao_ft_interception_point (
    PortableInterceptor::ServerRequestInfo_ptr ri,
    CORBA::OctetSeq_out ocs
    ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     PortableInterceptor::ForwardRequest))
{
  IOP::ServiceContext_var svc =
    ri->get_request_service_context (Replay_Reply::SPECIFIC_CONTEXT
                                     ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  TAO_InputCDR cdr (ACE_reinterpret_cast (const char*,
                                          svc->context_data.get_buffer ()),
                    svc->context_data.length ());

  CORBA::Boolean byte_order;

  if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
    {
      return;
    }

  cdr.reset_byte_order (ACE_static_cast (int,byte_order));

  Replay_Reply::tagged_component group_component;

  cdr >> group_component;

  if (!cdr.good_bit ())
    return;

  if (group_component.id == this->last_id_)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "(%P|%t) Replaying reply ..\n"));

      // CORBA::OctetSeq_var o;
      ACE_NEW (ocs,
               CORBA::OctetSeq (this->reply_.in ()));

      // (ocs) = o.in ();

      ACE_DEBUG ((LM_DEBUG,
                  "(%P|%t) Done copying reply ..\n"));
    }
  else
    this->last_id_ = group_component.id;

  return;
}

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

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

void
Server_Request_Interceptor::receive_request_service_contexts (
    PortableInterceptor::ServerRequestInfo_ptr
    ACE_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ForwardRequest))
{

}

void
Server_Request_Interceptor::receive_request (
    PortableInterceptor::ServerRequestInfo_ptr
    ACE_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ForwardRequest))
{
}

void
Server_Request_Interceptor::send_reply (
    PortableInterceptor::ServerRequestInfo_ptr ri
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  CORBA::Any_var result =
    ri->result (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  CORBA::Short retval = 0;

  result >>= retval;

  TAO_OutputCDR cdr;

  cdr << retval;

  Dynamic::ParameterList_var pl =
    ri->arguments (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  CORBA::ULong len =
    pl->length ();

  for (CORBA::ULong index = 0; index != len ; ++index)
    {
      // No chance for PARAM_OUT
      if ((*pl)[index].mode == CORBA::PARAM_INOUT)
        {
          const char *str;
          (*pl)[index].argument >>= str;

          cdr.write_string (str);
        }
    }

  CORBA::OctetSeq *p = 0;

  ACE_NEW (p,
           CORBA::OctetSeq (cdr.total_length ()));

  this->reply_ = p;

  this->reply_->length (cdr.total_length ());

  CORBA::Octet *buf =
    this->reply_->get_buffer ();

  // @@ What if this throws an exception??  We don't have anyway to
  // check whether this succeeded
  for (const ACE_Message_Block *mb = cdr.begin ();
       mb != 0;
       mb = mb->cont ())
    {
      ACE_OS::memcpy (buf, mb->rd_ptr (), mb->length ());
      buf += mb->length ();
    }

}

void
Server_Request_Interceptor::send_exception (
    PortableInterceptor::ServerRequestInfo_ptr
    ACE_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ForwardRequest))
{
}

void
Server_Request_Interceptor::send_other (
    PortableInterceptor::ServerRequestInfo_ptr
    ACE_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ForwardRequest))
{
}