summaryrefslogtreecommitdiff
path: root/tests/Portable_Interceptors/PICurrent/test_i.cpp
blob: b2b72b018a49419274fbe0986f932512be4c348f (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
// -*- C++ -*-
// $Id$

#include "test_i.h"

test_i::test_i (PortableInterceptor::Current_ptr current,
                PortableInterceptor::SlotId id,
                CORBA::ORB_ptr orb)
  : current_ (PortableInterceptor::Current::_duplicate (current)),
    slot_id_ (id),
    orb_ (CORBA::ORB::_duplicate (orb))
{
}

test_i::~test_i (void)
{
}

void
test_i::invoke_me (void)
{
  ACE_DEBUG ((LM_DEBUG,
              "Test method invoked.\n"));

  // @note "TSC" is "thread scope current"
  //       "RSC" is "request scope current"

  // ----------------------------------------------------

  // Verify that the following RSC->TSC->RSC copying scenario works:
  //
  // 1.    ServerRequestInterceptor::receive_request_service_contexts()
  //   a.       ServerRequestInfo::set_slot()
  //   b.       RSC->TSC shallow copy
  // 2.    servant implementation invokes method on another server
  //   a.       TSC->RSC shallow copy
  //   b.       ClientRequestInterceptor::send_request()
  //     i.          ClientRequestInfo::get_slot()

  // By this point all of step 1 has occurred.  Step 2 will now
  // occur.
  PICurrentTest::test_var my_ref = this->_this ();

  // ----------------------------------------------------

  CORBA::Any_var retrieved_any;

  try
    {
      // Retrieve data placed into RSC PICurrent by the
      // receive_request_service_contexts() interception point, and
      // then copied into the TSC current.
      retrieved_any =
        this->current_->get_slot (this->slot_id_);
    }
  catch (const PortableInterceptor::InvalidSlot& ex)
    {
      ex._tao_print_exception (
        "Exception thrown in ""test_i::invoke_me() when calling ""Current::get_slot\n");

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

      throw CORBA::INTERNAL ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Unexpected exception\n");
    }

  CORBA::Long retrieved;
  if (retrieved_any.in() >>= retrieved)
    ACE_DEBUG ((LM_DEBUG,
                "(%P|%t) Retrieved number <%d> from TSC.\n",
                retrieved));
  else
    {
      ACE_DEBUG ((LM_DEBUG,
                  "(%P|%t) Problem extracting data from "
                  "CORBA::Any retrieved from TSC.\n"));

      throw CORBA::INTERNAL ();
    }
  // ----------------------------------------------------

  // Note that the invocation must occur through the object
  // reference to force the client request interceptor
  // (ClientRequestInterceptor2) to be invoked.  This assumes that
  // DIRECT collocation (and possibly THRU_POA collocation) is
  // disabled.
  my_ref->invoke_you ();

  // ----------------------------------------------------

  // Insert some data into the TSC PICurrent object.
  const char str[] = "Drink milk!";

  CORBA::Any data;

  data <<= str;

  try
    {
      this->current_->set_slot (this->slot_id_,
                                data);
    }
  catch (const PortableInterceptor::InvalidSlot& ex)
    {
      ex._tao_print_exception (
        "Exception thrown in ""test_i::invoke_me() when calling ""Current::set_slot\n");

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

      throw CORBA::INTERNAL ();
    }

  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) String \"%C\" inserted into TSC.\n",
              str));
}

void
test_i::invoke_you (void)
{
  // Nothing to be tested here.  This method is here just so that we
  // have a different method
}

void
test_i::invoke_we (void)
{
  // Insert some data into the TSC PICurrent object.
  const char str[] = "We drink milk!";

  CORBA::Any data;

  data <<= str;

  try
    {
      this->current_->set_slot (this->slot_id_,
                                data);
    }
  catch (const PortableInterceptor::InvalidSlot& ex)
    {
      ex._tao_print_exception (
        "Exception thrown in ""test_i::invoke_me() when calling ""Current::set_slot\n");

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

      throw CORBA::INTERNAL ();
    }

  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) String \"%C\" inserted into TSC.\n",
              str));
}

void
test_i::shutdown (void)
{
  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Server is shutting down.\n"));

  this->orb_->shutdown (0);
}