Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / PICurrent / ServerRequestInterceptor.cpp
blob74b6a11a33f4e4060e4af95af8f3e26c1aaa8e06
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 (void)
18 return CORBA::string_dup ("ServerRequestInterceptor");
21 void
22 ServerRequestInterceptor::destroy (void)
26 void
27 ServerRequestInterceptor::receive_request_service_contexts (
28 PortableInterceptor::ServerRequestInfo_ptr ri)
31 CORBA::String_var op = ri->operation ();
33 if (ACE_OS::strcmp (op.in (), "invoke_me") != 0)
34 return; // Don't mess with PICurrent if not invoking test method.
36 try
38 // Insert data into the RSC (request scope current).
40 CORBA::Long number = 62;
42 CORBA::Any data;
43 data <<= number;
45 ri->set_slot (this->slot_id_, data);
47 ACE_DEBUG ((LM_DEBUG,
48 "(%P|%t) Inserted number <%d> into RSC.\n",
49 number));
51 catch (const PortableInterceptor::InvalidSlot& ex)
53 ex._tao_print_exception (
54 "Exception thrown in ""receive_request_service_contexts()\n");
56 ACE_DEBUG ((LM_DEBUG,
57 "Invalid slot: %u\n",
58 this->slot_id_));
60 throw CORBA::INTERNAL ();
64 void
65 ServerRequestInterceptor::receive_request (
66 PortableInterceptor::ServerRequestInfo_ptr ri)
68 try
70 CORBA::Any new_data;
71 CORBA::Long number = 19;
72 new_data <<= number;
74 // Set a value in RSC, this should not effect TSC anymore
75 ri->set_slot (this->slot_id_,
76 new_data);
78 // Now retrieve the data from the TSC again. It should not have
79 // changed to the new value
80 CORBA::Any_var data2 =
81 this->pi_current_->get_slot (this->slot_id_);
83 CORBA::Long number2 = 0;
84 if ((data2.in () >>= number2)
85 && number == number2)
87 ACE_ERROR ((LM_ERROR,
88 "(%P|%t) ERROR: TSC was modified because "
89 "RSC was modified.\n"));
91 throw CORBA::INTERNAL ();
94 catch (const PortableInterceptor::InvalidSlot& ex)
96 ex._tao_print_exception ("Exception thrown in ""send_reply()\n");
98 ACE_DEBUG ((LM_DEBUG,
99 "Invalid slot: %u\n",
100 this->slot_id_));
102 throw CORBA::INTERNAL ();
105 ACE_DEBUG ((LM_INFO,
106 "(%P|%t) Server side RSC/TSC semantics appear "
107 "to be correct.\n"));
111 void
112 ServerRequestInterceptor::send_reply (
113 PortableInterceptor::ServerRequestInfo_ptr ri)
116 CORBA::String_var op = ri->operation ();
118 if (ACE_OS::strcmp (op.in (), "invoke_me") != 0)
119 return; // Don't mess with PICurrent if not invoking test method.
123 CORBA::Any_var data;
125 // Retrieve the data stored in the RSC. This data (a string)
126 // should be different from the original data (a CORBA::Long)
127 // stored into the RSC by the receive_request_service_contexts()
128 // interception point.
129 data = ri->get_slot (this->slot_id_);
131 // The original data in the RSC was of type CORBA::Long. If the
132 // following extraction from the CORBA::Any fails, then the
133 // original data in the RSC was not replaced with the data in
134 // the TSC after the test method completed.
135 const char *str = 0;
136 if (data.in () >>= str)
138 ACE_DEBUG ((LM_DEBUG,
139 "(%P|%t) Retrieved \"%s\" from the RSC.\n",
140 str));
142 else
144 ACE_DEBUG ((LM_DEBUG,
145 "(%P|%t) Unable to extract data (a string) "
146 "from the RSC.\n"));
148 throw CORBA::INTERNAL ();
151 // Now verify that the RSC is truly independent of the TSC. In
152 // particular, modifying the TSC at this point should not cause
153 // the RSC to be modified.
154 CORBA::Any new_data;
155 CORBA::Long number = 19;
157 new_data <<= number;
159 // Now reset the contents of our slot in the thread-scope
160 // current (TSC).
161 this->pi_current_->set_slot (this->slot_id_,
162 new_data);
164 // Now retrieve the data from the RSC again. It should not have
165 // changed!
166 CORBA::Any_var data2 =
167 ri->get_slot (this->slot_id_);
169 const char *str2 = 0;
170 if (!(data2.in () >>= str2)
171 || ACE_OS::strcmp (str, str2) != 0)
173 ACE_ERROR ((LM_ERROR,
174 "(%P|%t) ERROR: RSC was modified after "
175 "TSC was modified.\n"));
177 throw CORBA::INTERNAL ();
180 catch (const PortableInterceptor::InvalidSlot& ex)
182 ex._tao_print_exception ("Exception thrown in ""send_reply()\n");
184 ACE_DEBUG ((LM_DEBUG,
185 "Invalid slot: %u\n",
186 this->slot_id_));
188 throw CORBA::INTERNAL ();
191 ACE_DEBUG ((LM_INFO,
192 "(%P|%t) Server side RSC/TSC semantics appear "
193 "to be correct.\n"));
196 void
197 ServerRequestInterceptor::send_exception (
198 PortableInterceptor::ServerRequestInfo_ptr)
202 void
203 ServerRequestInterceptor::send_other (
204 PortableInterceptor::ServerRequestInfo_ptr)