1 #include "tao/ORB_Core.h"
2 #include "tao/ORBInitializer_Registry.h"
4 #include "tao/PI_Server/PI_Server.h"
5 #include "tao/PI/ORBInitInfo.h"
11 #pragma warning(disable:4250)
16 //------------------------------------------------------------------
17 // For simplicity most of the main variables are available GLOBALLY.
20 PortableInterceptor::Current_var PICurrent
;
21 PortableInterceptor::SlotId slot_id
= 2093843221;
22 testInterface_var server
;
24 void isCorrect (const CORBA::Any
&data
, const CORBA::Long correct
, const ACE_TCHAR
*const ID
)
26 CORBA::Long actual
= 0;
28 if (correct
== actual
)
30 ". %s retrieved CORRECT long (%d) from the TSC.\n",
35 ". %s retrieved **INCORRECT** long (%d should be %d) from TSC.\n",
36 ID
, actual
, correct
));
42 ". %s can't retrieved long from the TSC.\n",
48 //------------------------------------------------------------------
49 // Need either a Client OR Server OR BOTH Request Interceptors
50 // registered for the use of PICurrent to make sense in the application.
51 struct ClientRequestInterceptor
52 : public virtual PortableInterceptor::ClientRequestInterceptor
,
53 public virtual CORBA::LocalObject
56 ClientRequestInterceptor () {}
58 /// Return the name of this ClientRequestInterceptor.
59 virtual char * name ()
61 return CORBA::string_dup ("ClientRequestInterceptor");
64 virtual void destroy () {}
66 virtual void send_request (
67 PortableInterceptor::ClientRequestInfo_ptr
)
70 ". CLIENT Interception, send_request\n"));
73 virtual void send_poll (
74 PortableInterceptor::ClientRequestInfo_ptr
)
77 ". CLIENT Interception, send_poll\n"));
80 virtual void receive_reply (
81 PortableInterceptor::ClientRequestInfo_ptr
)
84 ". CLIENT Interception, receive_reply\n"));
87 virtual void receive_exception (
88 PortableInterceptor::ClientRequestInfo_ptr
)
91 ". CLIENT Interception, receive_exception\n"));
94 virtual void receive_other (
95 PortableInterceptor::ClientRequestInfo_ptr
)
98 ". CLIENT Interception, receive_other\n"));
102 //------------------------------------------------------------------
103 // This is our server side request interceptor.
104 // Need either a Client OR Server OR BOTH Request Interceptors
105 // registered for the use of PICurrent to make sense in the application.
106 struct ServerRequestInterceptor
107 : public virtual PortableInterceptor::ServerRequestInterceptor
,
108 public virtual CORBA::LocalObject
111 ServerRequestInterceptor () {}
113 /// Return the name of this ServerRequestinterceptor.
114 virtual char * name ()
116 return CORBA::string_dup ("ServerRequestInterceptor");
119 virtual void destroy () {}
121 #if TAO_HAS_EXTENDED_FT_INTERCEPTORS == 1
122 virtual void tao_ft_interception_point (
123 PortableInterceptor::ServerRequestInfo_ptr
,
126 ACE_DEBUG ((LM_DEBUG
,
127 ". SERVER Interception, tao_ft_interception_point\n"));
129 #endif // TAO_HAS_EXTENDED_FT_INTERCEPTORS == 1
131 virtual void receive_request_service_contexts (
132 PortableInterceptor::ServerRequestInfo_ptr
)
134 ACE_DEBUG ((LM_DEBUG
,
135 ". SERVER Interception, receive_request_service_contexts\n"));
138 virtual void receive_request (
139 PortableInterceptor::ServerRequestInfo_ptr
)
141 ACE_DEBUG ((LM_DEBUG
,
142 ". SERVER Interception, receive_request\n"));
145 virtual void send_reply (
146 PortableInterceptor::ServerRequestInfo_ptr
)
148 ACE_DEBUG ((LM_DEBUG
,
149 ". SERVER Interception, send_reply\n"));
152 virtual void send_exception (
153 PortableInterceptor::ServerRequestInfo_ptr
)
155 ACE_DEBUG ((LM_DEBUG
,
156 ". SERVER Interception, send_exception\n"));
159 virtual void send_other (
160 PortableInterceptor::ServerRequestInfo_ptr
)
162 ACE_DEBUG ((LM_DEBUG
,
163 ". SERVER Interception, send_other\n"));
167 //------------------------------------------------------------------
168 // This is the test ORB initializer that registers the IORInterceptor
170 class MyORBInitializer
:
171 public virtual PortableInterceptor::ORBInitializer
,
172 public virtual CORBA::LocalObject
175 ~MyORBInitializer() {slot_id
= 2093843221;} // Invalidate slot
176 /// The pre-initialization hook.
177 virtual void pre_init (
178 PortableInterceptor::ORBInitInfo_ptr
)
181 /// The post-initialization hook.
182 virtual void post_init (
183 PortableInterceptor::ORBInitInfo_ptr info
)
186 obj
= info
->resolve_initial_references ("PICurrent");
187 PICurrent
= PortableInterceptor::Current::_narrow (obj
.in ());
188 if (CORBA::is_nil (PICurrent
.in ()))
190 ACE_ERROR ((LM_ERROR
,
191 "ERROR: Could not resolve PICurrent object.\n"));
192 throw ::CORBA::INTERNAL ();
194 slot_id
= info
->allocate_slot_id ();
196 // Need either a Client OR Server OR BOTH Request Interceptors
197 // Registered for the use of PICurrent to make sense in the application.
198 PortableInterceptor::ClientRequestInterceptor_ptr client_tmp
;
199 ACE_NEW_THROW_EX (client_tmp
,
200 ClientRequestInterceptor (),
202 CORBA::SystemException::_tao_minor_code (
205 CORBA::COMPLETED_NO
));
206 PortableInterceptor::ClientRequestInterceptor_var
207 client_interceptor
= client_tmp
;
208 info
->add_client_request_interceptor (client_interceptor
.in ());
210 // Need either a Client OR Server OR BOTH Request Interceptors
211 // Registered for the use of PICurrent to make sense in the application.
212 PortableInterceptor::ServerRequestInterceptor_ptr server_tmp
;
213 ACE_NEW_THROW_EX (server_tmp
,
214 ServerRequestInterceptor
,
216 CORBA::SystemException::_tao_minor_code (
219 CORBA::COMPLETED_NO
));
220 PortableInterceptor::ServerRequestInterceptor_var
221 server_interceptor
= server_tmp
;
222 info
->add_server_request_interceptor (server_interceptor
.in ());
224 // Disable collocation identification -- TAO-specific!!!
225 // The fix needs to work even if collocation is not optomized for.
227 tao_info
= TAO_ORBInitInfo::_narrow (info
);
228 tao_info
->orb_core ()->optimize_collocation_objects (0);
232 //------------------------------------------------------------------
233 // This is the implimentation of our test server.
234 class testInterface_i
: public virtual POA_testInterface
237 /// Constructor & Destructor.
238 testInterface_i () {}
239 ~testInterface_i () {}
240 /// Main servant test methods.
241 virtual void firstCalling ()
243 // Insert some data into the allocated PICurrent slot BEFORE we start.
245 CORBA::Long number
= 2; // Different from the client's data
247 PICurrent
.in()->set_slot (slot_id
, data
);
248 ACE_DEBUG ((LM_DEBUG
,
249 ". SERVER firstCalling() stored long (%d) to TSC.\n",
251 // Perform the next nested collocated call.
252 server
->secondCalling();
253 // Check that the data in the PICurrent slot has not been corrupted.
254 CORBA::Any_var data2
= PICurrent
.in()->get_slot (slot_id
);
255 isCorrect (data2
.in (), 2, ACE_TEXT ("SERVER firstCalling()"));
257 virtual void secondCalling ()
259 // Insert some data into the allocated PICurrent slot.
261 CORBA::Long number
= 3; // Different from other server's data
263 PICurrent
.in()->set_slot (slot_id
, data
);
264 ACE_DEBUG ((LM_DEBUG
,
265 ". SERVER secondCalling() stored long (%d) to TSC.\n",
271 #if defined(_MSC_VER)
273 #endif /* _MSC_VER */
275 //------------------------------------------------------------------
277 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
281 // Initialise the ORBInitializer for server side interception points
282 PortableInterceptor::ORBInitializer_ptr
283 temp_initializer
= PortableInterceptor::ORBInitializer::_nil ();
284 ACE_NEW_RETURN (temp_initializer
,
286 -1); // No CORBA exceptions yet we haven't yet ORB_init!
287 PortableInterceptor::ORBInitializer_var
288 orb_initializer
= temp_initializer
;
289 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
291 // Start up the ORB and start the POAManager
294 guardORB(int argc
, ACE_TCHAR
*argv
[])
295 {orb
= CORBA::ORB_init (argc
, argv
, "test_orb");}
296 ~guardORB() {PICurrent
= 0; orb
= 0;}
297 } guardORB_(argc
, argv
);
300 obj
= orb
->resolve_initial_references ("RootPOA");
301 PortableServer::POA_var
302 RootPOA
= PortableServer::POA::_narrow (obj
.in ());
303 if (CORBA::is_nil (RootPOA
.in ()))
304 ACE_ERROR_RETURN ((LM_ERROR
,
305 "Unable to obtain RootPOA reference.\n"),
307 PortableServer::POAManager_var
308 POAManager
= RootPOA
->the_POAManager ();
309 if (CORBA::is_nil (POAManager
.in ()))
310 ACE_ERROR_RETURN ((LM_ERROR
,
311 "Unable to obtain POAManager reference.\n"),
313 POAManager
->activate ();
315 // OK now start our collocated client/server and activate it on the default POA
316 testInterface_i
*testInt
;
317 ACE_NEW_THROW_EX (testInt
,
320 CORBA::SystemException::_tao_minor_code (
323 CORBA::COMPLETED_NO
));
324 PortableServer::ServantBase_var
325 server_impl
= testInt
;
326 obj
= testInt
->_this ();
329 serverGuard(CORBA::Object_ptr obj
)
330 {server
= testInterface::_narrow (obj
);}
331 ~serverGuard() {server
= 0;}
332 } serverGuard_ (obj
.in ());
333 if (CORBA::is_nil (server
.in ()))
334 ACE_ERROR_RETURN ((LM_ERROR
,
335 "Unable to obtain reference to testInterface object.\n"),
338 ACE_DEBUG ((LM_DEBUG
, "Start of actual regression test...\n"));
339 // Insert some data into the allocated PICurrent slot BEFORE we start.
341 CORBA::Long number
= 1;
343 PICurrent
.in ()->set_slot (slot_id
, data
);
344 ACE_DEBUG ((LM_DEBUG
,
345 ". CLIENT stored long (%d) to TSC.\n",
347 // Perform the collocated call.
348 server
->firstCalling();
349 // Check that the data in the PICurrent slot has not been corrupted.
350 CORBA::Any_var data2
= PICurrent
.in ()->get_slot (slot_id
);
351 isCorrect (data2
.in (), 1, ACE_TEXT ("CLIENT"));
352 ACE_DEBUG ((LM_DEBUG
, "End of actual regression test...\n"));
354 RootPOA
->destroy (1, 1);
357 catch (const ::CORBA::Exception
&ex
)
359 ex
._tao_print_exception ("Corba exception");
364 ACE_DEBUG ((LM_DEBUG
, "Unknown exception caught\n"));
368 ACE_DEBUG ((LM_DEBUG
,
371 ACE_TEXT ("***FAILURE***") :
372 ACE_TEXT ("Success"))));