Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / PICurrent / test_i.cpp
blob7f6dd624104f848755bec4521bda4a5cf4fdfa2e
1 // -*- C++ -*-
2 #include "test_i.h"
4 test_i::test_i (PortableInterceptor::Current_ptr current,
5 PortableInterceptor::SlotId id,
6 CORBA::ORB_ptr orb)
7 : current_ (PortableInterceptor::Current::_duplicate (current)),
8 slot_id_ (id),
9 orb_ (CORBA::ORB::_duplicate (orb))
13 test_i::~test_i (void)
17 void
18 test_i::invoke_me (void)
20 ACE_DEBUG ((LM_DEBUG,
21 "Test method invoked.\n"));
23 // @note "TSC" is "thread scope current"
24 // "RSC" is "request scope current"
26 // ----------------------------------------------------
28 // Verify that the following RSC->TSC->RSC copying scenario works:
30 // 1. ServerRequestInterceptor::receive_request_service_contexts()
31 // a. ServerRequestInfo::set_slot()
32 // b. RSC->TSC shallow copy
33 // 2. servant implementation invokes method on another server
34 // a. TSC->RSC shallow copy
35 // b. ClientRequestInterceptor::send_request()
36 // i. ClientRequestInfo::get_slot()
38 // By this point all of step 1 has occurred. Step 2 will now
39 // occur.
40 PICurrentTest::test_var my_ref = this->_this ();
42 // ----------------------------------------------------
44 CORBA::Any_var retrieved_any;
46 try
48 // Retrieve data placed into RSC PICurrent by the
49 // receive_request_service_contexts() interception point, and
50 // then copied into the TSC current.
51 retrieved_any =
52 this->current_->get_slot (this->slot_id_);
54 catch (const PortableInterceptor::InvalidSlot& ex)
56 ex._tao_print_exception (
57 "Exception thrown in ""test_i::invoke_me() when calling ""Current::get_slot\n");
59 ACE_DEBUG ((LM_DEBUG,
60 "Invalid slot: %u\n",
61 this->slot_id_));
63 throw CORBA::INTERNAL ();
65 catch (const CORBA::Exception& ex)
67 ex._tao_print_exception ("Unexpected exception\n");
70 CORBA::Long retrieved;
71 if (retrieved_any.in() >>= retrieved)
72 ACE_DEBUG ((LM_DEBUG,
73 "(%P|%t) Retrieved number <%d> from TSC.\n",
74 retrieved));
75 else
77 ACE_DEBUG ((LM_DEBUG,
78 "(%P|%t) Problem extracting data from "
79 "CORBA::Any retrieved from TSC.\n"));
81 throw CORBA::INTERNAL ();
83 // ----------------------------------------------------
85 // Note that the invocation must occur through the object
86 // reference to force the client request interceptor
87 // (ClientRequestInterceptor2) to be invoked. This assumes that
88 // DIRECT collocation (and possibly THRU_POA collocation) is
89 // disabled.
90 my_ref->invoke_you ();
92 // ----------------------------------------------------
94 // Insert some data into the TSC PICurrent object.
95 const char str[] = "Drink milk!";
97 CORBA::Any data;
99 data <<= str;
103 this->current_->set_slot (this->slot_id_,
104 data);
106 catch (const PortableInterceptor::InvalidSlot& ex)
108 ex._tao_print_exception (
109 "Exception thrown in ""test_i::invoke_me() when calling ""Current::set_slot\n");
111 ACE_DEBUG ((LM_DEBUG,
112 "Invalid slot: %u\n",
113 this->slot_id_));
115 throw CORBA::INTERNAL ();
118 ACE_DEBUG ((LM_DEBUG,
119 "(%P|%t) String \"%C\" inserted into TSC.\n",
120 str));
123 void
124 test_i::invoke_you (void)
126 // Nothing to be tested here. This method is here just so that we
127 // have a different method
130 void
131 test_i::invoke_we (void)
133 // Insert some data into the TSC PICurrent object.
134 const char str[] = "We drink milk!";
136 CORBA::Any data;
138 data <<= str;
142 this->current_->set_slot (this->slot_id_,
143 data);
145 catch (const PortableInterceptor::InvalidSlot& ex)
147 ex._tao_print_exception (
148 "Exception thrown in ""test_i::invoke_me() when calling ""Current::set_slot\n");
150 ACE_DEBUG ((LM_DEBUG,
151 "Invalid slot: %u\n",
152 this->slot_id_));
154 throw CORBA::INTERNAL ();
157 ACE_DEBUG ((LM_DEBUG,
158 "(%P|%t) String \"%C\" inserted into TSC.\n",
159 str));
162 void
163 test_i::shutdown (void)
165 ACE_DEBUG ((LM_DEBUG,
166 "(%P|%t) Server is shutting down.\n"));
168 this->orb_->shutdown (0);