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
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
|
// $Id$
// @ (#)iiopobj.cpp 1.9 95/11/04
// Copyright 1995 by Sun Microsystems Inc.
// All Rights Reserved
//
// XXXX Bridge: CORBA::Object operations
//
// Some CORBA::Object and other operations are specific to this STUB
// based implementation, and can neither be used by other kinds of
// objref nor have a default implementation.
#include "tao/Endpoint.h"
#include "tao/Stub.h"
#include "tao/Sequence.h"
#include "tao/Object.h"
#include "tao/NVList.h"
#include "tao/Invocation.h"
#include "tao/Asynch_Invocation.h"
#include "tao/DII_Invocation.h"
#include "tao/ORB_Core.h"
#include "tao/Client_Strategy_Factory.h"
#include "tao/Sync_Strategies.h"
#include "tao/Buffering_Constraint_Policy.h"
#include "tao/Messaging_Policy_i.h"
#include "tao/Client_Priority_Policy.h"
#include "tao/debug.h"
#if (TAO_HAS_RT_CORBA == 1)
# include "tao/RT_Policy_i.h"
#endif /* TAO_HAS_RT_CORBA == 1 */
#include "ace/Auto_Ptr.h"
#if !defined (__ACE_INLINE__)
# include "tao/Stub.i"
#endif /* ! __ACE_INLINE__ */
ACE_RCSID(tao, TAO_Stub, "$Id$")
TAO_Stub::TAO_Stub (char *repository_id,
const TAO_MProfile &profiles,
TAO_ORB_Core* orb_core)
: type_id (repository_id),
#if (TAO_HAS_RT_CORBA == 1)
priority_model_policy_ (0),
priority_banded_connection_policy_ (0),
client_protocol_policy_ (0),
are_policies_parsed_ (0),
#endif /* TAO_HAS_RT_CORBA == 1 */
base_profiles_ ((CORBA::ULong) 0),
forward_profiles_ (0),
profile_in_use_ (0),
profile_lock_ptr_ (0),
profile_success_ (0),
refcount_lock_ (),
refcount_ (1),
use_locate_request_ (0),
first_locate_request_ (0),
orb_core_ (orb_core),
orb_ (),
servant_orb_ (),
#if (TAO_HAS_CORBA_MESSAGING == 1)
policies_ (0),
#endif /* TAO_HAS_CORBA_MESSAGING == 1 */
addressing_mode_ (0)
{
if (this->orb_core_ == 0)
{
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("TAO: (%P|%t) TAO_Stub created with default ")
ACE_TEXT ("ORB core\n")));
}
this->orb_core_ = TAO_ORB_Core_instance ();
}
// Duplicate the ORB_Core, otherwise the allocators and other
// resources that this class references (directly or indirectly)
// could be destroyed before it is time.
(void) this->orb_core_->_incr_refcnt ();
// Cache the ORB pointer to respond faster to certain queries.
this->orb_ = CORBA::ORB::_duplicate (this->orb_core_->orb ());
this->profile_lock_ptr_ =
this->orb_core_->client_factory ()->create_profile_lock ();
this->base_profiles (profiles);
TAO_Profile *profile = 0;
for (CORBA::ULong i = 0; i < this->base_profiles_.profile_count (); ++i)
{
// Get the ith profile
profile = this->base_profiles_.get_profile (i);
profile->the_stub (this);
}
}
TAO_Stub::~TAO_Stub (void)
{
ACE_ASSERT (this->refcount_ == 0);
if (this->forward_profiles_)
reset_profiles ();
if (this->profile_in_use_ != 0)
{
if (this->orb_->orb_core () != 0)
{
// The hint in the profile is a hint for a client connection
// handler. If the ORB core doesn't exist, perhaps due to
// it being destroy()ed, then no connectors exist so do not
// reset the hint in case it points to non-existent
// connection handler.
this->profile_in_use_->endpoint ()->reset_hint ();
}
// decrease reference count on profile
this->profile_in_use_->_decr_refcnt ();
this->profile_in_use_ = 0;
}
delete this->profile_lock_ptr_;
#if (TAO_HAS_CORBA_MESSAGING == 1)
delete this->policies_;
#endif /* TAO_HAS_CORBA_MESSAGING == 1 */
this->orb_core_->_decr_refcnt ();
#if (TAO_HAS_RT_CORBA == 1)
if (this->priority_model_policy_)
this->priority_model_policy_->destroy ();
if (this->priority_banded_connection_policy_)
this->priority_banded_connection_policy_->destroy ();
if (this->client_protocol_policy_)
this->client_protocol_policy_->destroy ();
#endif /* TAO_HAS_RT_CORBA */
}
void
TAO_Stub::add_forward_profiles (const TAO_MProfile &mprofiles)
{
// we assume that the profile_in_use_ is being
// forwarded! Grab the lock so things don't change.
ACE_MT (ACE_GUARD (ACE_Lock,
guard,
*this->profile_lock_ptr_));
TAO_MProfile *now_pfiles = this->forward_profiles_;
if (now_pfiles == 0)
now_pfiles = &this->base_profiles_;
ACE_NEW (this->forward_profiles_,
TAO_MProfile (mprofiles));
// forwarded profile points to the new IOR (profiles)
this->profile_in_use_->forward_to (this->forward_profiles_);
// new profile list points back to the list which was forwarded.
this->forward_profiles_->forward_from (now_pfiles);
// make sure we start at the beginning of mprofiles
this->forward_profiles_->rewind ();
// Since we have been forwarded, we must set profile_success_ to 0
// since we are starting a new with a new set of profiles!
this->profile_success_ = 0;
// Reset any flags that may be appropriate in the services that
// selects profiles for invocation
this->orb_core_->reset_service_profile_flags ();
}
// Quick'n'dirty hash of objref data, for partitioning objrefs into
// sets.
//
// NOTE that this must NOT go across the network!
// @@ Use all profiles for hash function!!!!! FRED
// can get different values, depending on the profile_in_use!!
CORBA::ULong
TAO_Stub::hash (CORBA::ULong max,
CORBA::Environment &ACE_TRY_ENV)
{
// we rely on the profile object that its address info
if (profile_in_use_)
return profile_in_use_->hash (max, ACE_TRY_ENV);
if (TAO_debug_level > 3)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%P|%t) hash called on a null profile\n")));
ACE_THROW_RETURN (CORBA::INTERNAL (
CORBA_SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
0),
CORBA::COMPLETED_NO),
0);
}
// Expensive comparison of objref data, to see if two objrefs
// certainly point at the same object. (It's quite OK for this to
// return FALSE, and yet have the two objrefs really point to the same
// object.)
//
// NOTE that this must NOT go across the network!
// @@ Two object references are the same if any two profiles are the
// same! This function is only test the profile in use!!!
CORBA::Boolean
TAO_Stub::is_equivalent (CORBA::Object_ptr other_obj)
{
if (CORBA::is_nil (other_obj) == 1)
return 0;
TAO_Profile *other_profile = other_obj->_stubobj ()->profile_in_use_;
TAO_Profile *this_profile = this->profile_in_use_;
if (other_profile == 0 || this_profile == 0)
return 0;
// Compare the profiles
return this_profile->is_equivalent (other_profile);
}
// Memory managment
CORBA::ULong
TAO_Stub::_incr_refcnt (void)
{
ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
guard,
this->refcount_lock_,
0);
return this->refcount_++;
}
CORBA::ULong
TAO_Stub::_decr_refcnt (void)
{
{
ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
mon,
this->refcount_lock_,
0);
this->refcount_--;
if (this->refcount_ != 0)
return this->refcount_;
}
delete this;
return 0;
}
// Note that if the repository ID (typeID) is NULL, it will make
// narrowing rather expensive, though it does ensure that type-safe
// narrowing code gets thoroughly exercised/debugged! Without a
// typeID, the _narrow will be required to make an expensive remote
// "is_a" call.
// THREADING NOTE: Code below this point is of course thread-safe (at
// least on supported threaded platforms), so the caller of these
// routines need only ensure that the data being passed in is not
// being modified by any other thread.
//
// As an _experiment_ (to estimate the performance cost) remote calls
// are currently deemed "cancel-safe". That means that they can be
// called by threads when they're in asynchronous cancellation mode.
// The only effective way to do this is to disable async cancellation
// for the duration of the call. There are numerous rude interactions
// with code generators for C++ ... cancellation handlers just do
// normal stack unwinding like exceptions, but exceptions are purely
// synchronous and sophisticated code generators rely on that to
// generate better code, which in some cases may be very hard to
// unwind.
class TAO_Synchronous_Cancellation_Required
// = TITLE
// Stick one of these at the beginning of a block that can't
// support asynchronous cancellation, and which must be
// cancel-safe.
//
// = EXAMPLE
// somefunc()
// {
// TAO_Synchronous_Cancellation_Required NOT_USED;
// ...
// }
{
public:
// These should probably be in a separate inline file, but they're
// only used within this one file right now, and we always want them
// inlined, so here they sit.
TAO_Synchronous_Cancellation_Required (void)
: old_type_ (0)
{
#if !defined (VXWORKS)
ACE_OS::thr_setcanceltype (THR_CANCEL_DEFERRED, &old_type_);
#endif /* ! VXWORKS */
}
~TAO_Synchronous_Cancellation_Required (void)
{
#if !defined (VXWORKS)
int dont_care;
ACE_OS::thr_setcanceltype(old_type_, &dont_care);
#endif /* ! VXWORKS */
}
private:
int old_type_;
};
#if (TAO_HAS_MINIMUM_CORBA == 0)
// DII analogue of the above.
void
TAO_Stub::do_dynamic_call (const char *opname,
CORBA::Boolean is_roundtrip,
CORBA::NVList_ptr args,
CORBA::NamedValue_ptr result,
CORBA::Flags,
CORBA::ExceptionList_ptr exceptions,
int lazy_evaluation,
CORBA::Environment &ACE_TRY_ENV)
{
// @@ TOCCST: why do we keep using this function when ACE+TAO code
// is clearly not cancel safe anymore? Furthermore, all the
// generated code using the Invocation classes is probably not
// cancel safe!
TAO_Synchronous_Cancellation_Required NOT_USED;
// Do a locate_request if necessary/wanted.
// Suspect that you will be forwarded, so be proactive!
// strategy for reducing overhead when you think a request will
// be forwarded. No standard way now to know.
if (this->use_locate_request_ && this->first_locate_request_)
{
// @@ TOCCST: notice how the locate request is only sent for
// dynamic and deferred (!!) calls, nothing is done for static
// calls, the far more common case. IMHO this should just go
// away, after all we have _validate_connection to do the same
// thing!
TAO_GIOP_Locate_Request_Invocation call (this,
this->orb_core_);
// Simply let these exceptions propagate up
// (if any of them occurs.)
call.start (ACE_TRY_ENV);
ACE_CHECK;
call.invoke (ACE_TRY_ENV);
ACE_CHECK;
this->first_locate_request_ = 0;
}
if (is_roundtrip)
{
TAO_GIOP_Twoway_Invocation call (this,
opname,
ACE_OS::strlen (opname),
this->orb_core_);
// Loop as needed for forwarding; see above.
for (;;)
{
call.start (ACE_TRY_ENV);
ACE_CHECK;
CORBA::Short flag = TAO_TWOWAY_RESPONSE_FLAG;
call.prepare_header (ACE_static_cast (CORBA::Octet, flag),
ACE_TRY_ENV);
ACE_CHECK;
this->put_params (call,
args,
ACE_TRY_ENV);
ACE_CHECK;
// Make the call ... blocking for the response.
int status =
call.invoke (exceptions, ACE_TRY_ENV);
ACE_CHECK;
if (status == TAO_INVOKE_RESTART)
continue;
if (status == TAO_INVOKE_EXCEPTION)
return; // Shouldn't happen
if (status != TAO_INVOKE_OK)
ACE_THROW (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
CORBA::COMPLETED_MAYBE));
// The only case left is status == TAO_INVOKE_OK, exit the
// loop. We cannot retry because at this point we either
// got a reply or something with an status of
// COMPLETED_MAYBE, thus we cannot reissue the request if we
// are to satisfy the "at most once" semantics.
break;
}
// Now, get all the "return", "out", and "inout" parameters
// from the response message body ... return parameter is
// first, the rest are in the order defined in the IDL spec
// (which is also the order that DII users are required to
// use).
if (result != 0)
{
result->value ()->_tao_decode (call.inp_stream (),
ACE_TRY_ENV);
ACE_CHECK;
}
args->_tao_incoming_cdr (call.inp_stream (),
CORBA::ARG_OUT | CORBA::ARG_INOUT,
lazy_evaluation,
ACE_TRY_ENV);
}
else
{
TAO_GIOP_Oneway_Invocation call (this,
opname,
ACE_OS::strlen (opname),
this->orb_core_);
for (;;)
{
call.start (ACE_TRY_ENV);
ACE_CHECK;
CORBA::Octet response_flag = ACE_static_cast (CORBA::Octet,
call.sync_scope ());
call.prepare_header (response_flag,
ACE_TRY_ENV);
ACE_CHECK;
this->put_params (call,
args,
ACE_TRY_ENV);
ACE_CHECK;
int status = call.invoke (ACE_TRY_ENV);
ACE_CHECK;
if (status == TAO_INVOKE_RESTART)
continue;
if (status == TAO_INVOKE_EXCEPTION)
return; // Shouldn't happen
if (status != TAO_INVOKE_OK)
ACE_THROW (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
CORBA::COMPLETED_MAYBE));
break;
}
}
}
void
TAO_Stub::do_deferred_call (const CORBA::Request_ptr req,
CORBA::Environment &ACE_TRY_ENV)
{
// @@ TOCCST: why do we keep using this function when ACE+TAO code
// is clearly not cancel safe anymore? Furthermore, all the
// generated code using the Invocation classes is probably not
// cancel safe!
TAO_Synchronous_Cancellation_Required NOT_USED;
// Do a locate_request if necessary/wanted.
// Suspect that you will be forwarded, so be proactive!
// strategy for reducing overhead when you think a request will
// be forwarded. No standard way now to know.
if (this->use_locate_request_ && this->first_locate_request_)
{
// @@ TOCCST: notice how the locate request is only sent for
// dynamic and deferred (!!) calls, nothing is done for static
// calls, the far more common case. IMHO this should just go
// away, after all we have _validate_connection to do the same
// thing!
TAO_GIOP_Locate_Request_Invocation call (this,
this->orb_core_);
// Simply let these exceptions propagate up
// (if any of them occurs.)
call.start (ACE_TRY_ENV);
ACE_CHECK;
call.invoke (ACE_TRY_ENV);
ACE_CHECK;
this->first_locate_request_ = 0;
}
TAO_GIOP_DII_Deferred_Invocation call (this,
this->orb_core_,
req);
// Loop as needed for forwarding; see above.
for (;;)
{
call.start (ACE_TRY_ENV);
ACE_CHECK;
CORBA::Short flag = TAO_TWOWAY_RESPONSE_FLAG;
call.prepare_header (ACE_static_cast (CORBA::Octet, flag),
ACE_TRY_ENV);
ACE_CHECK;
this->put_params (call,
req->arguments (),
ACE_TRY_ENV);
ACE_CHECK;
// Make the call without blocking.
CORBA::ULong status = call.invoke (ACE_TRY_ENV);
ACE_CHECK;
if (status == TAO_INVOKE_RESTART)
continue;
if (status != TAO_INVOKE_OK)
ACE_THROW (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
CORBA::COMPLETED_MAYBE));
// The only case left is status == TAO_INVOKE_OK, exit the
// loop. We cannot retry because at this point we either
// got a reply or something with an status of
// COMPLETED_MAYBE, thus we cannot reissue the request if we
// are to satisfy the "at most once" semantics.
break;
}
}
void
TAO_Stub::put_params (TAO_GIOP_Invocation &call,
CORBA::NVList_ptr args,
CORBA::Environment &ACE_TRY_ENV)
{
args->_tao_encode (call.out_stream (),
this->orb_core_,
CORBA::ARG_IN | CORBA::ARG_INOUT,
ACE_TRY_ENV);
}
#endif /* TAO_HAS_MINIMUM_CORBA */
// ****************************************************************
#if (TAO_HAS_CORBA_MESSAGING == 1)
#if (TAO_HAS_RT_CORBA == 1)
void
TAO_Stub::parse_policies (void)
{
CORBA::PolicyList *policy_list
= this->base_profiles_.policy_list ();
CORBA::ULong length = policy_list->length ();
// CORBA::ULong index = 0;
for (unsigned int i = 0; i < length; ++i)
{
if (((*policy_list)[i]->policy_type () == RTCORBA::PRIORITY_MODEL_POLICY_TYPE))
this->exposed_priority_model ((*policy_list)[i].in ());
else if (((*policy_list)[i]->policy_type () == RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE))
this->exposed_priority_banded_connection ((*policy_list)[i].in ());
else if (((*policy_list)[i]->policy_type () == RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE))
this->exposed_client_protocol ((*policy_list)[i].in ());
}
this->are_policies_parsed_ = 1;
}
TAO_PriorityModelPolicy *
TAO_Stub::exposed_priority_model (void)
{
if (!this->are_policies_parsed_)
this->parse_policies ();
if (!CORBA::is_nil (this->priority_model_policy_))
this->priority_model_policy_->_add_ref ();
return this->priority_model_policy_;
}
void TAO_Stub::exposed_priority_model (CORBA::Policy_ptr policy)
{
if (!CORBA::is_nil (policy))
{
RTCORBA::PriorityModelPolicy *pm_policy = 0;
pm_policy =
RTCORBA::PriorityModelPolicy::_narrow (policy);
if (!CORBA::is_nil (pm_policy))
{
this->priority_model_policy_ =
ACE_static_cast (TAO_PriorityModelPolicy *,
pm_policy);
}
}
}
TAO_PriorityBandedConnectionPolicy *
TAO_Stub::exposed_priority_banded_connection (void)
{
if (!this->are_policies_parsed_)
this->parse_policies ();
if (!CORBA::is_nil (this->priority_banded_connection_policy_))
this->priority_banded_connection_policy_->_add_ref ();
return this->priority_banded_connection_policy_;
}
void
TAO_Stub::exposed_priority_banded_connection (CORBA::Policy_ptr policy)
{
if (!CORBA::is_nil (policy))
{
RTCORBA::PriorityBandedConnectionPolicy_ptr pbc_policy =
RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy);
if (!CORBA::is_nil (pbc_policy))
{
this->priority_banded_connection_policy_ =
ACE_static_cast (TAO_PriorityBandedConnectionPolicy *,
pbc_policy);
}
}
}
TAO_ClientProtocolPolicy *
TAO_Stub::exposed_client_protocol (void)
{
if (!this->are_policies_parsed_)
this->parse_policies ();
if (!CORBA::is_nil (this->client_protocol_policy_))
this->client_protocol_policy_->_add_ref ();
return this->client_protocol_policy_;
}
void
TAO_Stub::exposed_client_protocol (CORBA::Policy_ptr policy)
{
if (!CORBA::is_nil (policy))
{
RTCORBA::ClientProtocolPolicy_ptr cp_policy =
RTCORBA::ClientProtocolPolicy::_narrow (policy);
if (!CORBA::is_nil (cp_policy))
{
this->client_protocol_policy_ =
ACE_static_cast (TAO_ClientProtocolPolicy *,
cp_policy);
}
}
}
#endif /* TAO_HAS_RT_CORBA == 1 */
CORBA::Policy_ptr
TAO_Stub::get_policy (CORBA::PolicyType type,
CORBA::Environment &ACE_TRY_ENV)
{
// No need to lock, the stub only changes its policies at
// construction time...
#if (TAO_HAS_RT_CORBA == 1)
// Validity check. Make sure requested policy type is appropriate
// for this scope.
if (type == RTCORBA::THREADPOOL_POLICY_TYPE
|| type == RTCORBA::SERVER_PROTOCOL_POLICY_TYPE)
ACE_THROW_RETURN (CORBA::INV_POLICY (),
CORBA::Policy::_nil ());
// If we are dealing with a client exposed policy, check if any
// value came in the IOR/reconcile IOR value and overrides.
if (type == RTCORBA::PRIORITY_MODEL_POLICY_TYPE)
return this->exposed_priority_model ();
if (type == RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE)
return this->effective_priority_banded_connection (ACE_TRY_ENV);
if (type == RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE)
return this->effective_client_protocol (ACE_TRY_ENV);
#endif /* TAO_HAS_RT_CORBA == 1 */
if (this->policies_ == 0)
return CORBA::Policy::_nil ();
// Some policies can only be set locally on the client, while others
// can only be exported in the IOR by the server, and yet others can
// be set by both by client and server. Furthermore, reconciliation
// between client-set values and the ones exported in the IOR is
// policy-specific. Therefore, with the current state of things, it
// isn't possible to write generic code for <get_policy> that will
// work for any policy type.
// Currently, we take specific action
// for each of the known client-exposed policies (above), and simply
// look up effective override for any other policy type (below).
// Later, if there is a need/desire for generic code, it can be
// done by pushing the smarts into the policies
// implementations, and will involve modifying PolicyC* and friends,
// e.g., to add methods for policy specific reconciliation, etc.
return this->get_client_policy (type,
ACE_TRY_ENV);
}
CORBA::Policy_ptr
TAO_Stub::get_client_policy (CORBA::PolicyType type,
CORBA::Environment &ACE_TRY_ENV)
{
// No need to lock, the stub only changes its policies at
// construction time...
#if (TAO_HAS_RT_CORBA == 1)
// Validity check. Make sure requested policy type is appropriate
// for this scope.
if (type == RTCORBA::THREADPOOL_POLICY_TYPE
|| type == RTCORBA::SERVER_PROTOCOL_POLICY_TYPE
|| type == RTCORBA::PRIORITY_MODEL_POLICY_TYPE)
ACE_THROW_RETURN (CORBA::INV_POLICY (),
CORBA::Policy::_nil ());
#endif /* TAO_HAS_RT_CORBA == 1 */
CORBA::Policy_var result;
if (this->policies_ != 0)
{
result = this->policies_->get_policy (type,
ACE_TRY_ENV);
ACE_CHECK_RETURN (CORBA::Policy::_nil ());
}
if (CORBA::is_nil (result.in ()))
{
TAO_Policy_Current &policy_current = this->orb_core_->policy_current ();
result = policy_current.get_policy (type,
ACE_TRY_ENV);
ACE_CHECK_RETURN (CORBA::Policy::_nil ());
}
if (CORBA::is_nil (result.in ()))
{
// @@ Must lock, but is is harder to implement than just modifying
// this call: the ORB does take a lock to modify the policy
// manager
TAO_Policy_Manager *policy_manager =
this->orb_core_->policy_manager ();
if (policy_manager != 0)
{
result = policy_manager->get_policy (type,
ACE_TRY_ENV);
ACE_CHECK_RETURN (CORBA::Policy::_nil ());
}
}
if (CORBA::is_nil (result.in ()))
{
result = this->orb_core_->get_default_policy (type,
ACE_TRY_ENV);
ACE_CHECK_RETURN (CORBA::Policy::_nil ());
}
return result._retn ();
}
TAO_Stub *
TAO_Stub::set_policy_overrides (const CORBA::PolicyList & policies,
CORBA::SetOverrideType set_add,
CORBA::Environment &ACE_TRY_ENV)
{
#if (TAO_HAS_RT_CORBA == 1)
// Validity check. Make sure requested policies are allowed to be
// set at this scope.
for (CORBA::ULong i = 0; i < policies.length (); ++i)
{
CORBA::Policy_ptr policy = policies[i];
if (CORBA::is_nil (policy))
continue;
CORBA::ULong slot = policy->policy_type (ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
if (slot == RTCORBA::THREADPOOL_POLICY_TYPE
|| slot == RTCORBA::SERVER_PROTOCOL_POLICY_TYPE
|| slot == RTCORBA::PRIORITY_MODEL_POLICY_TYPE)
ACE_THROW_RETURN (CORBA::NO_PERMISSION (),
0);
}
// We are not required to check for consistency of <policies> with
// overrides at other levels or with policies exported in the IOR.
#endif /* TAO_HAS_RT_CORBA == 1 */
// Notice the use of an explicit constructor....
auto_ptr<TAO_Policy_Manager_Impl> policy_manager (new TAO_Policy_Manager_Impl);
if (set_add == CORBA::SET_OVERRIDE)
{
policy_manager->set_policy_overrides (policies,
set_add,
ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
}
else if (this->policies_ == 0)
{
policy_manager->set_policy_overrides (policies,
CORBA::SET_OVERRIDE,
ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
}
else
{
policy_manager->copy_from (this->policies_,
ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
policy_manager->set_policy_overrides (policies,
set_add,
ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
}
TAO_Stub* stub;
ACE_NEW_RETURN (stub, TAO_Stub (CORBA::string_dup (this->type_id.in ()),
this->base_profiles_,
this->orb_core_),
0);
stub->policies_ = policy_manager.release ();
// Copy the servant ORB if it is present.
stub->servant_orb (this->servant_orb_var ().in ());
return stub;
}
CORBA::PolicyList *
TAO_Stub::get_policy_overrides (const CORBA::PolicyTypeSeq &types,
CORBA::Environment &ACE_TRY_ENV)
{
if (this->policies_ == 0)
return 0;
return this->policies_->get_policy_overrides (types,
ACE_TRY_ENV);
}
CORBA::Boolean
TAO_Stub::validate_connection (CORBA::PolicyList_out inconsistent_policies,
CORBA::Environment &ACE_TRY_ENV)
{
inconsistent_policies = 0;
ACE_UNUSED_ARG (ACE_TRY_ENV);
#if (TAO_HAS_CLIENT_PRIORITY_POLICY == 1)
// Check if we care about Client Priority policy, and store the
// result in the variable called <set>.
int set = 1;
TAO::ClientPriorityPolicy *policy =
this->client_priority ();
if (policy == 0)
set = 0;
else
// Policy is set.
{
TAO::PrioritySpecification priority_spec =
policy->priority_specification (ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
TAO::PrioritySelectionMode mode = priority_spec.mode;
// Don't care about priority.
if (mode == TAO::USE_NO_PRIORITY)
set = 0;
}
// Use Locate Request to establish connection/make sure the object
// is there ...
TAO_GIOP_Locate_Request_Invocation locate_request (this,
this->orb_core_);
//@@ Currently, if we select profiles based on priorities (i.e.,
// ClientPriorityPolicy is set), and we get a FORWARD reply to our
// location request, we don't go to the new location - just return
// 0. This is because we don't yet have full support in
// MProfiles & friends for profiles used based on priorities.
// Once the support is there, we should follow a forwarded object
// to track it down, just like in the case where
// ClientPriorityPolicy is not set. At that point, we can remove
// a lot of 'special case' code from this function, along with
// this comment ;-) (marina).
for (;;)
{
locate_request.start (ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
int status = locate_request.invoke (ACE_TRY_ENV);
ACE_CHECK_RETURN (0);
// We'll get this only if the object was, in fact, forwarded.
if (status == TAO_INVOKE_RESTART)
if (set)
return 0;
else
continue;
if (status != TAO_INVOKE_OK)
{
ACE_THROW_RETURN (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
CORBA::COMPLETED_YES),
0);
}
break;
}
#endif /* TAO_HAS_CLIENT_PRIORITY_POLICY == 1 */
return 1;
}
#endif /* TAO_HAS_CORBA_MESSAGING == 1 */
TAO_Sync_Strategy &
TAO_Stub::sync_strategy (void)
{
#if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
int has_synchronization;
int scope;
this->orb_core_->call_sync_scope_hook (this,
has_synchronization,
scope);
if (has_synchronization == 1)
return this->orb_core_->get_sync_strategy (this,
scope);
#endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
return this->orb_core_->transport_sync_strategy ();
}
CORBA::Policy *
TAO_Stub::relative_roundtrip_timeout (void)
{
CORBA::Policy *result = 0;
this->policies_ = 0;
// No need to lock, the stub only changes its policies at
// construction time...
if (this->policies_ != 0)
result = this->policies_->relative_roundtrip_timeout ();
// No need to lock, the object is in TSS storage....
if (result == 0)
{
TAO_Policy_Current &policy_current =
this->orb_core_->policy_current ();
result = policy_current.relative_roundtrip_timeout ();
}
// @@ Must lock, but is is harder to implement than just modifying
// this call: the ORB does take a lock to modify the policy
// manager
if (result == 0)
{
TAO_Policy_Manager *policy_manager =
this->orb_core_->policy_manager ();
if (policy_manager != 0)
result = policy_manager->relative_roundtrip_timeout ();
}
if (result == 0)
result = this->orb_core_->default_relative_roundtrip_timeout ();
return result;
}
#if (TAO_HAS_CLIENT_PRIORITY_POLICY == 1)
TAO_Client_Priority_Policy *
TAO_Stub::client_priority (void)
{
TAO_Client_Priority_Policy *result = 0;
// No need to lock, the stub only changes its policies at
// construction time...
if (this->policies_ != 0)
result = this->policies_->client_priority ();
// No need to lock, the object is in TSS storage....
if (result == 0)
{
TAO_Policy_Current &policy_current =
this->orb_core_->policy_current ();
result = policy_current.client_priority ();
}
// @@ Must lock, but is is harder to implement than just modifying
// this call: the ORB does take a lock to modify the policy
// manager
if (result == 0)
{
TAO_Policy_Manager *policy_manager =
this->orb_core_->policy_manager ();
if (policy_manager != 0)
result = policy_manager->client_priority ();
}
if (result == 0)
result = this->orb_core_->default_client_priority ();
return result;
}
#endif /* TAO_HAS_CLIENT_PRIORITY_POLICY == 1 */
CORBA::Policy *
TAO_Stub::sync_scope (void)
{
CORBA::Policy *result = 0;
// No need to lock, the stub only changes its policies at
// construction time...
if (this->policies_ != 0)
result = this->policies_->sync_scope ();
this->orb_core_->stubless_sync_scope (result);
return result;
}
#if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
TAO_Buffering_Constraint_Policy *
TAO_Stub::buffering_constraint (void)
{
TAO_Buffering_Constraint_Policy *result = 0;
// No need to lock, the stub only changes its policies at
// construction time...
if (this->policies_ != 0)
result = this->policies_->buffering_constraint ();
// No need to lock, the object is in TSS storage....
if (result == 0)
{
TAO_Policy_Current &policy_current =
this->orb_core_->policy_current ();
result = policy_current.buffering_constraint ();
}
// @@ Must lock, but is is harder to implement than just modifying
// this call: the ORB does take a lock to modify the policy
// manager
if (result == 0)
{
TAO_Policy_Manager *policy_manager =
this->orb_core_->policy_manager ();
if (policy_manager != 0)
result = policy_manager->buffering_constraint ();
}
if (result == 0)
result = this->orb_core_->default_buffering_constraint ();
return result;
}
#endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
#if (TAO_HAS_RT_CORBA == 1)
TAO_PrivateConnectionPolicy *
TAO_Stub::private_connection (void)
{
TAO_PrivateConnectionPolicy *result = 0;
// No need to lock, the stub only changes its policies at
// construction time...
if (this->policies_ != 0)
result = this->policies_->private_connection ();
// No need to lock, the object is in TSS storage....
if (result == 0)
{
TAO_Policy_Current &policy_current =
this->orb_core_->policy_current ();
result = policy_current.private_connection ();
}
// @@ Must lock, but is is harder to implement than just modifying
// this call: the ORB does take a lock to modify the policy
// manager
if (result == 0)
{
TAO_Policy_Manager *policy_manager =
this->orb_core_->policy_manager ();
if (policy_manager != 0)
result = policy_manager->private_connection ();
}
if (result == 0)
result = this->orb_core_->default_private_connection ();
return result;
}
TAO_ClientProtocolPolicy *
TAO_Stub::client_protocol (void)
{
TAO_ClientProtocolPolicy *result = 0;
// No need to lock, the stub only changes its policies at
// construction time...
if (this->policies_ != 0)
result = this->policies_->client_protocol ();
// No need to lock, the object is in TSS storage....
if (result == 0)
{
TAO_Policy_Current &policy_current =
this->orb_core_->policy_current ();
result = policy_current.client_protocol ();
}
// @@ Must lock, but is is harder to implement than just modifying
// this call: the ORB does take a lock to modify the policy
// manager
if (result == 0)
{
TAO_Policy_Manager *policy_manager =
this->orb_core_->policy_manager ();
if (policy_manager != 0)
result = policy_manager->client_protocol ();
}
// No default is used for client priority policy (default creates
// conflict in case the policy is also set for the object on the
// server side).
return result;
}
TAO_PriorityBandedConnectionPolicy *
TAO_Stub::priority_banded_connection (void)
{
TAO_PriorityBandedConnectionPolicy *result = 0;
// No need to lock, the stub only changes its policies at
// construction time...
if (this->policies_ != 0)
result = this->policies_->priority_banded_connection ();
// No need to lock, the object is in TSS storage....
if (result == 0)
{
TAO_Policy_Current &policy_current =
this->orb_core_->policy_current ();
result = policy_current.priority_banded_connection ();
}
// @@ Must lock, but is is harder to implement than just modifying
// this call: the ORB does take a lock to modify the policy
// manager
if (result == 0)
{
TAO_Policy_Manager *policy_manager =
this->orb_core_->policy_manager ();
if (policy_manager != 0)
result = policy_manager->priority_banded_connection ();
}
if (result == 0)
result = this->orb_core_->default_priority_banded_connection ();
return result;
}
TAO_PriorityBandedConnectionPolicy *
TAO_Stub::effective_priority_banded_connection (CORBA::Environment &ACE_TRY_ENV)
{
// Get effective override.
TAO_PriorityBandedConnectionPolicy *override =
this->priority_banded_connection ();
// Get the value from the ior.
TAO_PriorityBandedConnectionPolicy *exposed =
this->exposed_priority_banded_connection ();
// Reconcile client-exposed and locally set values.
if (exposed == 0)
return override;
if (override == 0)
return exposed;
// Both override and exposed have been set.
// See if either of them has empty priority bands.
CORBA::Object_var auto_release_exp = exposed;
CORBA::Object_var auto_release_ov = override;
if (exposed->priority_bands_rep ().length () == 0)
{
auto_release_ov._retn ();
return override;
}
if (override->priority_bands_rep ().length () == 0)
{
auto_release_exp._retn ();
return exposed;
}
// Both override and exposed have been set and neither has empty
// priority bands. This is illegal (ptc/99-05-03, sec. 4.12.1).
ACE_THROW_RETURN (CORBA::INV_POLICY (),
0);
}
TAO_ClientProtocolPolicy *
TAO_Stub::effective_client_protocol (CORBA::Environment &ACE_TRY_ENV)
{
// Get effective override.
TAO_ClientProtocolPolicy *override =
this->client_protocol ();
// Get the value from the ior.
TAO_ClientProtocolPolicy *exposed =
this->exposed_client_protocol ();
// Reconcile client-exposed and locally set values.
if (exposed == 0)
return override;
if (override == 0)
return exposed;
// Both override and exposed have been set.
// See if either of them has empty priority bands.
CORBA::Object_var auto_release_exp = exposed;
CORBA::Object_var auto_release_ov = override;
if (exposed->protocols_rep ().length () == 0)
{
auto_release_ov._retn ();
return override;
}
if (override->protocols_rep ().length () == 0)
{
auto_release_exp._retn ();
return exposed;
}
// Both override and exposed have been set and neither has empty
// protocols. This is illegal (ptc/99-05-03, sec. 4.15.4).
ACE_THROW_RETURN (CORBA::INV_POLICY (),
0);
}
#endif /* TAO_HAS_RT_CORBA == 1 */
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
#if (TAO_HAS_CORBA_MESSAGING == 1)
template class auto_ptr<TAO_Policy_Manager_Impl>;
template class ACE_Auto_Basic_Ptr<TAO_Policy_Manager_Impl>;
#endif /* TAO_HAS_CORBA_MESSAGING == 1 */
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#if (TAO_HAS_CORBA_MESSAGING == 1)
#pragma instantiate auto_ptr<TAO_Policy_Manager_Impl>
#pragma instantiate ACE_Auto_Basic_Ptr<TAO_Policy_Manager_Impl>
#endif /* TAO_HAS_CORBA_MESSAGING == 1 */
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|