Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / PICurrent / ServerRequestInterceptor.cpp
blobbc573411f0a806a7a3a35b7f31aad0440340d036
1 // -*- C++ -*-
2 #include "ServerRequestInterceptor.h"
3 #include "tao/CORBA_String.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_string.h"
7 ServerRequestInterceptor::ServerRequestInterceptor (
8 PortableInterceptor::SlotId id,
9 PortableInterceptor::Current_ptr pi_current)
10 : slot_id_ (id),
11 pi_current_ (PortableInterceptor::Current::_duplicate (pi_current))
15 char *
16 ServerRequestInterceptor::name ()
18 return CORBA::string_dup ("ServerRequestInterceptor");
21 void
22 ServerRequestInterceptor::destroy ()
26 void
27 ServerRequestInterceptor::receive_request_service_contexts (
28 PortableInterceptor::ServerRequestInfo_ptr ri)
30 CORBA::String_var op = ri->operation ();
32 if (ACE_OS::strcmp (op.in (), "invoke_me") != 0)
33 return; // Don't mess with PICurrent if not invoking test method.
35 try
37 // Insert data into the RSC (request scope current).
39 CORBA::Long number = 62;
41 CORBA::Any data;
42 data <<= number;
44 ri->set_slot (this->slot_id_, data);
46 ACE_DEBUG ((LM_DEBUG,
47 "(%P|%t) Inserted number <%d> into RSC.\n",
48 number));
50 catch (const PortableInterceptor::InvalidSlot& ex)
52 ex._tao_print_exception (
53 "Exception thrown in ""receive_request_service_contexts()\n");
55 ACE_DEBUG ((LM_DEBUG,
56 "Invalid slot: %u\n",
57 this->slot_id_));
59 throw CORBA::INTERNAL ();
63 void
64 ServerRequestInterceptor::receive_request (
65 PortableInterceptor::ServerRequestInfo_ptr ri)
67 try
69 CORBA::Any new_data;
70 CORBA::Long number = 19;
71 new_data <<= number;
73 // Set a value in RSC, this should not effect TSC anymore
74 ri->set_slot (this->slot_id_,
75 new_data);
77 // Now retrieve the data from the TSC again. It should not have
78 // changed to the new value
79 CORBA::Any_var data2 =
80 this->pi_current_->get_slot (this->slot_id_);
82 CORBA::Long number2 = 0;
83 if ((data2.in () >>= number2)
84 && number == number2)
86 ACE_ERROR ((LM_ERROR,
87 "(%P|%t) ERROR: TSC was modified because "
88 "RSC was modified.\n"));
90 throw CORBA::INTERNAL ();
93 catch (const PortableInterceptor::InvalidSlot& ex)
95 ex._tao_print_exception ("Exception thrown in ""send_reply()\n");
97 ACE_DEBUG ((LM_DEBUG,
98 "Invalid slot: %u\n",
99 this->slot_id_));
101 throw CORBA::INTERNAL ();
104 ACE_DEBUG ((LM_INFO,
105 "(%P|%t) Server side RSC/TSC semantics appear "
106 "to be correct.\n"));
109 void
110 ServerRequestInterceptor::send_reply (
111 PortableInterceptor::ServerRequestInfo_ptr ri)
113 CORBA::String_var op = ri->operation ();
115 if (ACE_OS::strcmp (op.in (), "invoke_me") != 0)
116 return; // Don't mess with PICurrent if not invoking test method.
120 CORBA::Any_var data;
122 // Retrieve the data stored in the RSC. This data (a string)
123 // should be different from the original data (a CORBA::Long)
124 // stored into the RSC by the receive_request_service_contexts()
125 // interception point.
126 data = ri->get_slot (this->slot_id_);
128 // The original data in the RSC was of type CORBA::Long. If the
129 // following extraction from the CORBA::Any fails, then the
130 // original data in the RSC was not replaced with the data in
131 // the TSC after the test method completed.
132 const char *str = 0;
133 if (data.in () >>= str)
135 ACE_DEBUG ((LM_DEBUG,
136 "(%P|%t) Retrieved \"%s\" from the RSC.\n",
137 str));
139 else
141 ACE_DEBUG ((LM_DEBUG,
142 "(%P|%t) Unable to extract data (a string) "
143 "from the RSC.\n"));
145 throw CORBA::INTERNAL ();
148 // Now verify that the RSC is truly independent of the TSC. In
149 // particular, modifying the TSC at this point should not cause
150 // the RSC to be modified.
151 CORBA::Any new_data;
152 CORBA::Long number = 19;
154 new_data <<= number;
156 // Now reset the contents of our slot in the thread-scope
157 // current (TSC).
158 this->pi_current_->set_slot (this->slot_id_,
159 new_data);
161 // Now retrieve the data from the RSC again. It should not have
162 // changed!
163 CORBA::Any_var data2 =
164 ri->get_slot (this->slot_id_);
166 const char *str2 = 0;
167 if (!(data2.in () >>= str2)
168 || ACE_OS::strcmp (str, str2) != 0)
170 ACE_ERROR ((LM_ERROR,
171 "(%P|%t) ERROR: RSC was modified after "
172 "TSC was modified.\n"));
174 throw CORBA::INTERNAL ();
177 catch (const PortableInterceptor::InvalidSlot& ex)
179 ex._tao_print_exception ("Exception thrown in ""send_reply()\n");
181 ACE_DEBUG ((LM_DEBUG,
182 "Invalid slot: %u\n",
183 this->slot_id_));
185 throw CORBA::INTERNAL ();
188 ACE_DEBUG ((LM_INFO,
189 "(%P|%t) Server side RSC/TSC semantics appear "
190 "to be correct.\n"));
193 void
194 ServerRequestInterceptor::send_exception (
195 PortableInterceptor::ServerRequestInfo_ptr)
199 void
200 ServerRequestInterceptor::send_other (
201 PortableInterceptor::ServerRequestInfo_ptr)