summaryrefslogtreecommitdiff
path: root/TAO/tests/Portable_Interceptors/PICurrent/ClientRequestInterceptor.cpp
blob: 69042d4326fda32de583da30488d587a98cdb05b (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
#include "ClientRequestInterceptor.h"

#include "tao/CORBA_String.h"

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


ACE_RCSID (PICurrent,
           ClientRequestInterceptor,
           "$Id$")


ClientRequestInterceptor::ClientRequestInterceptor (
  PortableInterceptor::SlotId id,
  PortableInterceptor::Current_ptr pi_current)
  : slot_id_ (id),
    pi_current_ (PortableInterceptor::Current::_duplicate (pi_current))
{
}

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

void
ClientRequestInterceptor::destroy (void)
{
}

void
ClientRequestInterceptor::send_request (
      PortableInterceptor::ClientRequestInfo_ptr ri)
{
  CORBA::String_var op = ri->operation ();

  if (ACE_OS::strcmp (op.in (), "invoke_me") != 0)
    return; // Don't mess with PICurrent if not invoking test method.

  try
    {
      // Retrieve data from the RSC (request scope current).
      CORBA::Long number = 0;

      CORBA::Any_var data =
        ri->get_slot (this->slot_id_);

      if (!(data.in () >>= number))
        {
          ACE_ERROR ((LM_ERROR,
                      "(%P|%t) ERROR: Unable to extract data from Any.\n"));

          throw CORBA::INTERNAL ();
        }

      ACE_DEBUG ((LM_DEBUG,
                  "(%P|%t) Extracted <%d> from RSC slot %u\n",
                  number,
                  this->slot_id_));

      CORBA::Any new_data;
      CORBA::String_var s = CORBA::string_dup ("Et tu Brute?");

      new_data <<= s.in ();

      // Now reset the contents of our slot in the thread-scope
      // current (TSC).
      this->pi_current_->set_slot (this->slot_id_,
                                   new_data);

      // Now retrieve the data from the RSC again.  It should not have
      // changed!
      CORBA::Long number2 = -1;

      CORBA::Any_var data2 =
        ri->get_slot (this->slot_id_);

      if (!(data2.in () >>= number2)
          || number != number2)
        {
          ACE_ERROR ((LM_ERROR,
                      "(%P|%t) ERROR: RSC was modified after "
                      "TSC was modified.\n"));

          throw CORBA::INTERNAL ();
        }

    }
  catch (const PortableInterceptor::InvalidSlot& ex)
    {
      ex._tao_print_exception ("Exception thrown in ""send_request()\n");

      ACE_DEBUG ((LM_DEBUG,
                  "Invalid slot: %u\n",
                  this->slot_id_));

      throw CORBA::INTERNAL ();
    }

  ACE_DEBUG ((LM_INFO,
              "(%P|%t) Client side RSC/TSC semantics appear "
              "to be correct.\n"));
}

void
ClientRequestInterceptor::send_poll (
    PortableInterceptor::ClientRequestInfo_ptr)
{
}

void
ClientRequestInterceptor::receive_reply (
    PortableInterceptor::ClientRequestInfo_ptr)
{
}

void
ClientRequestInterceptor::receive_exception (
    PortableInterceptor::ClientRequestInfo_ptr)
{
}

void
ClientRequestInterceptor::receive_other (
    PortableInterceptor::ClientRequestInfo_ptr)
{
}