summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Transport_Current/Framework/Client_Request_Interceptor.cpp
blob: 05190ee9efaafa9fc8056c012bc9e86946483433 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// -*- C++ -*-

#include "ace/Log_Msg.h"

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

#include "Current_TestC.h"
#include "Client_Request_Interceptor.h"
#include "ORBInitializer_T.h"

//   // A specialization to handle client-side interceptors
//   template <>
//   void ORBInitializer<PortableInterceptor::ClientRequestInterceptor>::post_init
//     (PortableInterceptor::ORBInitInfo* oii ACE_ENV_ARG_DECL_WITH_DEFAULTS)
//       ACE_THROW_SPEC ((CORBA::SystemException));


namespace Test
{

  using namespace TAO;

  // A specialization to handle client-side interceptors
  template <>
  void
  ORBInitializer<PortableInterceptor::ClientRequestInterceptor>::post_init (PortableInterceptor::ORBInitInfo* oii
                                                                            ACE_ENV_ARG_DECL_WITH_DEFAULTS)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    oii->add_client_request_interceptor (this->interceptor_.in ());
  };

  Client_Request_Interceptor::Client_Request_Interceptor (const char *orb_id,
                                                          TEST test)
    : orb_id_ (CORBA::string_dup (orb_id))
    , request_count_ (0)
    , requestID_ (1)
    , test_ (test)
  {
  }

  CORBA::Long
  Client_Request_Interceptor::interceptions (void)
  {
    return this->request_count_;
  }

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

  void
  Client_Request_Interceptor::test_transport_current (const ACE_TCHAR* amethod
                                                      ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     CORBA::UserException))
  {
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("CRI    (%P|%t) Test accessing Transport Current from %s\n"),
                amethod));

    ++this->request_count_;

    int tmp = 0;
    CORBA::ORB_var orb = CORBA::ORB_init (tmp,
                                          0,
                                          orb_id_.in ()
                                          ACE_ENV_ARG_PARAMETER);
    ACE_TRY_CHECK;


    (*this->test_) (orb.in () ACE_ENV_ARG_PARAMETER);
    ACE_TRY_CHECK;

    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("CRI    (%P|%t) Successfully tested Transport Current from %s\n"),
                amethod));
  }

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

  void
  Client_Request_Interceptor::send_request (PortableInterceptor::ClientRequestInfo_ptr ri
                                            ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     PortableInterceptor::ForwardRequest))
  {
    //Test TC

    test_transport_current ("send_request"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;

    CORBA::Boolean response_expected =
      ri->response_expected (ACE_ENV_SINGLE_ARG_PARAMETER);
    ACE_CHECK;

    // Oneway?
    if (response_expected)
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT("CRI    (%P|%t) Sending a two-way\n")));
    else
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT("CRI    (%P|%t) Sending a one-way\n")));

    // Make the context to send the context to the target

    IOP::ServiceContext sc;
    sc.context_id = TAO::Transport::CurrentTest::ContextTag;

    char temp[100];
    {
      ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);

      ACE_OS::sprintf (temp, "%d", this->requestID_);
      this->requestID_++;
    }

    CORBA::ULong string_len = ACE_OS::strlen (temp) + 1;
    CORBA::Octet *buf = CORBA::OctetSeq::allocbuf (string_len);
    ACE_OS::strcpy (ACE_reinterpret_cast (char *, buf), temp);

    sc.context_data.replace (string_len, string_len, buf, 1);

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

  }

  void
  Client_Request_Interceptor::send_poll (PortableInterceptor::ClientRequestInfo_ptr
                                         ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    test_transport_current ("send_poll"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;
  }

  void
  Client_Request_Interceptor::receive_reply (PortableInterceptor::ClientRequestInfo_ptr
                                             ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    test_transport_current ("receive_reply"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;
  }

  void
  Client_Request_Interceptor::receive_exception (PortableInterceptor::ClientRequestInfo_ptr
                                                 ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     PortableInterceptor::ForwardRequest))
  {
    test_transport_current ("receive_exception"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;
  }

  void
  Client_Request_Interceptor::receive_other (PortableInterceptor::ClientRequestInfo_ptr
                                             ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     PortableInterceptor::ForwardRequest))
  {

    test_transport_current ("receive_other"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;

  }

}
// -*- C++ -*-

#include "ace/Log_Msg.h"

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

#include "Current_TestC.h"
#include "Client_Request_Interceptor.h"
#include "ORBInitializer_T.h"

//   // A specialization to handle client-side interceptors
//   template <>
//   void ORBInitializer<PortableInterceptor::ClientRequestInterceptor>::post_init
//     (PortableInterceptor::ORBInitInfo* oii ACE_ENV_ARG_DECL_WITH_DEFAULTS)
//       ACE_THROW_SPEC ((CORBA::SystemException));


namespace Test
{

  using namespace TAO;

  // A specialization to handle client-side interceptors
  template <>
  void
  ORBInitializer<PortableInterceptor::ClientRequestInterceptor>::post_init (PortableInterceptor::ORBInitInfo* oii
                                                                            ACE_ENV_ARG_DECL_WITH_DEFAULTS)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    oii->add_client_request_interceptor (this->interceptor_.in ());
  };

  Client_Request_Interceptor::Client_Request_Interceptor (const char *orb_id,
                                                          TEST test)
    : orb_id_ (CORBA::string_dup (orb_id))
    , request_count_ (0)
    , requestID_ (1)
    , test_ (test)
  {
  }

  CORBA::Long
  Client_Request_Interceptor::interceptions (void)
  {
    return this->request_count_;
  }

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

  void
  Client_Request_Interceptor::test_transport_current (const ACE_TCHAR* amethod
                                                      ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     CORBA::UserException))
  {
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("CRI    (%P|%t) Test accessing Transport Current from %s\n"),
                amethod));

    ++this->request_count_;

    int tmp = 0;
    CORBA::ORB_var orb = CORBA::ORB_init (tmp,
                                          0,
                                          orb_id_.in ()
                                          ACE_ENV_ARG_PARAMETER);
    ACE_TRY_CHECK;


    (*this->test_) (orb.in () ACE_ENV_ARG_PARAMETER);
    ACE_TRY_CHECK;

    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("CRI    (%P|%t) Successfully tested Transport Current from %s\n"),
                amethod));
  }

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

  void
  Client_Request_Interceptor::send_request (PortableInterceptor::ClientRequestInfo_ptr ri
                                            ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     PortableInterceptor::ForwardRequest))
  {
    //Test TC

    test_transport_current ("send_request"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;

    CORBA::Boolean response_expected =
      ri->response_expected (ACE_ENV_SINGLE_ARG_PARAMETER);
    ACE_CHECK;

    // Oneway?
    if (response_expected)
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT("CRI    (%P|%t) Sending a two-way\n")));
    else
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT("CRI    (%P|%t) Sending a one-way\n")));

    // Make the context to send the context to the target

    IOP::ServiceContext sc;
    sc.context_id = TAO::Transport::CurrentTest::ContextTag;

    char temp[100];
    {
      ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);

      ACE_OS::sprintf (temp, "%d", this->requestID_);
      this->requestID_++;
    }

    CORBA::ULong string_len = ACE_OS::strlen (temp) + 1;
    CORBA::Octet *buf = CORBA::OctetSeq::allocbuf (string_len);
    ACE_OS::strcpy (ACE_reinterpret_cast (char *, buf), temp);

    sc.context_data.replace (string_len, string_len, buf, 1);

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

  }

  void
  Client_Request_Interceptor::send_poll (PortableInterceptor::ClientRequestInfo_ptr
                                         ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    test_transport_current ("send_poll"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;
  }

  void
  Client_Request_Interceptor::receive_reply (PortableInterceptor::ClientRequestInfo_ptr
                                             ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    test_transport_current ("receive_reply"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;
  }

  void
  Client_Request_Interceptor::receive_exception (PortableInterceptor::ClientRequestInfo_ptr
                                                 ACE_ENV_ARG_DECL_NOT_USED)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     PortableInterceptor::ForwardRequest))
  {
    test_transport_current ("receive_exception"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;
  }

  void
  Client_Request_Interceptor::receive_other (PortableInterceptor::ClientRequestInfo_ptr
                                             ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     PortableInterceptor::ForwardRequest))
  {

    test_transport_current ("receive_other"
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;

  }

}