More tests update
[ACE_TAO.git] / TAO / tests / Bug_2234_Regression / server.cpp
blob0fc3e0396fa292b7d9bffcf9ad0b44b8f9ab97da
1 // Regression test Bug 2234
2 //
3 // The bug actually manifested itself in class AnInterceptor::receive_request()
4 // where any OUT parameters of variable length items (as they are held as
5 // addresses of NULL pointers)
6 //
7 // The bug is caused by the arguments() call which should be
8 // creating a read-only COPY of the parameters to the call. These are held as
9 // a sequence of ANYs, whith the code for the insertion into which is created
10 // by the TAO_IDL compiler when their user types are compiled.
11 // It is also manifested by the result() call in the same way.
13 #include "TestS.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/IOStream.h"
16 #include "tao/PI/PI.h"
17 #include "tao/PI_Server/PI_Server.h"
18 #include "tao/ORBInitializer_Registry.h"
19 #include "tao/PortableServer/Root_POA.h"
20 #include "tao/LocalObject.h"
22 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
24 int
25 parse_args (int argc, ACE_TCHAR *argv[])
27 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
28 int c;
30 while ((c = get_opts ()) != -1)
31 switch (c)
33 case 'o':
34 ior_output_file = get_opts.opt_arg ();
35 break;
37 case '?':
38 default:
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "usage: %s "
41 "-o <iorfile>"
42 "\n",
43 argv [0]),
44 -1);
46 // Indicates successful parsing of the command line
47 return 0;
50 CORBA::ORB_ptr orb;
52 // The test case code for the server always sends back to the client:
53 // b(out)= a(in) *2
54 // c(inout)= c(inout) + 1
55 // return= 7
56 // Strings are single numerical digits, longs are the numbers themselves
57 // and sequences are always single long values.
58 // Parameter 'a' must be received from the client as 1, and 'c' as 3.
60 class FooImpl : public POA_Test::Foo
62 public:
63 FooImpl() {}
64 ~FooImpl() {}
66 //-----------------------------------------------------------
68 CORBA::Long TestLong(
69 CORBA::Long a,
70 CORBA::Long_out b,
71 CORBA::Long &c
74 ACE_DEBUG( (LM_INFO, ". in TestLong\n") );
75 if (static_cast<CORBA::Long>( 1 ) != a)
77 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
78 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
80 if (static_cast<CORBA::Long>( 3 ) != c)
82 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
83 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
86 b= static_cast<CORBA::Long>( a << 1 );
88 c+= static_cast<CORBA::Long>( 1 );
89 return static_cast<CORBA::Long>( 7 );
92 //-----------------------------------------------------------
94 char *TestString(
95 const char *a,
96 CORBA::String_out b,
97 char *&c
100 ACE_DEBUG( (LM_INFO, ". in TestString\n") );
101 if (0 == a)
103 //FUZZ: disable check_for_NULL
104 ACE_DEBUG( (LM_INFO, "* Incorrect NULL string given for parameter a\n") );
105 //FUZZ: enable check_for_NULL
106 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
108 if (1 != ACE_OS::strlen( a ))
110 ACE_DEBUG( (LM_INFO, "* Incorrect string length for parameter a\n") );
111 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
113 if ('1' != *a)
115 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
116 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
118 if (0 == c)
120 //FUZZ: disable check_for_NULL
121 ACE_DEBUG( (LM_INFO, "* Incorrect NULL string given for parameter c\n") );
122 //FUZZ: enable check_for_NULL
123 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
125 if (1 != ACE_OS::strlen( c ))
127 ACE_DEBUG( (LM_INFO, "* Incorrect string length for parameter c\n") );
128 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
130 if ('3' != *c)
132 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
133 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
136 b= CORBA::string_dup( "0" ); // Create a one character output buffer
137 *b= a[0] + 1;
138 *c+= 1;
139 return CORBA::string_dup( "7" );
142 //-----------------------------------------------------------
144 Test::MyNonVarStruct TestNonVarStruct(
145 const Test::MyNonVarStruct &a,
146 Test::MyNonVarStruct_out b,
147 Test::MyNonVarStruct &c
150 Test::MyNonVarStruct
151 newret;
153 ACE_DEBUG( (LM_INFO, ". in TestNonVarStruct\n") );
154 if (static_cast<CORBA::Long>( 1 ) != a.val)
156 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
157 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
159 if (static_cast<CORBA::Long>( 3 ) != c.val)
161 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
162 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
165 newret.val= static_cast<CORBA::Long>( 7 );
167 Test::MyNonVarStruct *newval_p;
168 ACE_NEW_RETURN( newval_p, Test::MyNonVarStruct, newret );
169 Test::MyNonVarStruct_var
170 newval= newval_p;
172 newval->val= a.val << 1;
173 c.val+= 1;
175 b= newval._retn();
176 return newret;
179 //-----------------------------------------------------------
181 Test::MyVarStruct *TestVarStruct(
182 const Test::MyVarStruct &a,
183 Test::MyVarStruct_out b,
184 Test::MyVarStruct &c
187 ACE_DEBUG( (LM_INFO, ". in TestVarStruct\n") );
188 if (0 == a.val.in())
190 //FUZZ: disable check_for_NULL
191 ACE_DEBUG( (LM_INFO, "* Incorrect NULL string given for parameter a\n") );
192 //FUZZ: enable check_for_NULL
193 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
195 if (1 != ACE_OS::strlen( a.val.in() ))
197 ACE_DEBUG( (LM_INFO, "* Incorrect string length for parameter a\n") );
198 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
200 if ('1' != *a.val.in())
202 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
203 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
205 if (0 == c.val.in())
207 //FUZZ: disable check_for_NULL
208 ACE_DEBUG( (LM_INFO, "* Incorrect NULL string given for parameter c\n") );
209 //FUZZ: enable check_for_NULL
210 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
212 if (1 != ACE_OS::strlen( c.val.in() ))
214 ACE_DEBUG( (LM_INFO, "* Incorrect string length for parameter c\n") );
215 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
217 if ('3' != *c.val.in())
219 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
220 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
223 char ca[2]= {0};
224 ca[0]= ('0' + ((*a.val.in() -'0') << 1));
226 Test::MyVarStruct_var
227 newval_p,
228 newret_p;
229 ACE_NEW_RETURN( newval_p, Test::MyVarStruct(), 0 );
230 Test::MyVarStruct_var
231 newval= newval_p;
232 ACE_NEW_RETURN( newret_p, Test::MyVarStruct(), 0 );
233 Test::MyVarStruct_var
234 newret= newret_p;
236 newval->val= CORBA::string_dup( ca );
238 *c.val.inout()+= 1;
240 newret->val= CORBA::string_dup( "7" );
242 b= newval._retn();
243 return newret._retn();
246 //-----------------------------------------------------------
248 Test::MyNonVarUnion TestNonVarUnion(
249 const Test::MyNonVarUnion &a,
250 Test::MyNonVarUnion_out b,
251 Test::MyNonVarUnion &c
254 Test::MyNonVarUnion
255 newret;
257 ACE_DEBUG( (LM_INFO, ". in TestNonVarUnion\n") );
258 if (static_cast<CORBA::Short>( 1 ) != a._d())
260 ACE_DEBUG( (LM_INFO, "* Incorrect type of parameter a\n") );
261 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
263 if (static_cast<CORBA::Long>( 1 ) != a.valLong())
265 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
266 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
268 if (static_cast<CORBA::Short>( 1 ) != c._d())
270 ACE_DEBUG( (LM_INFO, "* Incorrect type of parameter c\n") );
271 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
273 if (static_cast<CORBA::Long>( 3 ) != c.valLong())
275 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
276 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
279 Test::MyNonVarUnion *newval_p;
280 ACE_NEW_RETURN( newval_p, Test::MyNonVarUnion(), newret );
281 Test::MyNonVarUnion_var
282 newval= newval_p;
284 newval->valLong( a.valLong() << 1 );
285 c.valLong( c.valLong() + 1 );
287 newret.valLong( static_cast<CORBA::Long>( 7 ) );
289 b= newval._retn();
290 return newret;
293 //-----------------------------------------------------------
295 Test::MyVarUnion *TestVarUnion(
296 const Test::MyVarUnion &a,
297 Test::MyVarUnion_out b,
298 Test::MyVarUnion &c
301 ACE_DEBUG( (LM_INFO, ". in TestVarUnion\n") );
302 if (static_cast<CORBA::Short>( 1 ) != a._d())
304 ACE_DEBUG( (LM_INFO, "* Incorrect type of parameter a\n") );
305 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
307 if (static_cast<CORBA::Long>( 1 ) != a.valLong())
309 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
310 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
312 if (static_cast<CORBA::Short>( 1 ) != c._d())
314 ACE_DEBUG( (LM_INFO, "* Incorrect type of parameter c\n") );
315 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
317 if (static_cast<CORBA::Long>( 3 ) != c.valLong())
319 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
320 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
323 Test::MyVarUnion *newval_p;
324 ACE_NEW_RETURN( newval_p, Test::MyVarUnion(), 0 );
325 Test::MyVarUnion_var
326 newval= newval_p;
328 newval->valLong( a.valLong() << 1 );
329 c.valLong( c.valLong() + 1 );
331 Test::MyVarUnion_var
332 newret_p;
333 ACE_NEW_RETURN( newret_p, Test::MyVarUnion(), 0 );
334 Test::MyVarUnion_var
335 newret= newret_p;
336 newret->valLong( static_cast<CORBA::Short>( 7 ) );
338 b= newval._retn();
339 return newret._retn();
342 //-----------------------------------------------------------
344 Test::MySeqOfLong *TestSeqOfLong (
345 const Test::MySeqOfLong &a,
346 Test::MySeqOfLong_out b,
347 Test::MySeqOfLong &c
350 ACE_DEBUG( (LM_INFO, ". in TestSeqOfLong\n") );
351 if (1u != a.length())
353 ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter a\n") );
354 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
356 if (static_cast<CORBA::Long>( 1 ) != a[0])
358 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
359 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
361 if (1u != c.length())
363 ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter c\n") );
364 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
366 if (static_cast<CORBA::Long>( 3 ) != c[0])
368 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
369 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
372 Test::MySeqOfLong *newval_p;
373 ACE_NEW_RETURN( newval_p, Test::MySeqOfLong(1), 0 );
374 Test::MySeqOfLong_var
375 newval= newval_p;
377 newval->length(1);
378 newval[0]= a[0] << 1;
379 c[0]+= 1;
381 Test::MySeqOfLong *newret_p;
382 ACE_NEW_RETURN( newret_p, Test::MySeqOfLong(1), 0 );
383 Test::MySeqOfLong_var
384 newret= newret_p;
385 newret->length( 1 );
386 newret[0]= static_cast<CORBA::Long>( 7 );
388 b= newval._retn();
389 return newret._retn();
392 //-----------------------------------------------------------
394 CORBA::Any *TestAny(
395 const CORBA::Any &a,
396 CORBA::Any_out b,
397 CORBA::Any &c
400 ACE_DEBUG( (LM_INFO, ". in TestAny\n") );
401 CORBA::Long aL;
402 CORBA::Long cL;
403 if (a >>= aL)
405 if (static_cast<CORBA::Long>( 1 ) != aL)
407 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
408 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
411 else
413 ACE_DEBUG( (LM_INFO, "* Incorrect any type for parameter a\n") );
414 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
416 if (c >>= cL)
418 if (static_cast<CORBA::Long>( 3 ) != cL)
420 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
421 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
424 else
426 ACE_DEBUG( (LM_INFO, "* Incorrect any type for parameter c\n") );
427 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
430 CORBA::Any *newval_p;
431 ACE_NEW_RETURN( newval_p, CORBA::Any(), 0 );
432 CORBA::Any_var
433 newval= newval_p;
435 newval<<= aL << 1;
436 c<<= cL + 1;
438 CORBA::Any *newret_p;
439 ACE_NEW_RETURN( newret_p, CORBA::Any(), 0 );
440 CORBA::Any_var
441 newret= newret_p;
442 newret<<= static_cast<CORBA::Long>( 7 );
444 b= newval._retn();
445 return newret._retn();
448 //-----------------------------------------------------------
450 Test::MyArray_slice *TestArray(
451 const Test::MyArray a,
452 Test::MyArray_out b,
453 Test::MyArray c)
455 ACE_DEBUG( (LM_INFO, ". in TestArray\n") );
456 if (a[0].length () != 1)
458 ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter a[0]\n") );
459 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
461 if (a[0][0] != 9)
463 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a[0]\n") );
464 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
466 if (a[1].length () != 1)
468 ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter a[1]\n") );
469 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
471 if (a[1][0] != 23)
473 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a[1]\n") );
474 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
477 if (c[0].length () != 1)
479 ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter c[0]\n") );
480 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
482 if (c[0][0]++ != 23)
484 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c[0]\n") );
485 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
487 if (c[1].length () != 1)
489 ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter c[1]\n") );
490 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
492 if (c[1][0]++ != 9)
494 ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c[1]\n") );
495 throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
498 b = Test::MyArray_alloc ();
499 CORBA::ULong idx (0);
500 b[idx].length (1);
501 b[idx][0] = 8;
502 ++idx;
503 b[idx].length (1);
504 b[idx][0] = 22;
506 Test::MyArray_var ret = new Test::MyArray;
507 idx = 0;
508 ret[idx].length (1);
509 ret[idx][0] = 7;
510 ++idx;
511 ret[idx].length (1);
512 ret[idx][0] = 21;
513 return ret._retn ();
516 //-----------------------------------------------------------
518 CORBA::Object_ptr TestObject(
519 CORBA::Object_ptr a,
520 CORBA::Object_out b,
521 CORBA::Object_ptr &c
524 b = CORBA::Object::_duplicate (a);
525 return CORBA::Object::_duplicate (c);
528 //-----------------------------------------------------------
530 void ShutdownServer(
533 ACE_DEBUG( (LM_INFO, ". in ShutdownServer\n") );
534 orb->shutdown(0);
538 // Here is our Regression test class that actually tests the problem with
539 // the interceptor's arguments.
541 class AnInterceptor : public PortableInterceptor::ServerRequestInterceptor
543 public:
544 char *name( )
546 return const_cast<char *>("");
549 void destroy( )
553 void receive_request_service_contexts(
554 PortableInterceptor::ServerRequestInfo_ptr
558 // Note this helper only deals with the types inserted into
559 // the any that we defined for this test.
560 static void display_any( const CORBA::Any &arg )
562 const CORBA::Any *holding;
563 const Test::MyVarStruct *vS;
564 const Test::MyNonVarStruct *fS;
565 const char *pString;
566 CORBA::Long theLong;
567 const Test::MyVarUnion *vU;
568 const Test::MyNonVarUnion *fU;
569 const Test::MySeqOfLong *sL;
570 Test::MyArray_forany arr;
571 CORBA::Object_var obj;
573 if (arg >>= vS)
575 ACE_DEBUG( (LM_INFO, "MyVarStruct (") );
576 if (vS)
577 ACE_DEBUG( (LM_INFO, vS->val.in()) );
578 else
579 ACE_DEBUG( (LM_INFO, "*Null*") );
581 else if (arg >>= fS)
583 ACE_DEBUG( (LM_INFO, "MyNonVarStruct (") );
584 if (fS)
585 ACE_DEBUG( (LM_INFO, "%d", fS->val) );
586 else
587 ACE_DEBUG( (LM_INFO, "*Null*") );
589 else if (arg >>= pString)
591 ACE_DEBUG( (LM_INFO, "String (") );
592 if (pString)
593 ACE_DEBUG( (LM_INFO, pString) );
594 else
595 ACE_DEBUG( (LM_INFO, "*Null*") );
597 else if (arg >>= theLong)
598 ACE_DEBUG( (LM_INFO, "Long (%d", theLong) );
599 else if (arg >>= fU)
601 ACE_DEBUG( (LM_INFO, "MyNonVarUnion (") );
602 if (fU) switch (fU->_d())
604 case 1:
605 ACE_DEBUG( (LM_INFO, "Long %d", fU->valLong()) );
606 break;
608 case 2:
609 ACE_DEBUG( (LM_INFO, "Short %d", fU->valShort()) );
610 break;
612 default:
613 ACE_DEBUG( (LM_INFO, "*Unknown*") );
615 else
616 ACE_DEBUG( (LM_INFO, "*Null*") );
618 else if (arg >>= vU)
620 ACE_DEBUG( (LM_INFO, "MyVarUnion (") );
621 if (vU) switch (vU->_d())
623 case 1:
624 ACE_DEBUG( (LM_INFO, "Long %d", vU->valLong()) );
625 break;
627 case 2:
628 ACE_DEBUG( (LM_INFO, "String %C", vU->valString()));
629 break;
631 default:
632 ACE_DEBUG( (LM_INFO, "*Unknown*") );
634 else
635 ACE_DEBUG( (LM_INFO, "*Null*") );
637 else if (arg >>= sL)
639 ACE_DEBUG( (LM_INFO, "MySeqOfLong (") );
640 if (sL)
642 if (0u < sL->length())
644 for (unsigned int i= 0u; i < sL->length() - 1u; ++i)
645 ACE_DEBUG( (LM_INFO, "%d, ", (*sL)[ i ]) );
646 ACE_DEBUG( (LM_INFO, "%d", (*sL)[ sL->length() - 1u ]) );
648 else
649 ACE_DEBUG( (LM_INFO, "*Empty*") );
651 else
652 ACE_DEBUG( (LM_INFO, "*Null*") );
654 else if (arg >>= holding)
656 ACE_DEBUG( (LM_INFO, "Any (") );
657 if (holding)
659 if (*holding >>= theLong)
660 ACE_DEBUG( (LM_INFO, "Long %d", theLong) );
661 else
662 ACE_DEBUG( (LM_INFO, "*Not Long*") );
664 else
665 ACE_DEBUG( (LM_INFO, "*Null*") );
667 else if (arg >>= arr)
669 ACE_DEBUG( (LM_INFO, "MyArray (") );
670 for (CORBA::ULong a_idx = 0; a_idx < 2; ++a_idx)
672 CORBA::ULong length = arr[a_idx].length ();
673 ACE_DEBUG( (LM_INFO, "[%u].length () == %u ", a_idx, length));
676 else if (arg >>= CORBA::Any::to_object(obj))
678 ACE_DEBUG( (LM_INFO, "CORBA::Object (") );
680 else
681 ACE_DEBUG( (LM_INFO, "Unknown (") );
682 ACE_DEBUG( (LM_INFO, ") parameter\n") );
685 // Useful parameter dumping helper method.-----------| Note this VAR
686 // which will automatically delete after the call! V
687 static void display_arg_list( Dynamic::ParameterList_var param_list )
689 for (unsigned int i= 0u; i < param_list->length(); ++i)
691 ACE_DEBUG( (LM_INFO, " param %d is an ", i) );
692 switch( (*param_list)[i].mode )
694 case CORBA::PARAM_IN:
695 ACE_DEBUG( (LM_INFO, "in ") );
696 break;
698 case CORBA::PARAM_OUT:
699 ACE_DEBUG( (LM_INFO, "out ") );
700 break;
702 case CORBA::PARAM_INOUT:
703 ACE_DEBUG( (LM_INFO, "inout ") );
704 break;
706 default:
707 ACE_DEBUG( (LM_INFO, "non-directional ") );
708 break;
711 display_any( (*param_list)[i].argument );
715 void receive_request(
716 PortableInterceptor::ServerRequestInfo_ptr ri
719 ACE_DEBUG( (LM_INFO, "AnInterceptor::receive_request\n") );
720 Dynamic::ParameterList
721 *pArgs= ri->arguments( );
722 display_arg_list( pArgs );
725 // This send_reply() method would cause the problem due to it's
726 // ri->arguments() call. When the returned arguments list was
727 // deleted (due to the display_arg_list( Dynamic::ParameterList_var ))
728 // going out of scope, the "Owned" out pointer 'Argument B' would
729 // be premiturely deleted before being sent back to the client.
730 void send_reply(
731 PortableInterceptor::ServerRequestInfo_ptr ri
734 ACE_DEBUG( (LM_INFO, "AnInterceptor::send_reply\n") );
735 Dynamic::ParameterList
736 *pArgs= ri->arguments( );
737 display_arg_list( pArgs );
738 ACE_DEBUG( (LM_INFO, " result is an ") );
739 CORBA::Any
740 *pAny= ri->result( );
741 display_any( CORBA::Any_var( pAny ).in() );
742 ACE_DEBUG( (LM_INFO, "\n") );
745 void send_exception(
746 PortableInterceptor::ServerRequestInfo_ptr
750 void send_other(
751 PortableInterceptor::ServerRequestInfo_ptr
757 class Initialiser
758 : public virtual PortableInterceptor::ORBInitializer
759 , public virtual CORBA::LocalObject
761 public:
762 Initialiser( AnInterceptor* interceptor )
764 this->interceptor_= interceptor;
767 void pre_init(
768 PortableInterceptor::ORBInitInfo_ptr
773 void post_init(
774 PortableInterceptor::ORBInitInfo_ptr info
777 info->add_server_request_interceptor( interceptor_ );
780 private:
781 AnInterceptor *interceptor_;
784 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
788 ACE_DEBUG( (LM_INFO, "Server start\n") );
789 AnInterceptor
790 interceptor;
791 PortableInterceptor::ORBInitializer_ptr
792 initialiser_p;
793 ACE_NEW_RETURN( initialiser_p, Initialiser( &interceptor ), -1 );
794 PortableInterceptor::ORBInitializer_var
795 initialiser= initialiser_p;
796 PortableInterceptor::register_orb_initializer( initialiser.in() );
798 orb= CORBA::ORB_init (argc, argv);
799 CORBA::Object_var
800 Object = orb->resolve_initial_references( "RootPOA" );
801 PortableServer::POA_var rootPOA=
802 PortableServer::POA::_narrow( Object.in() );
803 PortableServer::POAManager_var
804 rootPOAMgr = rootPOA->the_POAManager( );
806 if (parse_args (argc, argv) != 0)
807 return 1;
809 FooImpl
810 phooey;
811 PortableServer::ObjectId_var
812 phooeyId= rootPOA->activate_object( &phooey );
813 CORBA::Object_var
814 phooeyObj= rootPOA->id_to_reference( phooeyId.in() );
815 CORBA::String_var
816 stringifiedObj= orb->object_to_string( phooeyObj.in() );
817 ofstream file( ACE_TEXT_ALWAYS_CHAR(ior_output_file) );
818 file << stringifiedObj;
819 file.close();
821 rootPOAMgr->activate( );
823 orb->run( 0 );
825 orb->destroy( );
827 catch (const CORBA::SystemException& exception)
829 exception._tao_print_exception ("CORBA::SystemException: ");
830 return -1;
832 catch (const CORBA::Exception& ex)
834 ex._tao_print_exception ("CORBA::Exception: ");
835 return -1;
837 catch (...)
839 ACE_DEBUG( (LM_ERROR, "Unexpected general exception.\n") );
840 return -1;
843 ACE_DEBUG( (LM_INFO, "Server stopped\n") );
844 return 0;