1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
// Regression test Bug 2234
//
// The bug actually manifested itself in class AnInterceptor::receive_request()
// where any OUT parameters of variable length items (as they are held as
// addresses of NULL pointers)
//
// The bug is caused by the arguments() call which should be
// creating a read-only COPY of the parameters to the call. These are held as
// a sequence of ANYs, whith the code for the insertion into which is created
// by the TAO_IDL compiler when their user types are compiled.
// It is also manifested by the result() call in the same way.
#include "TestS.h"
#include "ace/Get_Opt.h"
#include "ace/IOStream.h"
#include "tao/PI/PI.h"
#include "tao/PI_Server/PI_Server.h"
#include "tao/ORBInitializer_Registry.h"
#include "tao/PortableServer/Root_POA.h"
#include "tao/LocalObject.h"
const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
int
parse_args (int argc, ACE_TCHAR *argv[])
{
ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'o':
ior_output_file = get_opts.opt_arg ();
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s "
"-o <iorfile>"
"\n",
argv [0]),
-1);
}
// Indicates successful parsing of the command line
return 0;
}
CORBA::ORB_ptr orb;
// The test case code for the server always sends back to the client:
// b(out)= a(in) *2
// c(inout)= c(inout) + 1
// return= 7
// Strings are single numerical digits, longs are the numbers themselves
// and sequences are always single long values.
// Parameter 'a' must be received from the client as 1, and 'c' as 3.
class FooImpl : public POA_Test::Foo
{
public:
FooImpl() {}
~FooImpl() {}
//-----------------------------------------------------------
CORBA::Long TestLong(
CORBA::Long a,
CORBA::Long_out b,
CORBA::Long &c
)
{
ACE_DEBUG( (LM_INFO, ". in TestLong\n") );
if (static_cast<CORBA::Long>( 1 ) != a)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Long>( 3 ) != c)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
b= static_cast<CORBA::Long>( a << 1 );
c+= static_cast<CORBA::Long>( 1 );
return static_cast<CORBA::Long>( 7 );
}
//-----------------------------------------------------------
char *TestString(
const char *a,
CORBA::String_out b,
char *&c
)
{
ACE_DEBUG( (LM_INFO, ". in TestString\n") );
if (0 == a)
{
//FUZZ: disable check_for_NULL
ACE_DEBUG( (LM_INFO, "* Incorrect NULL string given for parameter a\n") );
//FUZZ: enable check_for_NULL
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (1 != ACE_OS::strlen( a ))
{
ACE_DEBUG( (LM_INFO, "* Incorrect string length for parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if ('1' != *a)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (0 == c)
{
//FUZZ: disable check_for_NULL
ACE_DEBUG( (LM_INFO, "* Incorrect NULL string given for parameter c\n") );
//FUZZ: enable check_for_NULL
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (1 != ACE_OS::strlen( c ))
{
ACE_DEBUG( (LM_INFO, "* Incorrect string length for parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if ('3' != *c)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
b= CORBA::string_dup( "0" ); // Create a one character output buffer
*b= a[0] + 1;
*c+= 1;
return CORBA::string_dup( "7" );
}
//-----------------------------------------------------------
Test::MyNonVarStruct TestNonVarStruct(
const Test::MyNonVarStruct &a,
Test::MyNonVarStruct_out b,
Test::MyNonVarStruct &c
)
{
Test::MyNonVarStruct
newret;
ACE_DEBUG( (LM_INFO, ". in TestNonVarStruct\n") );
if (static_cast<CORBA::Long>( 1 ) != a.val)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Long>( 3 ) != c.val)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
newret.val= static_cast<CORBA::Long>( 7 );
Test::MyNonVarStruct *newval_p;
ACE_NEW_RETURN( newval_p, Test::MyNonVarStruct, newret );
Test::MyNonVarStruct_var
newval= newval_p;
newval->val= a.val << 1;
c.val+= 1;
b= newval._retn();
return newret;
}
//-----------------------------------------------------------
Test::MyVarStruct *TestVarStruct(
const Test::MyVarStruct &a,
Test::MyVarStruct_out b,
Test::MyVarStruct &c
)
{
ACE_DEBUG( (LM_INFO, ". in TestVarStruct\n") );
if (0 == a.val.in())
{
//FUZZ: disable check_for_NULL
ACE_DEBUG( (LM_INFO, "* Incorrect NULL string given for parameter a\n") );
//FUZZ: enable check_for_NULL
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (1 != ACE_OS::strlen( a.val.in() ))
{
ACE_DEBUG( (LM_INFO, "* Incorrect string length for parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if ('1' != *a.val.in())
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (0 == c.val.in())
{
//FUZZ: disable check_for_NULL
ACE_DEBUG( (LM_INFO, "* Incorrect NULL string given for parameter c\n") );
//FUZZ: enable check_for_NULL
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (1 != ACE_OS::strlen( c.val.in() ))
{
ACE_DEBUG( (LM_INFO, "* Incorrect string length for parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if ('3' != *c.val.in())
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
char ca[2]= {0};
ca[0]= ('0' + ((*a.val.in() -'0') << 1));
Test::MyVarStruct_var
newval_p,
newret_p;
ACE_NEW_RETURN( newval_p, Test::MyVarStruct(), 0 );
Test::MyVarStruct_var
newval= newval_p;
ACE_NEW_RETURN( newret_p, Test::MyVarStruct(), 0 );
Test::MyVarStruct_var
newret= newret_p;
newval->val= CORBA::string_dup( ca );
*c.val.inout()+= 1;
newret->val= CORBA::string_dup( "7" );
b= newval._retn();
return newret._retn();
}
//-----------------------------------------------------------
Test::MyNonVarUnion TestNonVarUnion(
const Test::MyNonVarUnion &a,
Test::MyNonVarUnion_out b,
Test::MyNonVarUnion &c
)
{
Test::MyNonVarUnion
newret;
ACE_DEBUG( (LM_INFO, ". in TestNonVarUnion\n") );
if (static_cast<CORBA::Short>( 1 ) != a._d())
{
ACE_DEBUG( (LM_INFO, "* Incorrect type of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Long>( 1 ) != a.valLong())
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Short>( 1 ) != c._d())
{
ACE_DEBUG( (LM_INFO, "* Incorrect type of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Long>( 3 ) != c.valLong())
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
Test::MyNonVarUnion *newval_p;
ACE_NEW_RETURN( newval_p, Test::MyNonVarUnion(), newret );
Test::MyNonVarUnion_var
newval= newval_p;
newval->valLong( a.valLong() << 1 );
c.valLong( c.valLong() + 1 );
newret.valLong( static_cast<CORBA::Long>( 7 ) );
b= newval._retn();
return newret;
}
//-----------------------------------------------------------
Test::MyVarUnion *TestVarUnion(
const Test::MyVarUnion &a,
Test::MyVarUnion_out b,
Test::MyVarUnion &c
)
{
ACE_DEBUG( (LM_INFO, ". in TestVarUnion\n") );
if (static_cast<CORBA::Short>( 1 ) != a._d())
{
ACE_DEBUG( (LM_INFO, "* Incorrect type of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Long>( 1 ) != a.valLong())
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Short>( 1 ) != c._d())
{
ACE_DEBUG( (LM_INFO, "* Incorrect type of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Long>( 3 ) != c.valLong())
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
Test::MyVarUnion *newval_p;
ACE_NEW_RETURN( newval_p, Test::MyVarUnion(), 0 );
Test::MyVarUnion_var
newval= newval_p;
newval->valLong( a.valLong() << 1 );
c.valLong( c.valLong() + 1 );
Test::MyVarUnion_var
newret_p;
ACE_NEW_RETURN( newret_p, Test::MyVarUnion(), 0 );
Test::MyVarUnion_var
newret= newret_p;
newret->valLong( static_cast<CORBA::Short>( 7 ) );
b= newval._retn();
return newret._retn();
}
//-----------------------------------------------------------
Test::MySeqOfLong *TestSeqOfLong (
const Test::MySeqOfLong &a,
Test::MySeqOfLong_out b,
Test::MySeqOfLong &c
)
{
ACE_DEBUG( (LM_INFO, ". in TestSeqOfLong\n") );
if (1u != a.length())
{
ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Long>( 1 ) != a[0])
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (1u != c.length())
{
ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (static_cast<CORBA::Long>( 3 ) != c[0])
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
Test::MySeqOfLong *newval_p;
ACE_NEW_RETURN( newval_p, Test::MySeqOfLong(1), 0 );
Test::MySeqOfLong_var
newval= newval_p;
newval->length(1);
newval[0]= a[0] << 1;
c[0]+= 1;
Test::MySeqOfLong *newret_p;
ACE_NEW_RETURN( newret_p, Test::MySeqOfLong(1), 0 );
Test::MySeqOfLong_var
newret= newret_p;
newret->length( 1 );
newret[0]= static_cast<CORBA::Long>( 7 );
b= newval._retn();
return newret._retn();
}
//-----------------------------------------------------------
CORBA::Any *TestAny(
const CORBA::Any &a,
CORBA::Any_out b,
CORBA::Any &c
)
{
ACE_DEBUG( (LM_INFO, ". in TestAny\n") );
CORBA::Long aL;
CORBA::Long cL;
if (a >>= aL)
{
if (static_cast<CORBA::Long>( 1 ) != aL)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
}
else
{
ACE_DEBUG( (LM_INFO, "* Incorrect any type for parameter a\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (c >>= cL)
{
if (static_cast<CORBA::Long>( 3 ) != cL)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
}
else
{
ACE_DEBUG( (LM_INFO, "* Incorrect any type for parameter c\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
CORBA::Any *newval_p;
ACE_NEW_RETURN( newval_p, CORBA::Any(), 0 );
CORBA::Any_var
newval= newval_p;
newval<<= aL << 1;
c<<= cL + 1;
CORBA::Any *newret_p;
ACE_NEW_RETURN( newret_p, CORBA::Any(), 0 );
CORBA::Any_var
newret= newret_p;
newret<<= static_cast<CORBA::Long>( 7 );
b= newval._retn();
return newret._retn();
}
//-----------------------------------------------------------
Test::MyArray_slice *TestArray(
const Test::MyArray a,
Test::MyArray_out b,
Test::MyArray c)
{
ACE_DEBUG( (LM_INFO, ". in TestArray\n") );
if (a[0].length () != 1)
{
ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter a[0]\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (a[0][0] != 9)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a[0]\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (a[1].length () != 1)
{
ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter a[1]\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (a[1][0] != 23)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter a[1]\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (c[0].length () != 1)
{
ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter c[0]\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (c[0][0]++ != 23)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c[0]\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (c[1].length () != 1)
{
ACE_DEBUG( (LM_INFO, "* Incorrect length of parameter c[1]\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
if (c[1][0]++ != 9)
{
ACE_DEBUG( (LM_INFO, "* Incorrect input value of parameter c[1]\n") );
throw CORBA::BAD_PARAM(0, CORBA::COMPLETED_NO);
}
b = Test::MyArray_alloc ();
CORBA::ULong idx (0);
b[idx].length (1);
b[idx][0] = 8;
++idx;
b[idx].length (1);
b[idx][0] = 22;
Test::MyArray_var ret = new Test::MyArray;
idx = 0;
ret[idx].length (1);
ret[idx][0] = 7;
++idx;
ret[idx].length (1);
ret[idx][0] = 21;
return ret._retn ();
}
//-----------------------------------------------------------
CORBA::Object_ptr TestObject(
CORBA::Object_ptr a,
CORBA::Object_out b,
CORBA::Object_ptr &c
)
{
b = CORBA::Object::_duplicate (a);
return CORBA::Object::_duplicate (c);
}
//-----------------------------------------------------------
void ShutdownServer(
)
{
ACE_DEBUG( (LM_INFO, ". in ShutdownServer\n") );
orb->shutdown(0);
}
};
// Here is our Regression test class that actually tests the problem with
// the interceptor's arguments.
class AnInterceptor : public PortableInterceptor::ServerRequestInterceptor
{
public:
char *name( )
{
return const_cast<char *>("");
}
void destroy( )
{
}
void receive_request_service_contexts(
PortableInterceptor::ServerRequestInfo_ptr
)
{
}
// Note this helper only deals with the types inserted into
// the any that we defined for this test.
static void display_any( const CORBA::Any &arg )
{
const CORBA::Any *holding;
const Test::MyVarStruct *vS;
const Test::MyNonVarStruct *fS;
const char *pString;
CORBA::Long theLong;
const Test::MyVarUnion *vU;
const Test::MyNonVarUnion *fU;
const Test::MySeqOfLong *sL;
Test::MyArray_forany arr;
CORBA::Object_var obj;
if (arg >>= vS)
{
ACE_DEBUG( (LM_INFO, "MyVarStruct (") );
if (vS)
ACE_DEBUG( (LM_INFO, vS->val.in()) );
else
ACE_DEBUG( (LM_INFO, "*Null*") );
}
else if (arg >>= fS)
{
ACE_DEBUG( (LM_INFO, "MyNonVarStruct (") );
if (fS)
ACE_DEBUG( (LM_INFO, "%d", fS->val) );
else
ACE_DEBUG( (LM_INFO, "*Null*") );
}
else if (arg >>= pString)
{
ACE_DEBUG( (LM_INFO, "String (") );
if (pString)
ACE_DEBUG( (LM_INFO, pString) );
else
ACE_DEBUG( (LM_INFO, "*Null*") );
}
else if (arg >>= theLong)
ACE_DEBUG( (LM_INFO, "Long (%d", theLong) );
else if (arg >>= fU)
{
ACE_DEBUG( (LM_INFO, "MyNonVarUnion (") );
if (fU) switch (fU->_d())
{
case 1:
ACE_DEBUG( (LM_INFO, "Long %d", fU->valLong()) );
break;
case 2:
ACE_DEBUG( (LM_INFO, "Short %d", fU->valShort()) );
break;
default:
ACE_DEBUG( (LM_INFO, "*Unknown*") );
}
else
ACE_DEBUG( (LM_INFO, "*Null*") );
}
else if (arg >>= vU)
{
ACE_DEBUG( (LM_INFO, "MyVarUnion (") );
if (vU) switch (vU->_d())
{
case 1:
ACE_DEBUG( (LM_INFO, "Long %d", vU->valLong()) );
break;
case 2:
ACE_DEBUG( (LM_INFO, "String %C", vU->valString()));
break;
default:
ACE_DEBUG( (LM_INFO, "*Unknown*") );
}
else
ACE_DEBUG( (LM_INFO, "*Null*") );
}
else if (arg >>= sL)
{
ACE_DEBUG( (LM_INFO, "MySeqOfLong (") );
if (sL)
{
if (0u < sL->length())
{
for (unsigned int i= 0u; i < sL->length() - 1u; ++i)
ACE_DEBUG( (LM_INFO, "%d, ", (*sL)[ i ]) );
ACE_DEBUG( (LM_INFO, "%d", (*sL)[ sL->length() - 1u ]) );
}
else
ACE_DEBUG( (LM_INFO, "*Empty*") );
}
else
ACE_DEBUG( (LM_INFO, "*Null*") );
}
else if (arg >>= holding)
{
ACE_DEBUG( (LM_INFO, "Any (") );
if (holding)
{
if (*holding >>= theLong)
ACE_DEBUG( (LM_INFO, "Long %d", theLong) );
else
ACE_DEBUG( (LM_INFO, "*Not Long*") );
}
else
ACE_DEBUG( (LM_INFO, "*Null*") );
}
else if (arg >>= arr)
{
ACE_DEBUG( (LM_INFO, "MyArray (") );
for (CORBA::ULong a_idx = 0; a_idx < 2; ++a_idx)
{
CORBA::ULong length = arr[a_idx].length ();
ACE_DEBUG( (LM_INFO, "[%u].length () == %u ", a_idx, length));
}
}
else if (arg >>= CORBA::Any::to_object(obj))
{
ACE_DEBUG( (LM_INFO, "CORBA::Object (") );
}
else
ACE_DEBUG( (LM_INFO, "Unknown (") );
ACE_DEBUG( (LM_INFO, ") parameter\n") );
}
// Useful parameter dumping helper method.-----------| Note this VAR
// which will automatically delete after the call! V
static void display_arg_list( Dynamic::ParameterList_var param_list )
{
for (unsigned int i= 0u; i < param_list->length(); ++i)
{
ACE_DEBUG( (LM_INFO, " param %d is an ", i) );
switch( (*param_list)[i].mode )
{
case CORBA::PARAM_IN:
ACE_DEBUG( (LM_INFO, "in ") );
break;
case CORBA::PARAM_OUT:
ACE_DEBUG( (LM_INFO, "out ") );
break;
case CORBA::PARAM_INOUT:
ACE_DEBUG( (LM_INFO, "inout ") );
break;
default:
ACE_DEBUG( (LM_INFO, "non-directional ") );
break;
}
display_any( (*param_list)[i].argument );
}
}
void receive_request(
PortableInterceptor::ServerRequestInfo_ptr ri
)
{
ACE_DEBUG( (LM_INFO, "AnInterceptor::receive_request\n") );
Dynamic::ParameterList
*pArgs= ri->arguments( );
display_arg_list( pArgs );
}
// This send_reply() method would cause the problem due to it's
// ri->arguments() call. When the returned arguments list was
// deleted (due to the display_arg_list( Dynamic::ParameterList_var ))
// going out of scope, the "Owned" out pointer 'Argument B' would
// be premiturely deleted before being sent back to the client.
void send_reply(
PortableInterceptor::ServerRequestInfo_ptr ri
)
{
ACE_DEBUG( (LM_INFO, "AnInterceptor::send_reply\n") );
Dynamic::ParameterList
*pArgs= ri->arguments( );
display_arg_list( pArgs );
ACE_DEBUG( (LM_INFO, " result is an ") );
CORBA::Any
*pAny= ri->result( );
display_any( CORBA::Any_var( pAny ).in() );
ACE_DEBUG( (LM_INFO, "\n") );
}
void send_exception(
PortableInterceptor::ServerRequestInfo_ptr
)
{
}
void send_other(
PortableInterceptor::ServerRequestInfo_ptr
)
{
}
};
class Initialiser
: public virtual PortableInterceptor::ORBInitializer
, public virtual CORBA::LocalObject
{
public:
Initialiser( AnInterceptor* interceptor )
{
this->interceptor_= interceptor;
}
void pre_init(
PortableInterceptor::ORBInitInfo_ptr
)
{
}
void post_init(
PortableInterceptor::ORBInitInfo_ptr info
)
{
info->add_server_request_interceptor( interceptor_ );
}
private:
AnInterceptor *interceptor_;
};
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
ACE_DEBUG( (LM_INFO, "Server start\n") );
AnInterceptor
interceptor;
PortableInterceptor::ORBInitializer_ptr
initialiser_p;
ACE_NEW_RETURN( initialiser_p, Initialiser( &interceptor ), -1 );
PortableInterceptor::ORBInitializer_var
initialiser= initialiser_p;
PortableInterceptor::register_orb_initializer( initialiser.in() );
orb= CORBA::ORB_init (argc, argv);
CORBA::Object_var
Object = orb->resolve_initial_references( "RootPOA" );
PortableServer::POA_var rootPOA=
PortableServer::POA::_narrow( Object.in() );
PortableServer::POAManager_var
rootPOAMgr = rootPOA->the_POAManager( );
if (parse_args (argc, argv) != 0)
return 1;
FooImpl
phooey;
PortableServer::ObjectId_var
phooeyId= rootPOA->activate_object( &phooey );
CORBA::Object_var
phooeyObj= rootPOA->id_to_reference( phooeyId.in() );
CORBA::String_var
stringifiedObj= orb->object_to_string( phooeyObj.in() );
ofstream file( ACE_TEXT_ALWAYS_CHAR(ior_output_file) );
file << stringifiedObj;
file.close();
rootPOAMgr->activate( );
orb->run( 0 );
orb->destroy( );
}
catch (const CORBA::SystemException& exception)
{
exception._tao_print_exception ("CORBA::SystemException: ");
return -1;
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("CORBA::Exception: ");
return -1;
}
catch (...)
{
ACE_DEBUG( (LM_ERROR, "Unexpected general exception.\n") );
return -1;
}
ACE_DEBUG( (LM_INFO, "Server stopped\n") );
return 0;
}
|