summaryrefslogtreecommitdiff
path: root/TAO/tao/ORB_Core.cpp
blob: 7da08d0f8cb0c98b441d30481b9262037c478ab0 (plain)
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
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
#include "tao/ORB_Core.h"
#include "tao/ORB_Core_TSS_Resources.h"
#include "tao/ORB_Table.h"
#include "tao/TAO_Internal.h"
#include "tao/default_server.h"
#include "tao/Profile.h"
#include "tao/Stub.h"
#include "tao/LF_Follower.h"
#include "tao/Leader_Follower.h"
#include "tao/LF_Event_Loop_Thread_Helper.h"
#include "tao/Connector_Registry.h"
#include "tao/Transport_Queueing_Strategies.h"
#include "tao/Object_Loader.h"
#include "tao/ObjectIdListC.h"
#include "tao/BiDir_Adapter.h"
#include "tao/ZIOP_Adapter.h"
#include "tao/Collocation_Resolver.h"
#include "tao/Flushing_Strategy.h"
#include "tao/Request_Dispatcher.h"
#include "tao/Stub_Factory.h"
#include "tao/Thread_Lane_Resources.h"
#include "tao/Thread_Lane_Resources_Manager.h"
#include "tao/TSS_Resources.h"
#include "tao/Protocols_Hooks.h"
#include "tao/Network_Priority_Protocols_Hooks.h"
#include "tao/IORInterceptor_Adapter.h"
#include "tao/IORInterceptor_Adapter_Factory.h"
#include "tao/debug.h"
#include "tao/TAOC.h"
#include "tao/Endpoint_Selector_Factory.h"
#include "tao/Client_Strategy_Factory.h"
#include "tao/Adapter_Factory.h"
#include "tao/Adapter.h"
#include "tao/GUIResource_Factory.h"
#include "tao/PolicyFactory_Registry_Adapter.h"
#include "tao/PolicyFactory_Registry_Factory.h"
#include "tao/ORBInitializer_Registry_Adapter.h"
#include "tao/Codeset_Manager.h"
#include "tao/GIOP_Fragmentation_Strategy.h"
#include "tao/SystemException.h"

#include "tao/Valuetype_Adapter.h"
#include "tao/Valuetype_Adapter_Factory.h"

#if (TAO_HAS_CORBA_MESSAGING == 1)
#include "tao/Policy_Manager.h"
#include "tao/Policy_Current.h"
#endif /* TAO_HAS_CORBA_MESSAGING == 1 */

#include "ace/Reactor.h"
#include "ace/Dynamic_Service.h"
#include "ace/Arg_Shifter.h"
#include "ace/Argv_Type_Converter.h"
#include "ace/Static_Object_Lock.h"
#include "ace/Auto_Ptr.h"
#include "ace/CORBA_macros.h"
#include "ace/Logging_Strategy.h"

#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
// Needed to set ACE_LOG_MSG::msg_ostream()
// FUZZ: disable check_for_streams_include
#  include "ace/streams.h"
#endif /* !ACE_LACKS_IOSTREAM_TOTALLY */

#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_string.h"
#include "ace/Message_Block.h"
#include <cstring>
#include <memory>

#if TAO_HAS_INTERCEPTORS == 1
# include "tao/ClientRequestInterceptor_Adapter.h"
# include "tao/ClientRequestInterceptor_Adapter_Factory.h"
# include "tao/ServerRequestInterceptor_Adapter.h"
# include "tao/ServerRequestInterceptor_Adapter_Factory.h"
#endif  /* TAO_HAS_INTERCEPTORS == 1  */

#if !defined (__ACE_INLINE__)
# include "tao/ORB_Core.inl"
#endif /* ! __ACE_INLINE__ */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

ACE_STATIC_SVC_DEFINE(TAO_ORB_Core_Static_Resources,
                      ACE_TEXT ("TAO_ORB_Core_Static_Resources"),
                      ACE_SVC_OBJ_T,
                      &ACE_SVC_NAME (TAO_ORB_Core_Static_Resources),
                      ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
                       0)
ACE_FACTORY_DEFINE (TAO, TAO_ORB_Core_Static_Resources)

// ****************************************************************

CORBA::Environment&
TAO_default_environment ()
{
  return *TAO_TSS_Resources::instance ()->default_environment_;
}

// ****************************************************************

// Initialize instance_ to 0, since this is what we test for in the call
// to instance ().  Note that this does not require a constructor call, so
// it is always initialized by the time that instance () can be called.
//TAO_ORB_Core_Static_Resources* TAO_ORB_Core_Static_Resources::instance_ = 0;

// Force an instance to be created at module initialization time,
// since we do not want to worry about double checked locking and
// the race condition to initialize the lock.
TAO_ORB_Core_Static_Resources*
TAO_ORB_Core_Static_Resources::initialization_reference_ =
  TAO_ORB_Core_Static_Resources::instance ();

TAO_ORB_Core_Static_Resources*
TAO_ORB_Core_Static_Resources::instance ()
{
  ACE_Service_Gestalt *current = ACE_Service_Config::current();
  TAO_ORB_Core_Static_Resources* tocsr =
    ACE_Dynamic_Service<TAO_ORB_Core_Static_Resources>::instance
    (current, "TAO_ORB_Core_Static_Resources", true);

  if (tocsr == nullptr)
    {
      // This new is never freed on purpose.  The data specified by
      // it needs to be around for the last shared library that references
      // this class.  This could occur in a destructor in a shared library
      // that is unloaded after this one.  One solution to avoid this
      // harmless memory leak would be to use reference counting.
      current->process_directive(ace_svc_desc_TAO_ORB_Core_Static_Resources);
      tocsr = ACE_Dynamic_Service<TAO_ORB_Core_Static_Resources>::instance
        (current, "TAO_ORB_Core_Static_Resources", true);

      ACE_Service_Gestalt *global = ACE_Service_Config::global();
      if (current != global)
        {
          TAO_ORB_Core_Static_Resources* global_tocsr =
            ACE_Dynamic_Service<TAO_ORB_Core_Static_Resources>::instance
            (global,"TAO_ORB_Core_Static_Resources");

          if (global_tocsr != nullptr)
            *tocsr = *global_tocsr;
        }
    }

  return tocsr;
}

TAO_ORB_Core_Static_Resources::TAO_ORB_Core_Static_Resources ()
  : network_priority_protocols_hooks_name_ (
      "Network_Priority_Protocols_Hooks"),
    connection_timeout_hook_ (nullptr),
    resource_factory_name_ ("Resource_Factory"),
    dynamic_adapter_name_ ("Dynamic_Adapter"),
    ifr_client_adapter_name_ ("IFR_Client_Adapter"),
    typecodefactory_adapter_name_ ("TypeCodeFactory_Adapter"),
    iorinterceptor_adapter_factory_name_ ("IORInterceptor_Adapter_Factory"),
    valuetype_adapter_factory_name_ ("Valuetype_Adapter_Factory"),
    alt_connection_timeout_hook_ (nullptr)
{
}

TAO_ORB_Core_Static_Resources&
TAO_ORB_Core_Static_Resources::operator=(const TAO_ORB_Core_Static_Resources& other)
{
  this->network_priority_protocols_hooks_name_ =
    other.network_priority_protocols_hooks_name_;
  this->connection_timeout_hook_ = other.connection_timeout_hook_;
  this->resource_factory_name_ = other.resource_factory_name_;
  this->dynamic_adapter_name_ = other.dynamic_adapter_name_;
  this->ifr_client_adapter_name_ = other.ifr_client_adapter_name_;
  this->typecodefactory_adapter_name_ = other.typecodefactory_adapter_name_;
  this->iorinterceptor_adapter_factory_name_ =
    other.iorinterceptor_adapter_factory_name_;
  this->valuetype_adapter_factory_name_ =
    other.valuetype_adapter_factory_name_;
  this->alt_connection_timeout_hook_ = other.alt_connection_timeout_hook_;
  return *this;
}

// ****************************************************************

TAO_ORB_Core::TAO_ORB_Core (const char *orbid,
                            ACE_Intrusive_Auto_Ptr<ACE_Service_Gestalt> gestalt)
  : protocols_hooks_ (nullptr),
    network_priority_protocols_hooks_ (nullptr),
#if TAO_USE_LOCAL_MEMORY_POOL == 1
    use_local_memory_pool_ (true),
#else
    use_local_memory_pool_ (false),
#endif
    lock_ (),
    thread_lane_resources_manager_ (nullptr),
    collocation_resolver_ (nullptr),
    stub_factory_ (nullptr),
    protocol_factories_ (nullptr),
    implrepo_service_ (CORBA::Object::_nil ()),
    use_implrepo_ (0),
    imr_endpoints_in_ior_ (1),
    typecode_factory_ (CORBA::Object::_nil ()),
    codec_factory_ (CORBA::Object::_nil ()),
    compression_manager_ (CORBA::Object::_nil ()),
    dynany_factory_ (CORBA::Object::_nil ()),
    ior_manip_factory_ (CORBA::Object::_nil ()),
    ior_table_ (CORBA::Object::_nil ()),
    async_ior_table_ (CORBA::Object::_nil ()),
    monitor_ (CORBA::Object::_nil ()),
    orb_ (CORBA::ORB::_nil ()),
    root_poa_ (),
    orb_params_ (),
    init_ref_map_ (TAO_DEFAULT_OBJECT_REF_TABLE_SIZE),
    object_ref_table_ (),
    object_key_table_ (),
    orbid_ (ACE_OS::strdup (orbid ? orbid : "")),
    resource_factory_ (nullptr),
    client_factory_ (nullptr),
    server_factory_ (nullptr),
    ft_send_extended_sc_ (false),
    opt_for_collocation_ (true),
    use_global_collocation_ (true),
    collocation_strategy_ (TAO_DEFAULT_COLLOCATION_STRATEGY),

#if (TAO_HAS_CORBA_MESSAGING == 1)

    policy_manager_ (nullptr),
    default_policies_ (nullptr),
    policy_current_ (nullptr),

#endif /* TAO_HAS_CORBA_MESSAGING == 1 */

    poa_current_ (),
    adapter_registry_ (this),
    poa_adapter_ (nullptr),
    tm_ (),
    tss_cleanup_funcs_ (),
    tss_resources_ (),
    has_shutdown_ (true),  // Start the ORB in a  "shutdown" state.  Only
                           // after CORBA::ORB_init() is called will the
                           // ORB no longer be shutdown.  This does not
                           // mean that the ORB can be reinitialized.  It
                           // can only be initialized once.
    thread_per_connection_use_timeout_ (1),
    open_lock_ (),
    endpoint_selector_factory_ (nullptr),
#if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
    eager_transport_queueing_strategy_ (nullptr),
    delayed_transport_queueing_strategy_ (nullptr),
    flush_transport_queueing_strategy_ (nullptr),
#endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
    refcount_ (1),
    policy_factory_registry_ (nullptr),
    orbinitializer_registry_ (nullptr),
#if (TAO_HAS_INTERCEPTORS == 1)
    pi_current_ (CORBA::Object::_nil ()),
    client_request_interceptor_adapter_ (nullptr),
    server_request_interceptor_adapter_ (nullptr),
#endif  /* TAO_HAS_INTERCEPTORS == 1 */
    ior_interceptor_adapter_ (nullptr),
    valuetype_adapter_ (nullptr),
    parser_registry_ (),
    bidir_adapter_ (nullptr),
    bidir_giop_policy_ (false),
    ziop_adapter_ (nullptr),
    ziop_enabled_ (false),
    flushing_strategy_ (nullptr),
    codeset_manager_ (nullptr),
    config_ (gestalt),
    sync_scope_hook_ (nullptr),
    default_sync_scope_ (Messaging::SYNC_WITH_TRANSPORT),
    timeout_hook_ (nullptr)
{
#if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)

  ACE_NEW (this->flush_transport_queueing_strategy_,
           TAO::Flush_Transport_Queueing_Strategy);

#endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */

#if (TAO_HAS_CORBA_MESSAGING == 1)

  ACE_NEW (this->policy_manager_,
           TAO_Policy_Manager);

  ACE_NEW (this->default_policies_,
           TAO_Policy_Set (TAO_POLICY_ORB_SCOPE));

  ACE_NEW (this->policy_current_,
           TAO_Policy_Current);

#endif /* TAO_HAS_CORBA_MESSAGING == 1 */

  // Initialize the default request dispatcher.
  ACE_NEW (this->request_dispatcher_,
           TAO_Request_Dispatcher);

  this->set_sync_scope_hook (TAO_ORB_Core::default_sync_scope_hook);
}

TAO_ORB_Core::~TAO_ORB_Core ()
{
  delete this->thread_lane_resources_manager_;

  delete this->flushing_strategy_;

  ACE_OS::free (this->orbid_);

#if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)

  delete this->eager_transport_queueing_strategy_;
  delete this->delayed_transport_queueing_strategy_;
  delete this->flush_transport_queueing_strategy_;

#endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */

#if (TAO_HAS_CORBA_MESSAGING == 1)

  ::CORBA::release (this->policy_manager_);
  delete this->default_policies_;
  ::CORBA::release (this->policy_current_);

#endif /* TAO_HAS_CORBA_MESSAGING == 1 */

  delete this->request_dispatcher_;

  delete this->policy_factory_registry_;

  // Don't delete, is a process wide singleton shared by all orbs
  orbinitializer_registry_ = nullptr;

  ::CORBA::release (this->orb_);

  delete this->codeset_manager_;
  this->codeset_manager_ = nullptr;

  // This will destroy the service repository for this core
  (void) TAO::ORB::close_services (this->config_);
}

int
TAO_ORB_Core::init (int &argc, char *argv[] )
{
  // Right now, this code expects to begin parsing in argv[1] rather
  // than argv[0].  I don't think that's wise.  I think we need to
  // change that convention to argv[0] and let the initializing code
  // make any necessary shifts.
  //
  // Parse arguments to the ORB.  Typically the ORB is passed
  // arguments straight from the command line, so we will simply pass
  // through them and respond to the ones we understand and ignore
  // those we don't.
  //
  // In some instances, we may actually build another vector of
  // arguments and stash it for use initializing other components such
  // as the RootPOA.

  bool use_ior = true;
  int cdr_tradeoff = ACE_DEFAULT_CDR_MEMCPY_TRADEOFF;

  // The following things should be changed to use the ACE_Env_Value<>
  // template sometime.

  // Name Service port use for Multicast
  unsigned short ns_port = 0;

  // Trading Service port used for Multicast
  unsigned short ts_port = 0;

  // Implementation Repository Service port #.
  unsigned short ir_port = 0;

  // Buffer sizes for kernel socket buffers
  // @@ should be a default defined for each protocol implementation?
  //    since we may have protocols loaded which use shared memory of
  //    some form, fredk
  int rcv_sock_size = -1;
  int snd_sock_size = -1;

  // Use TCP_NODELAY.
  int nodelay = 1;

  // Use SO_KEEPALIVE (default 0).
  int so_keepalive = 0;

  // Use SO_DONTROUTE (default 0)
  int so_dontroute = 0;

  // Number of hops for a datagram sent through socket.
  int ip_hoplimit = -1;

  // Use IP_MILTICAST_LOOP (default 1).
  int ip_multicastloop = 1;

  // Use dotted decimal addresses
  // @@ This option will be treated as a suggestion to each loaded
  //    protocol to use a character representation for the numeric
  //    address, otherwise use a logical name. fredk
#if (TAO_USE_DOTTED_DECIMAL_ADDRESSES == 1)
  int dotted_decimal_addresses = 1;
#else
  int dotted_decimal_addresses = 0;
#endif /* TAO_USE_DOTTED_DECIMAL_ADDRESSES */

  // Disable looking up the host name for incoming connections.
  int no_server_side_name_lookups = 0;

#if defined (TAO_STD_PROFILE_COMPONENTS)
  bool std_profile_components = true;
#else
  bool std_profile_components = false;
#endif /* TAO_STD_PROFILE_COMPONENTS */

  int linger = TAO_SO_LINGER;
  time_t accept_error_delay = TAO_ACCEPT_ERROR_DELAY;
  bool use_parallel_connects = TAO_USE_PARALLEL_CONNECT;

  // Copy command line parameter not to use original.
  ACE_Argv_Type_Converter command_line (argc, argv);

  ACE_Arg_Shifter arg_shifter (command_line.get_argc (),
                               command_line.get_TCHAR_argv ());

  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                    monitor,
                    this->lock_,
                    -1);

#if (TAO_NEGOTIATE_CODESETS == 1)
  bool negotiate_codesets = true;
#else
  bool negotiate_codesets = false;
#endif /* TAO_NEGOTIATE_CODESETS */

  // Pick up the value of the use_implrepo_ flag from an environment variable
  // called "TAO_USE_IMR". Do it here so that it can be overridden by
  // the "-ORBUseIMR" command line argument.
  //
  char* const use_IMR_env_var_value = ACE_OS::getenv  ("TAO_USE_IMR") ;
  if  (use_IMR_env_var_value != nullptr)
    {
      this->use_implrepo_ = ACE_OS::atoi  (use_IMR_env_var_value) ;
    }

  while (arg_shifter.is_anything_left ())
    {
      const ACE_TCHAR *current_arg = nullptr;

      ////////////////////////////////////////////////////////////////
      // begin with the 'parameterless' flags                       //
      ////////////////////////////////////////////////////////////////
      if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBDottedDecimalAddresses"))))
        {
          // Use dotted decimal addresses
          // @@ this should be renamed.  See above comment. fredk
          dotted_decimal_addresses =
            ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBNoServerSideNameLookups"))))
        {
          // Don't look up the host name for incoming connections
          no_server_side_name_lookups =
            ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBNameServicePort"))))
        {
          // Specify the port number for the NameService.
          // Unrelated to ORB Protocols, this is used for multicast.

          ns_port = static_cast <CORBA::UShort> (ACE_OS::atoi (current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBMulticastDiscoveryEndpoint"))))
        {
          // Specify mcast address:port@network_interface for the
          // Naming Service Multicast Discovery Protocol.
          // If there is no colon, its only the port no.
          // If there is a '@' also, it means that the network
          // interface name is specified.
          this->orb_params ()->mcast_discovery_endpoint (
            ACE_TEXT_ALWAYS_CHAR(current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBNodelay"))))
        {
          // Use TCP_NODELAY or not.
          nodelay =
            ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBKeepalive"))))
        {
          // Use SO_KEEPALIVE or not.
          so_keepalive =
            ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBDontRoute"))))
        {
          // Use SO_DONTROUTE or not.
          so_dontroute =
            ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBIPHopLimit"))))
        {
          // Number of IP hops.
          ip_hoplimit =
            ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBIPMulticastLoop"))))
        {
          // Use IP_MULTICAST_LOOP or not.
          ip_multicastloop =
            ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBTradingServicePort"))))
        {
          // Specify the port number for the TradingService.

          ts_port = static_cast <CORBA::UShort> (ACE_OS::atoi (current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBImplRepoServicePort"))))
        {
          // Specify the multicast port number for the Implementation
          // Repository.
          ir_port = static_cast <CORBA::UShort> (ACE_OS::atoi (current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBRcvSock"))))
        {
          // @@ All protocol implementation may not use sockets, so
          //    this can either be a generic I/O Buffer size or
          //    Buffer info can be a per protocol specification, fredk

          // Specify the size of the socket's receive buffer

          rcv_sock_size = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBSndSock"))))
        {
          // @@ All protocol implementation may not use sockets, so
          //    this can either be a generic I/O Buffer size or
          //    Buffer info can be a per protocol specification, fredk

          // Specify the size of the socket's send buffer
          snd_sock_size = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBObjRefStyle"))))
        {
          // Specifies the style of printed objrefs: URL or IOR
          //
          // BEGIN COMMENTS FROM IIOP-1.4 On Win32, we should be
          // collecting information from the Registry such as what
          // ORBs are configured, specific configuration details like
          // whether they generate IOR or URL style stringified
          // objrefs and which addresses they listen to (e.g. allowing
          // multihomed hosts to implement firewalls), user-meaningful
          // orb names (they will normally indicate domains), and
          // more.
          //
          // On UNIX, we should collect that from some private config
          // file.
          //
          // Instead, this just treats the "internet" ORB name
          // specially and makes it always use URL-style stringified
          // objrefs, where the hostname and TCP port number are
          // explicit (and the whole objref is readable by mortals).
          // BEGIN COMMENTS FROM IIOP-1.4
          const ACE_TCHAR *opt = current_arg;
          if (ACE_OS::strcasecmp (opt, ACE_TEXT("URL")) == 0)
            use_ior = false;
          else if (ACE_OS::strcasecmp (opt, ACE_TEXT("IOR")) == 0)
            use_ior = true;

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBCollocationStrategy"))))
        {
          // Specify which collocation policy we want to use.
          const ACE_TCHAR *opt = current_arg;
          if (ACE_OS::strcasecmp (opt, ACE_TEXT("thru_poa")) == 0)
            {
              this->collocation_strategy_ = TAO_COLLOCATION_THRU_POA;
            }
          else if (ACE_OS::strcasecmp (opt, ACE_TEXT("direct")) == 0)
            {
              this->collocation_strategy_ = TAO_COLLOCATION_DIRECT;
            }
          else if (ACE_OS::strcasecmp (opt, ACE_TEXT("best")) == 0)
            {
              this->collocation_strategy_ = TAO_COLLOCATION_BEST;
            }

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBCollocation"))))
        {
          // Specify whether we want to optimize against collocation
          // objects.  Valid arguments are: "global", "no", and "per-orb".
          // Default is global.

          const ACE_TCHAR *opt = current_arg;
          if (ACE_OS::strcasecmp (opt, ACE_TEXT("global")) == 0)
            {
              this->opt_for_collocation_ = true;
              this->use_global_collocation_ = true;
            }
          else if (ACE_OS::strcasecmp (opt, ACE_TEXT("NO")) == 0)
            {
              this->opt_for_collocation_ = false;
              this->use_global_collocation_ = false;
            }
          else if (ACE_OS::strcasecmp (opt, ACE_TEXT("per-orb")) == 0)
            {
              this->opt_for_collocation_ = true;
              this->use_global_collocation_ = false;
            }
          else
            {
              TAOLIB_DEBUG ((LM_WARNING,
                          ACE_TEXT ("WARNING: Unknown option to ")
                          ACE_TEXT ("'-ORBCollocation': %s\n"), opt));
            }

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                     (ACE_TEXT("-ORBIIOPClientPortBase"))))
        {
          this->orb_params ()->iiop_client_port_base (ACE_OS::atoi (current_arg));
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                     (ACE_TEXT("-ORBIIOPClientPortSpan"))))
        {
          this->orb_params ()->iiop_client_port_span (ACE_OS::atoi (current_arg));
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBPreferredInterfaces"))) ||
               nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBPreferredInterface"))) )
        {
          if (this->orb_params ()->preferred_interfaces (
                ACE_TEXT_ALWAYS_CHAR (current_arg)) == false)
            throw ::CORBA::INTERNAL (
              CORBA::SystemException::_tao_minor_code (
                TAO_ORB_CORE_INIT_LOCATION_CODE,
                0),
              CORBA::COMPLETED_NO);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBEnforcePreferredInterfaces"))) ||
               nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBEnforcePreferredInterface"))) )
        {
          this->orb_params ()->enforce_pref_interfaces (
            !!ACE_OS::atoi (current_arg));
          arg_shifter.consume_arg ();
        }
#if defined (ACE_HAS_IPV6)
      else if (0 != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBPreferIPV6Interfaces"))))
        {
          int const prefer_ipv6_interfaces = ACE_OS::atoi (current_arg);
          if (prefer_ipv6_interfaces)
            this->orb_params ()->prefer_ipv6_interfaces (true);
          else
            this->orb_params ()->prefer_ipv6_interfaces (false);

          arg_shifter.consume_arg ();
        }
      else if (0 != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBConnectIPV6Only"))))
        {
          int const connect_ipv6_only = ACE_OS::atoi (current_arg);
          if (connect_ipv6_only)
            this->orb_params ()->connect_ipv6_only (true);
          else
            this->orb_params ()->connect_ipv6_only (false);

          arg_shifter.consume_arg ();
        }
      else if ((current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBUseIPV6LinkLocal"))))
        {
          int const use_ipv6_link_local = ACE_OS::atoi (current_arg);
          if (use_ipv6_link_local)
            this->orb_params ()->use_ipv6_link_local (true);
          else
            this->orb_params ()->use_ipv6_link_local (false);

          arg_shifter.consume_arg ();
        }
#endif /* ACE_HAS_IPV6 */
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBCDRTradeoff"))))
        {
          cdr_tradeoff = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }

      // A new <ObjectID>:<IOR> mapping has been specified. This will be
      // used by the resolve_initial_references ().

      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBInitRef"))))
        {
          const ACE_TCHAR *pos = ACE_OS::strchr (current_arg, '=');
          if (pos == nullptr)
            {
              TAOLIB_ERROR ((LM_ERROR,
                          ACE_TEXT ("Invalid ORBInitRef argument '%s'")
                          ACE_TEXT ("format is ObjectID=IOR\n"),
                          current_arg));
              throw ::CORBA::INTERNAL (
                CORBA::SystemException::_tao_minor_code (
                  TAO_ORB_CORE_INIT_LOCATION_CODE,
                  0),
                CORBA::COMPLETED_NO);
            }
          ACE_CString object_id (ACE_TEXT_ALWAYS_CHAR(current_arg),
                                 pos - current_arg);
          ACE_CString IOR (ACE_TEXT_ALWAYS_CHAR(pos + 1));
          if (!this->init_ref_map_.insert (
                 std::make_pair (InitRefMap::key_type (object_id),
                                 InitRefMap::data_type (IOR))).second)
            {
              TAOLIB_ERROR ((LM_ERROR,
                          ACE_TEXT ("Duplicate -ORBInitRef ")
                          ACE_TEXT ("argument '%s'\n"),
                          current_arg));
              throw ::CORBA::INTERNAL (
                CORBA::SystemException::_tao_minor_code (
                  TAO_ORB_CORE_INIT_LOCATION_CODE,
                  0),
                CORBA::COMPLETED_NO);
            }
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBDefaultInitRef"))))
        {
          // Set the list of prefixes from -ORBDefaultInitRef.
          this->orb_params ()->default_init_ref
            (ACE_TEXT_ALWAYS_CHAR(current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBStdProfileComponents"))))
        {
          std_profile_components =
            ACE_OS::atoi (current_arg);
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBAMICollocation"))))
        {
          int const ami_collocation = ACE_OS::atoi (current_arg);
          if (ami_collocation)
            this->orb_params ()->ami_collication (true);
          else
            this->orb_params ()->ami_collication (false);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBResources"))))
        {
          TAOLIB_DEBUG ((LM_WARNING,
                      ACE_TEXT ("\"-ORBResources\" has been ")
                      ACE_TEXT ("deprecated.\n")));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBLogFile"))))
        {
          // redirect all TAOLIB_DEBUG and TAOLIB_ERROR output to a file
          // USAGE: -ORBLogFile <file>
          // default: if <file> is present     = append
          //          if <file> is not present = create

          const ACE_TCHAR *file_name = current_arg;
          arg_shifter.consume_arg ();

          // would rather use ACE_OSTREAM_TYPE out here..
          // but need ACE_FSTREAM_TYPE to call ->open(...)
          // and haven't found such a macro to rep FILE* and/or fstream*

#if defined (ACE_LACKS_IOSTREAM_TOTALLY)

          FILE* output_stream = ACE_OS::fopen (file_name, ACE_TEXT ("a"));

          ACE_LOG_MSG->msg_ostream (output_stream, 1);

#else /* ! ACE_LACKS_IOSTREAM_TOTALLY */

          ofstream* output_stream = nullptr;

          //
          // note: we are allocating dynamic memory here....but
          // I assume it will persist for the life of the program
          //

          ACE_NEW_THROW_EX (output_stream,
                            ofstream (),
                            CORBA::NO_MEMORY (
                              CORBA::SystemException::_tao_minor_code (
                                TAO_ORB_CORE_INIT_LOCATION_CODE,
                                ENOMEM),
                              CORBA::COMPLETED_NO));

          output_stream->open (ACE_TEXT_ALWAYS_CHAR (file_name),
                               ios::out | ios::app);

          if (!output_stream->bad ())
            {
              ACE_LOG_MSG->msg_ostream (output_stream, 1);
            }

#endif /* ACE_LACKS_IOSTREAM_TOTALLY */

          ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR | ACE_Log_Msg::LOGGER);
          ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBVerboseLogging"))))
        {
          unsigned long const verbose_logging = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();

          typedef void (ACE_Log_Msg::*PTMF)(u_long);
          PTMF flagop = &ACE_Log_Msg::set_flags;
          u_long value;

          switch (verbose_logging)
            {
            case 0:
              flagop = &ACE_Log_Msg::clr_flags;
              value = ACE_Log_Msg::VERBOSE | ACE_Log_Msg::VERBOSE_LITE;
              break;
            case 1:
              value = ACE_Log_Msg::VERBOSE_LITE; break;
            default:
              value = ACE_Log_Msg::VERBOSE; break;
            }

          (ACE_LOG_MSG->*flagop)(value);
        }
      else if ((current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBHandleLoggingStrategyEvents"))))
        {
          ACE_Logging_Strategy *logging_strategy =
            dynamic_cast<ACE_Logging_Strategy*> (
              ACE_Dynamic_Service<ACE_Service_Object>::instance (current_arg));

          if (logging_strategy != nullptr)
            {
              logging_strategy->reactor (this->reactor ());
            }

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBUseIMR"))))
        {
          // Use IR or not.
          this->use_implrepo_ = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBIMREndpointsInIOR"))))
        {
          this->imr_endpoints_in_ior_ = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBid"))))
        {
          // The ORBid is actually set in ORB_init(), and then passed
          // to the TAO_ORB_Core() constructor.  However, in the case
          // where the ORBid third argument to ORB_init() is not zero,
          // any "-ORBid" arguments in the argv argument list are
          // supposed to be ignored, according to the CORBA spec.  As
          // such, "-ORBid" must be removed from the argument list
          // since ORB_init() must remove all "-ORB" option
          // arguments.

          // We obtain a lock on the ORB table when setting the
          // ORBid.  For this reason we should *not* set the ORBid
          // here.  CORBA::ORB_init() does all of the proper locking
          // and setting.

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBServerId"))))
        {
          // The this->server_id_ is to uniquely identify a server to
          // an IMR.
          // Fill in later.
          this->server_id_.set(ACE_TEXT_ALWAYS_CHAR(current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
               (ACE_TEXT("-ORBLingerTimeout"))))
        {
          linger = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
               (ACE_TEXT("-ORBAcceptErrorDelay"))))
        {
          accept_error_delay = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBEndpoint"))))
        {
          // Each "endpoint" is of the form:
          //
          //   protocol://V.v@addr1,addr2,...,addrN
          //
          // or:
          //
          //   protocol://addr1,addr2,...,addrN
          //
          // where "V.v" is an optional protocol version for each
          // addr.  All endpoint strings should be of the above
          // form(s).
          //
          // Multiple sets of endpoint may be separated by a semi-colon `;'.
          // For example:
          //
          //   corbaloc:space:2001,1.2@odyssey:2010;uiop://foo,bar
          //
          // All endpoint strings should be of the above form(s).

          this->set_endpoint_helper (TAO_DEFAULT_LANE,
                                     ACE_TEXT_ALWAYS_CHAR (current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBListenEndpoints"))))
        {
          // This option is similar to the -ORBEndPoint option. May be
          // ORBEndpoint option will be deprecated in future. But, for
          // now, I (Priyanka) am leaving so that both options can be
          // used.

          this->set_endpoint_helper (TAO_DEFAULT_LANE,
                                     ACE_TEXT_ALWAYS_CHAR (current_arg));

          arg_shifter.consume_arg ();
        }
      else if ((nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBLaneEndpoint")))) ||
               (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBLaneListenEndpoints")))))
        {
          // This option is similar to the -ORBEndPoint option but
          // specifies endpoints for each lane.

          if (arg_shifter.is_option_next ())
            return -1;

          ACE_CString lane (ACE_TEXT_ALWAYS_CHAR (current_arg));
          arg_shifter.consume_arg ();

          if (arg_shifter.is_option_next ())
            return -1;

          ACE_CString endpoints (ACE_TEXT_ALWAYS_CHAR
                                  (arg_shifter.get_current ()));
          arg_shifter.consume_arg ();

          this->set_endpoint_helper (lane, endpoints);
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBNoProprietaryActivation"))))
        {
          // This option can be used to set to not use any proprietary
          // activation framework. The only TAO proprietary activation
          // framework is IMR. So, by setting this option in TAO, the
          // IMR shouldnt be used .. even if the ORBUseIMR option is
          // set.
          // Fill in later
          // @@ To do later: Priyanka.

          throw ::CORBA::NO_IMPLEMENT ();
        }
       else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                 (ACE_TEXT("-ORBUseSharedProfile"))))
         {
           this->orb_params ()->shared_profile (ACE_OS::atoi (current_arg));

           arg_shifter.consume_arg ();
         }
       else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                 (ACE_TEXT("-ORBNegotiateCodesets"))))
         {
           negotiate_codesets = (ACE_OS::atoi (current_arg));

           arg_shifter.consume_arg ();
         }
       else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                 (ACE_TEXT("-ORBUseParallelConnects"))))
         {
           use_parallel_connects = ACE_OS::atoi (current_arg);
           arg_shifter.consume_arg ();
         }
       else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                 (ACE_TEXT("-ORBParallelConnectDelay"))))
         {
           this->orb_params ()->parallel_connect_delay
             (ACE_OS::atoi (current_arg));
           arg_shifter.consume_arg ();
         }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBSingleReadOptimization"))))
        {
          this->orb_params ()->single_read_optimization
            (ACE_OS::atoi (current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBDisableRTCollocation"))))
        {
          int disable_rt_collocation = ACE_OS::atoi (current_arg);
          if (disable_rt_collocation)
            this->orb_params ()->disable_rt_collocation_resolver (true);
          else
            this->orb_params ()->disable_rt_collocation_resolver (false);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBUseLocalMemoryPool"))))
        {
          this->use_local_memory_pool_ = (0 != ACE_OS::atoi (current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBMaxMessageSize"))))
        {
          this->orb_params_.max_message_size (ACE_OS::atoi (current_arg));

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBFTSendFullGroupTC"))))
        {
          this->ft_send_extended_sc_ = ACE_OS::atoi (current_arg);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBForwardInvocationOnObjectNotExist"))))
        {
          int const forward = ACE_OS::atoi (current_arg);
          if (forward)
            this->orb_params_.forward_invocation_on_object_not_exist (true);
          else
            this->orb_params_.forward_invocation_on_object_not_exist (false);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBForwardOnTransientLimit"))))
        {
          int const limit = ACE_OS::atoi (current_arg);
          this->orb_params_.forward_on_exception_limit (TAO::FOE_TRANSIENT, limit);
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                     (ACE_TEXT("-ORBForwardOnCommFailureLimit"))))
        {
          int const limit = ACE_OS::atoi (current_arg);
          this->orb_params_.forward_on_exception_limit (
                              TAO::FOE_COMM_FAILURE, limit);
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                     (ACE_TEXT("-ORBForwardOnObjectNotExistLimit"))))
        {
          int const limit = ACE_OS::atoi (current_arg);
          this->orb_params_.forward_on_exception_limit (
                              TAO::FOE_OBJECT_NOT_EXIST, limit);
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBForwardOnInvObjrefLimit"))))
        {
          int const limit = ACE_OS::atoi (current_arg);
          this->orb_params_.forward_on_exception_limit (
                              TAO::FOE_INV_OBJREF, limit);
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                     (ACE_TEXT("-ORBForwardOnReplyClosedLimit"))))
        {
          int const limit = ACE_OS::atoi (current_arg);
          this->orb_params_.invocation_retry_params ()
            .forward_on_reply_closed_limit_ = limit;
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBForwardDelay"))))
        {
          int const msecs = ACE_OS::atoi (current_arg);
          ACE_Time_Value delay(0, 1000*msecs);
          this->orb_params_.forward_on_exception_delay (delay);
          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                     (ACE_TEXT("-ORBForwardOnceOnObjectNotExist"))))
        {
          int const forward = ACE_OS::atoi (current_arg);
          if (forward)
            this->orb_params_.forward_once_exception (TAO::FOE_OBJECT_NOT_EXIST);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBForwardOnceOnCommFailure"))))
        {
          int const forward = ACE_OS::atoi (current_arg);
          if (forward)
            this->orb_params_.forward_once_exception (TAO::FOE_COMM_FAILURE);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBForwardOnceOnTransient"))))
        {
          int const forward = ACE_OS::atoi (current_arg);
          if (forward)
            this->orb_params_.forward_once_exception (TAO::FOE_TRANSIENT);

          arg_shifter.consume_arg ();
        }
      else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                (ACE_TEXT("-ORBForwardOnceOnInvObjref"))))
        {
          int forward = ACE_OS::atoi (current_arg);
          if (forward)
            this->orb_params_.forward_once_exception (TAO::FOE_INV_OBJREF);

          arg_shifter.consume_arg ();
        }
     else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                    (ACE_TEXT("-ORBAllowZIOPNoServerPolicies"))))
        {
          // This option takes a boolean 0 (off/dissallow) or 1 (on/allow)
          this->orb_params_.allow_ziop_no_server_policies (!!ACE_OS::atoi (current_arg));
          arg_shifter.consume_arg ();
        }
     else if (nullptr != (current_arg = arg_shifter.get_the_parameter
                    (ACE_TEXT("-ORBDynamicThreadPoolName"))))
        {
          this->orb_params_.dynamic_thread_pool_config_name (ACE_TEXT_ALWAYS_CHAR
                                                             (current_arg));
          arg_shifter.consume_arg ();
        }

      ////////////////////////////////////////////////////////////////
      // catch any unknown -ORB args                                //
      ////////////////////////////////////////////////////////////////
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ORB")) != -1)
        {
          if (TAO_debug_level > 0)
            {
              current_arg = arg_shifter.get_current ();
              TAOLIB_ERROR ((LM_ERROR,
                          ACE_TEXT ("ERROR: Unknown \"-ORB\" option ")
                          ACE_TEXT ("<%s>.\n"),
                          ((current_arg == nullptr) ? ACE_TEXT("<NULL>")
                                              : current_arg)));
            }

          throw ::CORBA::BAD_PARAM (
            CORBA::SystemException::_tao_minor_code (
              TAO_ORB_CORE_INIT_LOCATION_CODE,
              EINVAL),
            CORBA::COMPLETED_NO);
        }

      ////////////////////////////////////////////////////////////////
      // ok, we can't interpret this argument, move to next argument//
      ////////////////////////////////////////////////////////////////
      else
        {
          // Any arguments that don't match are ignored so that the
          // caller can still use them.
          arg_shifter.ignore_arg ();
        }
    }

  const char *env_endpoint =
    ACE_OS::getenv ("TAO_ORBENDPOINT");

  if (env_endpoint != nullptr)
    {
      int result =
        this->orb_params ()->add_endpoints (TAO_DEFAULT_LANE, env_endpoint);

      if (result != 0)
        {
          if (TAO_debug_level > 0)
            {
              TAOLIB_ERROR ((LM_ERROR,
                          ACE_TEXT ("ERROR: Environment variable ")
                          ACE_TEXT ("TAO_ORBENDPOINT set to invalid value ")
                          ACE_TEXT ("<%C>.\n"),
                          env_endpoint));
            }

          throw ::CORBA::BAD_PARAM (
            CORBA::SystemException::_tao_minor_code (
              TAO_ORB_CORE_INIT_LOCATION_CODE,
              EINVAL),
            CORBA::COMPLETED_NO);
        }
    }

#if defined (SIGPIPE) && !defined (ACE_LACKS_UNIX_SIGNALS)
  // There's really no way to deal with this in a portable manner, so
  // we just have to suck it up and get preprocessor conditional and
  // ugly.
  //
  // Impractical to have each call to the ORB protect against the
  // implementation artifact of potential writes to dead connections,
  // as it'd be way expensive.  Do it here; who cares about SIGPIPE in
  // these kinds of applications, anyway?
  (void) ACE_OS::signal (SIGPIPE, (ACE_SignalHandler) SIG_IGN);
#endif /* SIGPIPE */

  // Calling the open method here so that the svc.conf file is
  // opened and TAO_default_resource_factory::init () is called by the
  // time this method is called.
  this->parser_registry_.open (this);

  // Initialize the pointers to resources in the ORB Core instance,
  // e.g., reactor, connector, etc.  Must do this after we open
  // services because we'll load the factory from there.
  TAO_Resource_Factory *trf = this->resource_factory ();

  if (trf == nullptr)
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - %p\n"),
                  ACE_TEXT ("ORB Core unable to find a ")
                  ACE_TEXT ("Resource Factory instance")));
      throw ::CORBA::INTERNAL (
        CORBA::SystemException::_tao_minor_code (
          TAO_ORB_CORE_INIT_LOCATION_CODE,
          0),
        CORBA::COMPLETED_NO);
    }

  // Set whether or not to use the local memory pool for the cdr allocators.

  trf->use_local_memory_pool (this->use_local_memory_pool_);

  // @@ ????
  // Make sure the reactor is initialized...
  ACE_Reactor *reactor = this->reactor ();
  if (reactor == nullptr)
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - %p\n"),
                  ACE_TEXT ("ORB Core unable to initialize reactor")));
      throw ::CORBA::INITIALIZE (
        CORBA::SystemException::_tao_minor_code (
          TAO_ORB_CORE_INIT_LOCATION_CODE,
          0),
        CORBA::COMPLETED_NO);
    }

  TAO_Server_Strategy_Factory *ssf = this->server_factory ();

  if (ssf == nullptr)
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - %p\n"),
                  ACE_TEXT ("ORB Core unable to find a ")
                  ACE_TEXT ("Server Strategy Factory instance")));
      throw ::CORBA::INTERNAL (
        CORBA::SystemException::_tao_minor_code (
          TAO_ORB_CORE_INIT_LOCATION_CODE,
          0),
        CORBA::COMPLETED_NO);
    }

  ssf->open (this);

  // Obtain the timeout value for the thread-per-connection model
  this->thread_per_connection_use_timeout_ =
    ssf->thread_per_connection_timeout (this->thread_per_connection_timeout_);

  if (thread_per_connection_use_timeout_ == -1)
    {
      if (ACE_OS::strcasecmp (TAO_DEFAULT_THREAD_PER_CONNECTION_TIMEOUT,
                              "INFINITE") == 0)
        {
          this->thread_per_connection_use_timeout_ = 0;
        }
      else
        {
          this->thread_per_connection_use_timeout_ = 1;
          int const milliseconds =
            ACE_OS::atoi (TAO_DEFAULT_THREAD_PER_CONNECTION_TIMEOUT);
          // Use a temporary to obtain automatic normalization.
          this->thread_per_connection_timeout_ =
            ACE_Time_Value (0, 1000 * milliseconds);
        }
    }
  if (this->thread_per_connection_use_timeout_ == 0)
    {
      // Do not wait for the server threads because they may block
      // forever.
      this->tm_.wait_on_exit (0);
    }

  // Initialize the "ORB" pseudo-object now.
  this->orb_ = CORBA::ORB::_tao_make_ORB (this);

  // This should probably move into the ORB Core someday rather then
  // being done at this level.
  this->orb_->_use_omg_ior_format (use_ior);

  // Set all kinds of orb parameters whose setting needed to be
  // deferred until after the service config entries had been
  // determined.

  this->orb_params ()->service_port (TAO::MCAST_NAMESERVICE, ns_port);

  if (ns_port != 0)
    {
      static char const mcast_fmt[] = "mcast://:%d::";
      static size_t const PORT_BUF_SIZE = 256;

      char def_init_ref[PORT_BUF_SIZE] = { 0 };

      ACE_OS::snprintf (def_init_ref,
                        PORT_BUF_SIZE,
                        mcast_fmt,
                        ns_port);

      this->orb_params ()->default_init_ref (def_init_ref);
    }

  this->orb_params ()->service_port (TAO::MCAST_TRADINGSERVICE, ts_port);
  this->orb_params ()->service_port (TAO::MCAST_IMPLREPOSERVICE, ir_port);

  this->orb_params ()->use_dotted_decimal_addresses (dotted_decimal_addresses);
  // When caching incoming transports don't use the host name if
  // -ORBDottedDecimalAddresses or -ORBNoServerSideNameLookups is true.
  this->orb_params ()->cache_incoming_by_dotted_decimal_address
                                            (no_server_side_name_lookups
                                             || dotted_decimal_addresses);

  this->orb_params ()->use_parallel_connects (use_parallel_connects != 0);

  this->orb_params ()->linger (linger);
  this->orb_params ()->accept_error_delay (accept_error_delay);
  this->orb_params ()->nodelay (nodelay);
  this->orb_params ()->sock_keepalive (so_keepalive);
  this->orb_params ()->sock_dontroute (so_dontroute);
  this->orb_params ()->ip_hoplimit (ip_hoplimit);
  this->orb_params ()->ip_multicastloop (ip_multicastloop);
  if (rcv_sock_size >= 0)
    this->orb_params ()->sock_rcvbuf_size (rcv_sock_size);
  if (snd_sock_size >= 0)
    this->orb_params ()->sock_sndbuf_size (snd_sock_size);
  if (cdr_tradeoff >= 0)
    this->orb_params ()->cdr_memcpy_tradeoff (cdr_tradeoff);

  this->orb_params ()->std_profile_components (std_profile_components);

  this->orb_params ()->negotiate_codesets (negotiate_codesets);

  if (this->codeset_manager())
    this->codeset_manager_->open(*this);
  else
    if  (TAO_debug_level > 0)
        TAOLIB_DEBUG ((LM_DEBUG,
                    ACE_TEXT("TAO (%P|%t) - ORB_Core: ")
                    ACE_TEXT("Codeset Manager not available\n")));

  // Set up the pluggable protocol infrastructure.  First get a
  // pointer to the protocol factories set, then obtain pointers to
  // all factories loaded by the service configurator.
  // Load all protocol factories!
  if (trf->init_protocol_factories () == -1)
    throw ::CORBA::INITIALIZE (
      CORBA::SystemException::_tao_minor_code (
        TAO_ORB_CORE_INIT_LOCATION_CODE,
        0),
      CORBA::COMPLETED_NO);

  // init the ORB core's pointer
  this->protocol_factories_ = trf->get_protocol_factories ();

  // Initialize the flushing strategy
  this->flushing_strategy_ = trf->create_flushing_strategy ();

  // Initialize the default sync scope value
  this->default_sync_scope_ = this->client_factory()->sync_scope ();

  // Look in the service repository for an instance of the Protocol Hooks.
  const char *protocols_hooks_name = this->orb_params ()->protocols_hooks_name ();

  this->protocols_hooks_ =
    ACE_Dynamic_Service<TAO_Protocols_Hooks>::instance
    (this->configuration (),
     ACE_TEXT_CHAR_TO_TCHAR (protocols_hooks_name));

  if (this->protocols_hooks_ != nullptr)
    {
      // Initialize the protocols hooks instance.
      this->protocols_hooks_->init_hooks (this);
    }

  // If available, allow the Adapter Factory to setup.
  ACE_Service_Object *adapter_factory =
    ACE_Dynamic_Service<ACE_Service_Object>::instance (
      this->configuration (),
      this->orb_params ()->poa_factory_name ());

  if (adapter_factory != nullptr)
    {
      adapter_factory->init (0, nullptr);
    }

  // Look in the service repository for an instance of the
  // Network Priority Protocol Hooks.
  const ACE_CString &network_priority_protocols_hooks_name =
     TAO_ORB_Core_Static_Resources::instance ()->
       network_priority_protocols_hooks_name_;

  this->network_priority_protocols_hooks_ =
    ACE_Dynamic_Service<TAO_Network_Priority_Protocols_Hooks>::instance
    (this->configuration (),
     ACE_TEXT_CHAR_TO_TCHAR (network_priority_protocols_hooks_name.c_str()));

  if (this->network_priority_protocols_hooks_ != nullptr)
    {
      // Initialize the protocols hooks instance.
      this->network_priority_protocols_hooks_->init_hooks (this);
    }

  // As a last step perform initializations of the service callbacks
  this->services_callbacks_init ();

  // The ORB has been initialized, meaning that the ORB is no longer
  // in the shutdown state.
  this->has_shutdown_ = false;

  return 0;
}


int
TAO_ORB_Core::fini ()
{
  try
    {
      // Shutdown the ORB and block until the shutdown is complete.
      this->shutdown (1);
    }
  catch (const ::CORBA::Exception& ex)
    {
      ACE_CString message =
        "Exception caught in trying to shutdown ";
      message += this->orbid_;
      message += "\n";

      ex._tao_print_exception (message.c_str ());
    }

  // Wait for any server threads, ignoring any failures.
  (void) this->thr_mgr ()->wait ();

  ::CORBA::release (this->typecode_factory_);

  ::CORBA::release (this->codec_factory_);

  ::CORBA::release (this->compression_manager_);

  ::CORBA::release (this->dynany_factory_);

  ::CORBA::release (this->ior_manip_factory_);

  ::CORBA::release (this->ior_table_);

  ::CORBA::release (this->async_ior_table_);

  ::CORBA::release (this->monitor_);

  if (TAO_debug_level > 2)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - Destroying ORB <%C>\n"),
                  this->orbid_));
    }

  // Finalize lane resources.
  //
  // @@ Do not call this->thread_lane_resources_manager().finalize().
  // this->thread_lane_manager_resources() can seg fault if the
  // factory method it invokes returns a zero pointer, which can
  // easily occur if the ORB is partially initialized due to a Service
  // Configurator initialization failure.  Instead check if the
  // cached pointer is non-zero and then finalize.
  //
  // @todo Fix potential seg fault in
  //       TAO_ORB_Core::thread_lane_resources_manager().
  if (this->thread_lane_resources_manager_ != nullptr)
    this->thread_lane_resources_manager_->finalize ();

  // Destroy the object_key table
  this->object_key_table_.destroy ();

  delete this;

  return 0;
}

void
TAO_ORB_Core::set_resource_factory (const char *resource_factory_name)
{
  TAO_ORB_Core_Static_Resources::instance ()->resource_factory_name_ =
    resource_factory_name;
}

void
TAO_ORB_Core::set_gui_resource_factory (TAO::GUIResource_Factory *gui_resource_factory)
{
  if (TAO_TSS_Resources::instance ()->gui_resource_factory_ != nullptr)
    {
      if (TAO_debug_level > 2)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                      "TAO (%P|%t) - Deleting old gui_resource_factory.\n"));
        }
      delete TAO_TSS_Resources::instance ()->gui_resource_factory_;
    }

  TAO_TSS_Resources::instance ()->gui_resource_factory_ = gui_resource_factory;
}

void
TAO_ORB_Core::dynamic_adapter_name (const char *name)
{
  TAO_ORB_Core_Static_Resources::instance ()->dynamic_adapter_name_ = name;
}

const char *
TAO_ORB_Core::dynamic_adapter_name ()
{
  return TAO_ORB_Core_Static_Resources::instance ()->dynamic_adapter_name_.c_str();
}

void
TAO_ORB_Core::ifr_client_adapter_name (const char *name)
{
  TAO_ORB_Core_Static_Resources::instance ()->ifr_client_adapter_name_ = name;
}

const char *
TAO_ORB_Core::ifr_client_adapter_name ()
{
  return TAO_ORB_Core_Static_Resources::instance ()->ifr_client_adapter_name_.c_str();
}

void
TAO_ORB_Core::typecodefactory_adapter_name (const char *name)
{
  TAO_ORB_Core_Static_Resources::instance ()->typecodefactory_adapter_name_ = name;
}

const char *
TAO_ORB_Core::typecodefactory_adapter_name ()
{
  return TAO_ORB_Core_Static_Resources::instance ()->typecodefactory_adapter_name_.c_str();
}

void
TAO_ORB_Core::iorinterceptor_adapter_factory_name (const char *name)
{
  TAO_ORB_Core_Static_Resources::instance ()->iorinterceptor_adapter_factory_name_ = name;
}

const char *
TAO_ORB_Core::iorinterceptor_adapter_factory_name ()
{
  return TAO_ORB_Core_Static_Resources::instance ()->iorinterceptor_adapter_factory_name_.c_str();
}

void
TAO_ORB_Core::valuetype_adapter_factory_name (const char *name)
{
  TAO_ORB_Core_Static_Resources::instance ()->valuetype_adapter_factory_name_ = name;
}

const char *
TAO_ORB_Core::valuetype_adapter_factory_name ()
{
  return TAO_ORB_Core_Static_Resources::instance ()->valuetype_adapter_factory_name_.c_str();
}

TAO_Resource_Factory *
TAO_ORB_Core::resource_factory ()
{
  // Check if there is a cached reference.
  if (this->resource_factory_ != nullptr)
    {
      return this->resource_factory_;
    }

  // Look in the service repository for an instance.
  ACE_CString &resource_factory_name =
    TAO_ORB_Core_Static_Resources::instance ()->resource_factory_name_;

  this->resource_factory_ =
    ACE_Dynamic_Service<TAO_Resource_Factory>::instance
      (this->configuration (),
       ACE_TEXT_CHAR_TO_TCHAR (resource_factory_name.c_str()));

  return this->resource_factory_;
}

TAO::GUIResource_Factory *
TAO_ORB_Core::gui_resource_factory ()
{
  return TAO_TSS_Resources::instance ()->gui_resource_factory_;
}


TAO_Thread_Lane_Resources_Manager &
TAO_ORB_Core::thread_lane_resources_manager ()
{
  // Check if there is a cached reference.
  if (this->thread_lane_resources_manager_ != nullptr)
    return *this->thread_lane_resources_manager_;

  // If not, lookup the corresponding factory and ask it to make one.
  const char *thread_lane_resources_manager_factory_name =
    this->orb_params ()->thread_lane_resources_manager_factory_name ();

  TAO_Thread_Lane_Resources_Manager_Factory *factory =
    ACE_Dynamic_Service<TAO_Thread_Lane_Resources_Manager_Factory>::instance
      (this->configuration (),
       ACE_TEXT_CHAR_TO_TCHAR (thread_lane_resources_manager_factory_name));

  this->thread_lane_resources_manager_ =
    factory->create_thread_lane_resources_manager (*this);

  return *this->thread_lane_resources_manager_;
}

TAO_Collocation_Resolver &
TAO_ORB_Core::collocation_resolver ()
{
  // Check if there is a cached reference.
  if (this->collocation_resolver_ != nullptr)
    return *this->collocation_resolver_;

  // If not, lookup it up.
  this->collocation_resolver_ =
    ACE_Dynamic_Service<TAO_Collocation_Resolver>::instance
      (this->configuration (),
       ACE_TEXT_CHAR_TO_TCHAR (this->orb_params ()->collocation_resolver_name ()));

  return *this->collocation_resolver_;
}

TAO::PolicyFactory_Registry_Adapter *
TAO_ORB_Core::policy_factory_registry_i ()
{
  TAO_PolicyFactory_Registry_Factory *loader =
    ACE_Dynamic_Service<TAO_PolicyFactory_Registry_Factory>::instance
      (this->configuration (),
       ACE_TEXT ("PolicyFactory_Loader"));

  if (loader == nullptr)
    {
      this->configuration ()->process_directive (
        ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("PolicyFactory_Loader",
                                      "TAO_PI",
                                      TAO_VERSION,
                                      "_make_TAO_PolicyFactory_Loader",
                                      ""));
      loader =
        ACE_Dynamic_Service<TAO_PolicyFactory_Registry_Factory>::instance
          (this->configuration (),
           ACE_TEXT ("PolicyFactory_Loader"));
    }

  if (loader != nullptr)
    {
      this->policy_factory_registry_ =
        loader->create ();
    }

  return this->policy_factory_registry_;
}

TAO_ZIOP_Adapter *
TAO_ORB_Core::ziop_adapter_i ()
{
  // Check if there is a cached reference.
  if (this->ziop_adapter_ != nullptr)
    return this->ziop_adapter_;

  this->ziop_adapter_ =
    ACE_Dynamic_Service<TAO_ZIOP_Adapter>::instance
      (this->configuration (),
       ACE_TEXT ("ZIOP_Loader"));

  return this->ziop_adapter_;
}

TAO::ORBInitializer_Registry_Adapter *
TAO_ORB_Core::orbinitializer_registry_i ()
{
  // @todo The ORBInitializer_Registry is supposed to be a singleton.

  // If not, lookup it up.
  this->orbinitializer_registry_ =
    ACE_Dynamic_Service<TAO::ORBInitializer_Registry_Adapter>::instance
      (this->configuration (),
       ACE_TEXT ("ORBInitializer_Registry"));

#if !defined (TAO_AS_STATIC_LIBS) && !(defined (ACE_VXWORKS) && !defined (__RTP__))
      // In case we build shared, try to load the PI Client library, in a
      // static build we just can't do this, so don't try it, lower layers
      // output an error then.
  if (this->orbinitializer_registry_ == nullptr)
    {
      this->configuration ()->process_directive (
        ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE ("ORBInitializer_Registry",
                                       "TAO_PI",
                                       TAO_VERSION,
                                       "_make_ORBInitializer_Registry",
                                       ""));
      this->orbinitializer_registry_ =
        ACE_Dynamic_Service<TAO::ORBInitializer_Registry_Adapter>::instance
          (this->configuration (),
           ACE_TEXT ("ORBInitializer_Registry"));
    }
#endif /* !TAO_AS_STATIC_LIBS && !(ACE_VXWORKS && !__RTP__) */

  return this->orbinitializer_registry_;
}

TAO_Stub_Factory *
TAO_ORB_Core::stub_factory ()
{
  // Check if there is a cached reference.
  if (this->stub_factory_ != nullptr)
    return this->stub_factory_;

  // If not, look in the service repository for an instance.
  const char *stub_factory_name =
    this->orb_params ()->stub_factory_name ();

  this->stub_factory_ =
    ACE_Dynamic_Service<TAO_Stub_Factory>::instance
      (this->configuration (),
       ACE_TEXT_CHAR_TO_TCHAR (stub_factory_name));

  return this->stub_factory_;
}

TAO_Endpoint_Selector_Factory *
TAO_ORB_Core::endpoint_selector_factory ()
{
  // Check if there is a cached reference.
  if (this->endpoint_selector_factory_ != nullptr)
    return this->endpoint_selector_factory_;

  // If not, look in the service repository for an instance.
  const char* endpoint_selector_factory_name =
    this->orb_params ()->endpoint_selector_factory_name ();

  this->endpoint_selector_factory_ =
    ACE_Dynamic_Service<TAO_Endpoint_Selector_Factory>::instance
      (this->configuration (),
       ACE_TEXT_CHAR_TO_TCHAR (endpoint_selector_factory_name));

  return this->endpoint_selector_factory_;
}

void
TAO_ORB_Core::set_network_priority_protocols_hooks (
  const char *network_priority_protocols_hooks_name)
{
  // Is synchronization necessary?
  TAO_ORB_Core_Static_Resources::instance ()->
    network_priority_protocols_hooks_name_ =
      network_priority_protocols_hooks_name;
}

void
TAO_ORB_Core::services_callbacks_init ()
{
  // We (should) know what are the services that would need
  // callbacks. So, what we do is go through the Service Configurator
  // list for looking at the services that we want to load.
  this->ft_service_.init (this);

  // @@ Other service callbacks can be added here
}

TAO::Invocation_Status
TAO_ORB_Core::service_raise_comm_failure (
    IOP::ServiceContextList &clist,
    TAO_Profile *profile)
{
  if (this->ft_service_.service_callback ())
    {
      return this->ft_service_.service_callback ()->
                 raise_comm_failure (clist, profile);
    }

  throw ::CORBA::COMM_FAILURE (
    CORBA::SystemException::_tao_minor_code (
      TAO_INVOCATION_RECV_REQUEST_MINOR_CODE,
      errno),
    CORBA::COMPLETED_MAYBE);
}


TAO::Invocation_Status
TAO_ORB_Core::service_raise_transient_failure (
    IOP::ServiceContextList &clist,
    TAO_Profile *profile)
{
  if (this->ft_service_.service_callback ())
    {
      return
        this->ft_service_.service_callback ()->raise_transient_failure (clist,
                                 profile);
    }

  return TAO::TAO_INVOKE_FAILURE;
}

TAO_Client_Strategy_Factory *
TAO_ORB_Core::client_factory ()
{
  if (this->client_factory_ == nullptr)
    {
      // Look in the service repository for an instance.
      this->client_factory_ =
        ACE_Dynamic_Service<TAO_Client_Strategy_Factory>::instance
          (this->configuration (),
           ACE_TEXT ("Client_Strategy_Factory"));
    }

  return this->client_factory_;
}

TAO_Server_Strategy_Factory *
TAO_ORB_Core::server_factory ()
{
  if (this->server_factory_ == nullptr)
    {
      // Look in the service repository for an instance.
      this->server_factory_ =
        ACE_Dynamic_Service<TAO_Server_Strategy_Factory>::instance
          (this->configuration (),
           ACE_TEXT ("Server_Strategy_Factory"));
    }

  return this->server_factory_;
}

CORBA::Object_ptr
TAO_ORB_Core::root_poa ()
{
  // DCL ..
  if (CORBA::is_nil (this->root_poa_.in ()))
    {
      // Making sure the initialization process in the current thread uses
      // the correct service repository (ours), instead of the global one.
      ACE_Service_Config_Guard scg (this->configuration ());

      TAO_Adapter_Factory *factory =
        ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
          (this->configuration (),
          this->orb_params ()->poa_factory_name ());

      if (factory == nullptr)
        {
          this->configuration()->process_directive (
             this->orb_params ()->poa_factory_directive ());

          factory =
            ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
              (this->configuration (),
              this->orb_params ()->poa_factory_name ());
        }

      if (factory == nullptr)
        {
          return CORBA::Object::_nil ();
        }

      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                        monitor,
                        this->open_lock_,
                        nullptr);

      if (CORBA::is_nil (this->root_poa_.in ()))
        {
          std::unique_ptr<TAO_Adapter> poa_adapter (factory->create (this));
          poa_adapter->open ();

          // @@ Not exception safe
          this->root_poa_ = poa_adapter->root ();

          this->adapter_registry_.insert (poa_adapter.get ());

          poa_adapter.release ();
        }
    }

  return CORBA::Object::_duplicate (this->root_poa_.in ());
}

TAO_Adapter *
TAO_ORB_Core::poa_adapter ()
{
  if (this->poa_adapter_ == nullptr)
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, nullptr);
      if (this->poa_adapter_ == nullptr)
        {
          this->poa_adapter_ =
            this->adapter_registry_.find_adapter ("RootPOA");
        }
    }
  return this->poa_adapter_;
}

TAO_Stub *
TAO_ORB_Core::create_stub (const char *repository_id,
                           const TAO_MProfile &profiles)
{
  TAO_Stub *retval =
    this->stub_factory ()->create_stub (repository_id, profiles, this);
  return retval;
}

void
TAO_ORB_Core::request_dispatcher (TAO_Request_Dispatcher *request_dispatcher)
{
  // Assume ownership of the request dispatcher.
  TAO_Request_Dispatcher *tmp = this->request_dispatcher_;
  this->request_dispatcher_ = request_dispatcher;
  delete tmp;
}

TAO_Stub *
TAO_ORB_Core::create_stub_object (TAO_MProfile &mprofile,
                                  const char *type_id,
                                  CORBA::PolicyList *policy_list)
{
  // Add the Polices contained in "policy_list" to each profile so
  // that those policies will be exposed to the client in the IOR.  In
  // particular each CORBA::Policy has to be converted in to
  // Messaging::PolicyValue, and then all the Messaging::PolicyValue
  // should be embedded inside a Messaging::PolicyValueSeq which
  // became in turns the "body" of the IOP::TaggedComponent. This
  // conversion is a responsability of the CORBA::Profile class.  (See
  // orbos\98-05-05.pdf Section 5.4)
  if (policy_list->length () != 0)
    {
      TAO_Profile * profile = nullptr;

      CORBA::ULong const count = mprofile.profile_count ();
      for (CORBA::ULong i = 0; i < count; ++i)
        {
          // Get the ith profile
          profile = mprofile.get_profile (i);
          profile->policies (policy_list);
        }
    }

  /// Initialize a TAO_Stub object with the mprofile thats passed.
  TAO_Stub *stub = this->create_stub (type_id, mprofile);

  stub->base_profiles ().policy_list (policy_list);

  return stub;
}

void
TAO_ORB_Core::load_policy_validators (TAO_Policy_Validator &validator)
{
  if (this->bidir_adapter_ == nullptr)
    {
      this->bidir_adapter_ =
        ACE_Dynamic_Service<TAO_BiDir_Adapter>::instance
          (this->configuration (), ACE_TEXT ("BiDirGIOP_Loader"));
    }

  // Call the BiDir library if it has been loaded
  if (this->bidir_adapter_)
    {
      this->bidir_adapter_->load_policy_validators (validator);
    }

  // Call the ZIOP library if it has been loaded
  if (this->ziop_adapter_)
    {
      this->ziop_adapter_->load_policy_validators (validator);
    }
}

CORBA::Object_ptr
TAO_ORB_Core::create_object (TAO_Stub *stub)
{
  // @@ What about forwarding.  With this approach we are never forwarded
  //    when we use collocation!
  const TAO_MProfile &mprofile = stub->base_profiles ();

  // @@ We should thow CORBA::NO_MEMORY in platforms with exceptions,
  // but we are stuck in platforms without exceptions!
  TAO_ORB_Core_Auto_Ptr collocated_orb_core;
  CORBA::Object_ptr x = nullptr;

  {
    // Lock the ORB_Table against concurrent modification while we
    // iterate through the ORBs.
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                      guard,
                      TAO::ORB_Table::instance()->lock (),
                      CORBA::Object::_nil ());

    TAO::ORB_Table * const table = TAO::ORB_Table::instance ();
    TAO::ORB_Table::iterator const end = table->end ();
    for (TAO::ORB_Table::iterator i = table->begin (); i != end; ++i)
      {
        ::TAO_ORB_Core * const other_core = (*i).second.core ();

        if (this->is_collocation_enabled (other_core, mprofile))
          {
            other_core->_incr_refcnt();
             TAO_ORB_Core_Auto_Ptr tmp_auto_ptr (other_core);
             collocated_orb_core = tmp_auto_ptr;
            break;
          }
      }
  }

  if (collocated_orb_core.get ())
    {
      x = collocated_orb_core.get ()->adapter_registry ().create_collocated_object (stub, mprofile);
    }


  if (!x)
    {
      // The constructor sets the proxy broker as the
      // Remote one.
      ACE_NEW_RETURN (x,
                      CORBA::Object (stub, 0),
                      nullptr);
    }

  return x;
}

CORBA::Long
TAO_ORB_Core::initialize_object (TAO_Stub *stub, CORBA::Object_ptr)
{
  // @@ What about forwarding.  With this approach we are never forwarded
  //    when we use collocation!
  const TAO_MProfile &mprofile =
    stub->base_profiles ();

  return initialize_object_i (stub, mprofile);
}

CORBA::Long
TAO_ORB_Core::reinitialize_object (TAO_Stub *stub)
{
  return initialize_object_i (stub, stub->forward_profiles ()
                                    ? *(stub->forward_profiles ())
                                    : stub->base_profiles ());
}

CORBA::Long
TAO_ORB_Core::initialize_object_i (TAO_Stub *stub, const TAO_MProfile &mprofile)

{
  CORBA::Long retval = 0;
  TAO_ORB_Core_Auto_Ptr collocated_orb_core;

  {
    // Lock the ORB_Table against concurrent modification while we
    // iterate through the ORBs.
    ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                              guard,
                              TAO::ORB_Table::instance()->lock (),
                              0));

    TAO::ORB_Table * const table = TAO::ORB_Table::instance ();
    TAO::ORB_Table::iterator const end = table->end ();
    for (TAO::ORB_Table::iterator i = table->begin (); i != end; ++i)
      {
        TAO_ORB_Core * const other_core = (*i).second.core ();

        if (this->is_collocation_enabled (other_core,
                                          mprofile))
          {
            other_core->_incr_refcnt ();
            TAO_ORB_Core_Auto_Ptr tmp_auto_ptr (other_core);
            collocated_orb_core = tmp_auto_ptr;
            break;
          }
      }
  }

  if (collocated_orb_core.get ())
    {
      retval = collocated_orb_core.get ()->adapter_registry ().initialize_collocated_object (stub);
    }
  else
    {
      stub->is_collocated (false);
    }

  return retval;
}

CORBA::Boolean
TAO_ORB_Core::is_collocation_enabled (TAO_ORB_Core *orb_core,
                                      const TAO_MProfile &mp)
{
  TAO_MProfile mp_temp;

  TAO_Profile* profile = nullptr;
  if (this->service_profile_selection(mp, profile) && profile)
  {
    if (mp_temp.add_profile(profile) == -1)
      {
        return false;
      }
  }

  if (!orb_core->optimize_collocation_objects ())
    return false;

  if (!orb_core->use_global_collocation () && orb_core != this)
    return false;

  if (!orb_core->is_collocated (profile ? mp_temp : mp))
    return false;

  return true;
}

int
TAO_ORB_Core::is_collocated (const TAO_MProfile& mprofile)
{
  // @@ Lots of issues arise when dealing with collocation.  What about
  //    forwarding or what if this is a multi-profile IOR where the order is
  //    significant and only one of the profiles is collocated.  For example
  //    when using a multiple servers for fault tolerance.  For now, we just
  //    look through all profiles and if any are colocated then we assume
  //    the object is collocated.
  // @@ Note, if collocated we can not be forwarded!
  //    Also, acceptor_registry_->is_collocated (...) will check the
  //    address (ORB Host) but not the object_key.  This should be checked
  //    also.

  return this->thread_lane_resources_manager ().is_collocated (mprofile);
}

// ****************************************************************

TAO_Leader_Follower &
TAO_ORB_Core::leader_follower ()
{
  return this->lane_resources ().leader_follower ();
}

TAO_LF_Strategy &
TAO_ORB_Core::lf_strategy ()
{
  return this->thread_lane_resources_manager ().lf_strategy ();
}

int
TAO_ORB_Core::run (ACE_Time_Value *tv, int perform_work)
{
  // ORB::run may be called from a thread, different from the one that
  // did the ORB_init, consequently we must establish the Service
  // Gestalt, this thread will consider "global"

  ACE_Service_Config_Guard use_orbs (this->configuration());

  if (TAO_debug_level > 10)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - ORB_Core::run, ")
                  ACE_TEXT ("start [%s]\n"),
                  perform_work?ACE_TEXT("perform_work"):ACE_TEXT("run")));
    }

  // Fetch the Reactor
  ACE_Reactor *r = this->reactor ();

  int result = 1;
  // 1 to detect that nothing went wrong

  // Loop handling client requests until the ORB is shutdown.

  // We could use the leader-follower lock to check for the state
  // if this variable or use the lock <create_event_loop_lock> in
  // the server strategy factory.
  // We don't need to do this because we use the Reactor
  // mechanisms to shutdown in a thread-safe way.

  while (this->has_shutdown () == false)
    {
      // Every time we perform an interaction we have to become the
      // leader again, because it is possible that a client has
      // acquired the leader role...
      TAO_Leader_Follower &leader_follower = this->leader_follower ();
      TAO_LF_Strategy &lf_strategy = this->lf_strategy ();

      TAO_LF_Event_Loop_Thread_Helper helper (leader_follower, lf_strategy, tv);

      result = helper.event_loop_return ();
      if (result != 0)
        {
          if (errno == ETIME)
            return 0;
          else
            return result;
        }

      // Set the owning thread of the Reactor to the one which we're
      // currently in.  This is necessary b/c it's possible that the
      // application is calling us from a thread other than that in which
      // the Reactor's CTOR (which sets the owner) was called.
      //
      // We need to do this on every iteration because the reactor may be
      // acquired by one of the client threads in the LF waiting
      // strategy
      r->owner (ACE_Thread::self ());

      if (TAO_debug_level > 10)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - ORB_Core::run, ")
                      ACE_TEXT ( "calling handle_events()\n")));
        }

      result = r->handle_events (tv);

      if (TAO_debug_level > 10)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - ORB_Core::run, ")
                      ACE_TEXT ("handle_events() returns %d\n"),
                      result));
        }

      if (result == -1)
        {
          // An error, terminate the loop
          break;
        }
      if (result == 0
          && tv != nullptr
          && *tv == ACE_Time_Value::zero)
        {
          // A timeout, terminate the loop...
          break;
        }

      if (perform_work)
        {
          // This is running on behalf of a perform_work() call,
          // The loop should run only once.
          break;
        }
      // Otherwise just continue..
    }

  // wait only in the parent thread.
  if (this->has_shutdown () == true &&
      (this->server_factory_->activate_server_connections () ||
       (this->tm_.task() == nullptr && this->tm_.count_threads() > 0) ) )
    {
      this->tm_.wait ();
    }

  if (TAO_debug_level > 10)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - ORB_Core::run, ")
                  ACE_TEXT ("ends with result = %d\n"),
                  result));
    }

  return result;
}


void
TAO_ORB_Core::shutdown (CORBA::Boolean wait_for_completion)
{
  {
    ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);

    if (this->has_shutdown () == true)
      return;

    // Check if we are on the right state, i.e. do not accept
    // shutdowns with the 'wait_for_completion' flag set in the middle
    // of an upcall (because those deadlock).
    this->adapter_registry_.check_close (wait_for_completion);

    // Set the 'has_shutdown' flag, so any further attempt to shutdown
    // becomes a noop.
    this->has_shutdown_ = true;

    // need to release the mutex, because some of the shutdown
    // operations invoke application code, that could (and in practice
    // does!) callback into ORB Core code.
  }

  this->adapter_registry_.close (wait_for_completion);

  // Shutdown reactor.
  this->thread_lane_resources_manager ().shutdown_reactor ();

  // Cleanup transports
  this->thread_lane_resources_manager ().close_all_transports ();

  // Grab the thread manager
  ACE_Thread_Manager *tm = this->thr_mgr ();

  // Try to cancel all the threads in the ORB.
  tm->cancel_all ();

  // If <wait_for_completion> is set, wait for all threads to exit.
  if (wait_for_completion == true)
    tm->wait ();

  // Explicitly destroy the valuetype adapter
  {
    ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);

    delete this->valuetype_adapter_;
    this->valuetype_adapter_ = nullptr;
  }

  // Explicitly destroy the object reference table since it
  // contains references to objects, which themselves may contain
  // reference to this ORB.
  this->object_ref_table_.destroy ();

  // Release implrepo_service_ if one existed. If everything went
  // fine then this must release reference from implrepo_service_
  // object to this orb core.
  ::CORBA::release (this->implrepo_service_);
  this->implrepo_service_ = CORBA::Object::_nil ();

#if (TAO_HAS_INTERCEPTORS == 1)
  CORBA::release (this->pi_current_);
  this->pi_current_ = CORBA::Object::_nil ();
#endif  /* TAO_HAS_INTERCEPTORS == 1 */
}

void
TAO_ORB_Core::destroy ()
{
  // All destroy() should do is (a) call shutdown() and (b) unbind()
  // from the ORB table.  Nothing else should really be added to this
  // method.  Everything else should go to the shutdown() method.
  // Remember when the ORB Core is finally removed from the ORB table,
  // the reference count goes to zero and fini() is called.  fini()
  // calls shutdown() and does not call destroy() since destroy() will
  // try to unbind from the ORB table again.  Additional code should
  // not be added to destroy() since there is no guarantee that
  // orb->destroy() will ever be called by the user.  Since TAO
  // guarantees that shutdown() will be called, all cleanup code
  // should go there.
  //

  // Shutdown the ORB and block until the shutdown is complete.
  this->shutdown (true);

  // Invoke Interceptor::destroy() on all registered interceptors.
  this->destroy_interceptors ();

  // Clean TSS resources. This cannot be done in shutdown() since the later
  // can be called during an upcall and once it's done it will remove
  // resources such as PICurrent that are required after the upcall. And this
  // cannot be postponed to TAO_ORB_Core's destructor as fini() needs access
  // to orb core and what is more important orb core can be destroyed too late
  // when some required libraries are already unloaded and we'll get
  // 'pure virtual method called' during cleanup.
  this->get_tss_resources ()->fini ();

  // Now remove it from the ORB table so that it's ORBid may be
  // reused.
  TAO::ORB_Table::instance ()->unbind (this->orbid_);
}

void
TAO_ORB_Core::check_shutdown ()
{
  if (this->has_shutdown ())
    {
      // As defined by the CORBA 2.3 specification, throw a
      // CORBA::BAD_INV_ORDER exception with minor code 4 if the ORB
      // has shutdown by the time an ORB function is called.

      throw ::CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 4, CORBA::COMPLETED_NO);
    }
}

void
TAO_ORB_Core::destroy_interceptors ()
{
  try
    {
      ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);

#if TAO_HAS_INTERCEPTORS == 1
      if (this->client_request_interceptor_adapter_ != nullptr)
        {
          this->client_request_interceptor_adapter_->destroy_interceptors ();

          delete this->client_request_interceptor_adapter_;
          this->client_request_interceptor_adapter_ = nullptr;
        }

      if (this->server_request_interceptor_adapter_ != nullptr)
        {
          this->server_request_interceptor_adapter_->destroy_interceptors ();

          delete this->server_request_interceptor_adapter_;
          this->server_request_interceptor_adapter_ = nullptr;
        }

#endif  /* TAO_HAS_INTERCEPTORS == 1 */

      if (this->ior_interceptor_adapter_ != nullptr)
        {
          this->ior_interceptor_adapter_->destroy_interceptors ();

          this->ior_interceptor_adapter_ = nullptr;
        }

    }
  catch (...)
    {
      // .. catch all the exceptions..
      if (TAO_debug_level > 3)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - Exception in TAO_ORB_Core")
                      ACE_TEXT ("::destroy_interceptors ()\n")));
        }
    }

  return;
}

TAO_Thread_Lane_Resources &
TAO_ORB_Core::lane_resources ()
{
  return this->thread_lane_resources_manager ().lane_resources ();
}

void
TAO_ORB_Core::resolve_typecodefactory_i ()
{
  TAO_Object_Loader *loader =
    ACE_Dynamic_Service<TAO_Object_Loader>::instance
      (this->configuration (),
       ACE_TEXT ("TypeCodeFactory_Loader"));

  if (loader == nullptr)
    {
      this->configuration ()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("TypeCodeFactory",
                                       "TAO_TypeCodeFactory",
                                       TAO_VERSION,
                                       "_make_TAO_TypeCodeFactory_Loader",
                                       ""));
      loader =
        ACE_Dynamic_Service<TAO_Object_Loader>::instance
        (this->configuration (),
         ACE_TEXT ("TypeCodeFactory_Loader"));

      if (loader == nullptr)
        {
          TAOLIB_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) Unable to instantiate ")
                      ACE_TEXT ("a TypeCodeFactory_Loader\n")));
          throw ::CORBA::ORB::InvalidName ();
        }
    }

  this->typecode_factory_ =
    loader->create_object (this->orb_, 0, nullptr);
}

void
TAO_ORB_Core::resolve_codecfactory_i ()
{
  TAO_Object_Loader *loader =
    ACE_Dynamic_Service<TAO_Object_Loader>::instance
      (this->configuration (),
       ACE_TEXT ("CodecFactory_Loader"));

  if (loader == nullptr)
    {
      this->configuration()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("CodecFactory",
                                       "TAO_CodecFactory",
                                       TAO_VERSION,
                                       "_make_TAO_CodecFactory_Loader",
                                       ""));
      loader =
        ACE_Dynamic_Service<TAO_Object_Loader>::instance
          (this->configuration (), ACE_TEXT ("CodecFactory_Loader"));
    }

  if (loader != nullptr)
    {
      this->codec_factory_ =
        loader->create_object (this->orb_, 0, nullptr);
    }
}

void
TAO_ORB_Core::resolve_compression_manager_i ()
{
  TAO_Object_Loader *loader =
    ACE_Dynamic_Service<TAO_Object_Loader>::instance
      (this->configuration (),
       ACE_TEXT ("Compression_Loader"));

  if (loader == nullptr)
    {
      this->configuration()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("Compression",
                                       "TAO_Compression",
                                       TAO_VERSION,
                                       "_make_TAO_Compression_Loader",
                                       ""));
      loader =
        ACE_Dynamic_Service<TAO_Object_Loader>::instance
          (this->configuration (), ACE_TEXT ("Compression_Loader"));
    }

  if (loader != nullptr)
    {
      this->compression_manager_ = loader->create_object (this->orb_, 0, nullptr);
    }
}

void
TAO_ORB_Core::resolve_poa_current_i ()
{
  TAO_Object_Loader *loader =
    ACE_Dynamic_Service<TAO_Object_Loader>::instance
      (this->configuration(),
       ACE_TEXT ("TAO_POA_Current_Factory"));

  if (loader == nullptr)
    {
      this->configuration()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("TAO_POA_Current_Factory",
                                       "TAO_PortableServer",
                                       TAO_VERSION,
                                       "_make_TAO_POA_Current_Factory",
                                       ""));
      loader =
        ACE_Dynamic_Service<TAO_Object_Loader>::instance
          (this->configuration(), ACE_TEXT ("TAO_POA_Current_Factory"));
    }

  if (loader != nullptr)
    {
      this->poa_current_ = loader->create_object (this->orb_, 0, nullptr);
    }
}


#if TAO_HAS_INTERCEPTORS == 1

void
TAO_ORB_Core::resolve_picurrent_i ()
{
  TAO_Object_Loader *loader =
    ACE_Dynamic_Service<TAO_Object_Loader>::instance
      (this->configuration (),
       ACE_TEXT ("PICurrent_Loader"));

  if (loader == nullptr)
    {
      this->configuration ()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("PICurrent_Loader",
                                       "TAO_PI",
                                       TAO_VERSION,
                                       "_make_TAO_PICurrent_Loader",
                                       ""));
      loader =
        ACE_Dynamic_Service<TAO_Object_Loader>::instance
          (this->configuration (), ACE_TEXT ("PICurrent_Loader"));
    }

  if (loader != nullptr)
    {
      CORBA::Object_ptr pi = loader->create_object (this->orb_, 0, nullptr);

      this->pi_current_ = pi;
    }
}

#endif /* TAO_HAS_INTERCEPTORS == 1 */


void
TAO_ORB_Core::resolve_dynanyfactory_i ()
{
  TAO_Object_Loader *loader =
    ACE_Dynamic_Service<TAO_Object_Loader>::instance
      (this->configuration (),
       ACE_TEXT ("DynamicAny_Loader"));

  if (loader == nullptr)
    {
      this->configuration ()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("DynamicAny_Loader",
                                       "TAO_DynamicAny",
                                       TAO_VERSION,
                                       "_make_TAO_DynamicAny_Loader",
                                       ""));
      loader =
        ACE_Dynamic_Service<TAO_Object_Loader>::instance
        (this->configuration (),
         ACE_TEXT ("DynamicAny_Loader"));
    }

  if (loader != nullptr)
    {
      this->dynany_factory_ = loader->create_object (this->orb_, 0, nullptr);
    }
}

void
TAO_ORB_Core::resolve_iormanipulation_i ()
{
  TAO_Object_Loader *loader =
    ACE_Dynamic_Service<TAO_Object_Loader>::instance
      (this->configuration (),
       ACE_TEXT ("IORManip_Loader"));

  if (loader == nullptr)
    {
      this->configuration()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("IORManip_Loader",
                                       "TAO_IORManip",
                                       TAO_VERSION,
                                       "_make_TAO_IORManip_Loader",
                                       ""));
      loader =
        ACE_Dynamic_Service<TAO_Object_Loader>::instance
          (this->configuration (), ACE_TEXT ("IORManip_Loader"));
    }

  if (loader != nullptr)
    {
      this->ior_manip_factory_ = loader->create_object (this->orb_, 0, nullptr);
    }
}

void
TAO_ORB_Core::resolve_ior_table_i ()
{
  TAO_Adapter_Factory *factory =
  ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
    (this->configuration (), ACE_TEXT("TAO_IORTable"));
  if (factory == nullptr)
    {
      this->configuration ()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("TAO_IORTable",
                                                 "TAO_IORTable",
                                                 TAO_VERSION,
                                                 "_make_TAO_Table_Adapter_Factory",
                                                 ""));
      factory =
        ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
        (this->configuration (), ACE_TEXT("TAO_IORTable"));
    }

  if (factory != nullptr)
    {
      std::unique_ptr <TAO_Adapter> iortable_adapter (factory->create (this));
      iortable_adapter->open ();

      CORBA::Object_var tmp_root = iortable_adapter->root ();

      this->adapter_registry_.insert (iortable_adapter.get ());

      // It is now (exception) safe to release ownership from the auto pointers
      this->ior_table_= tmp_root._retn ();
      iortable_adapter.release ();
    }
}

void
TAO_ORB_Core::resolve_async_ior_table_i ()
{
  TAO_Adapter_Factory *factory =
  ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
    (this->configuration (), ACE_TEXT("TAO_Async_IORTable"));
  if (factory == nullptr)
    {
      this->configuration ()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("TAO_Async_IORTable",
                                                 "TAO_Async_IORTable",
                                                 TAO_VERSION,
                                                 "_make_TAO_Async_Table_Adapter_Factory",
                                                 ""));
      factory =
        ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
        (this->configuration (), ACE_TEXT("TAO_Async_IORTable"));
    }

  if (factory != nullptr)
    {
      std::unique_ptr <TAO_Adapter> iortable_adapter (factory->create (this));
      iortable_adapter->open ();

      CORBA::Object_var tmp_root = iortable_adapter->root ();

      this->adapter_registry_.insert (iortable_adapter.get ());

      // It is now (exception) safe to release ownership from the auto pointers
      this->async_ior_table_= tmp_root._retn ();
      iortable_adapter.release ();
    }
}

void
TAO_ORB_Core::resolve_monitor_i ()
{
  TAO_Object_Loader *loader =
    ACE_Dynamic_Service<TAO_Object_Loader>::instance
      (this->configuration (),
       ACE_TEXT ("Monitor_Init"));

  if (loader == nullptr)
    {
      this->configuration ()->process_directive
        (ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("Monitor_Init",
                                       "TAO_Monitor",
                                       TAO_VERSION,
                                       "_make_TAO_Monitor_Init",
                                       ""));
      loader =
        ACE_Dynamic_Service<TAO_Object_Loader>::instance
        (this->configuration (),
         ACE_TEXT ("Monitor_Init"));
    }

  if (loader != nullptr)
    {
      this->monitor_ = loader->create_object (this->orb_, 0, nullptr);
    }
}

int
TAO_ORB_Core::set_endpoint_helper (const ACE_CString &lane,
                                   const ACE_CString &endpoints)
{
  if (this->orb_params ()->add_endpoints (lane, endpoints) != 0)
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%P|%t) ")
                  ACE_TEXT ("Invalid endpoint(s) specified: <%C>.\n"),
                  endpoints.c_str ()));
      throw ::CORBA::BAD_PARAM (
        CORBA::SystemException::_tao_minor_code (
          TAO_ORB_CORE_INIT_LOCATION_CODE,
          EINVAL),
        CORBA::COMPLETED_NO);
    }

  return 0;
}

CORBA::Object_ptr
TAO_ORB_Core::resolve_rir (const char *name)
{
  // Get the table of initial references specified through
  // -ORBInitRef.
  ACE_CString ior;
  ACE_CString object_id ((const char *) name);

  // Get the list of initial reference prefixes specified through
  // -ORBDefaultInitRef.
  CORBA::String_var default_init_ref =
    this->orb_params ()->default_init_ref ();

  // Check if a DefaultInitRef was specified.
  if (std::strlen (default_init_ref.in ()) != 0)
    {
      static const char corbaloc_prefix[] = "corbaloc:";
      static const char mcast_prefix[] = "mcast:";
      char object_key_delimiter = 0;

      ACE_CString list_of_profiles (default_init_ref.in ());

      // Check if the protocol is corbaloc: or mcast:.
      // If it is, set the object_key_delimiter.
      if ((ACE_OS::strncmp (default_init_ref.in (),
                            corbaloc_prefix,
                            sizeof corbaloc_prefix -1) == 0) ||
          (ACE_OS::strncmp (default_init_ref.in (),
                            mcast_prefix,
                            sizeof mcast_prefix -1) == 0))
        {
          object_key_delimiter = '/';
        }
      else
        {
          TAO_Connector_Registry *conn_reg = this->connector_registry ();

          // Obtain the appropriate object key delimiter for the
          // specified protocol.
          object_key_delimiter =
            conn_reg->object_key_delimiter (list_of_profiles.c_str ());
        }

      // Make sure that the default initial reference doesn't end
      // with the object key delimiter character.
      if (list_of_profiles[list_of_profiles.length() - 1] !=
          object_key_delimiter)
            list_of_profiles += ACE_CString (object_key_delimiter);

      list_of_profiles += object_id;

      return this->orb ()->string_to_object (list_of_profiles.c_str ());
    }

  return CORBA::Object::_nil ();
}

CORBA::ORB::ObjectIdList *
TAO_ORB_Core::list_initial_references ()
{
  // Unsupported initial services should NOT be included in the below list!
  static const char *initial_services[] = { TAO_LIST_OF_INITIAL_SERVICES };
  // Make sure the "terminating" zero is the last array element so
  // that there is a stop condition when iterating through the list.

  static const size_t initial_services_size =
    sizeof (initial_services) / sizeof (initial_services[0]);

  const size_t total_size =
    initial_services_size
    + this->init_ref_map_.size ()
    + this->object_ref_table_.current_size ();

  CORBA::ORB::ObjectIdList *tmp = nullptr;

  ACE_NEW_THROW_EX (tmp,
                    CORBA::ORB::ObjectIdList (
                      static_cast<CORBA::ULong> (total_size)),
                    CORBA::NO_MEMORY ());

  CORBA::ORB::ObjectIdList_var list (tmp);
  list->length (static_cast<CORBA::ULong> (total_size));

  CORBA::ULong index = 0;
  // Index for ObjectIdList members.

  // Iterate over the registered initial references.
  for (index = 0; index < initial_services_size; ++index)
    list[index] = initial_services[index];

  // Now iterate over the initial references created by the user and
  // add them to the sequence.

  // References registered via
  // ORBInitInfo::register_initial_reference().
  TAO_Object_Ref_Table::iterator const obj_ref_end =
    this->object_ref_table_.end ();

  for (TAO_Object_Ref_Table::iterator i = this->object_ref_table_.begin ();
       i != obj_ref_end;
       ++i, ++index)
    list[index] = CORBA::string_dup ((*i).first.in ());

  // References registered via INS.
  InitRefMap::iterator const end = this->init_ref_map_.end ();

  for (InitRefMap::iterator j = this-> init_ref_map_.begin ();
       j != end;
       ++j, ++index)
    list[index] = (*j).first.c_str ();

  return list._retn ();
}

// ****************************************************************
ACE_Allocator*
TAO_ORB_Core::input_cdr_dblock_allocator ()
{
  return this->lane_resources ().input_cdr_dblock_allocator ();
}

ACE_Allocator*
TAO_ORB_Core::input_cdr_buffer_allocator ()
{
  return this->lane_resources ().input_cdr_buffer_allocator ();
}

ACE_Allocator*
TAO_ORB_Core::input_cdr_msgblock_allocator ()
{
  return this->lane_resources ().input_cdr_msgblock_allocator ();
}

ACE_Allocator*
TAO_ORB_Core::output_cdr_dblock_allocator ()
{
  return this->lane_resources ().output_cdr_dblock_allocator ();
}

ACE_Allocator*
TAO_ORB_Core::output_cdr_buffer_allocator ()
{
  return this->lane_resources ().output_cdr_buffer_allocator ();
}


ACE_Allocator*
TAO_ORB_Core::output_cdr_msgblock_allocator ()
{
  return this->lane_resources ().output_cdr_msgblock_allocator ();
}


ACE_Allocator *
TAO_ORB_Core::transport_message_buffer_allocator ()
{
  return this->lane_resources ().transport_message_buffer_allocator ();
}


ACE_Data_Block*
TAO_ORB_Core::create_input_cdr_data_block (size_t size)
{
  ACE_Allocator *dblock_allocator = nullptr;
  ACE_Allocator *buffer_allocator = nullptr;

  dblock_allocator =
    this->input_cdr_dblock_allocator ();
  buffer_allocator =
    this->input_cdr_buffer_allocator ();

  ACE_Lock* lock_strategy = nullptr;
  if (this->resource_factory ()->use_locked_data_blocks ())
    {
      lock_strategy = &this->data_block_lock_;
    }

  return this->create_data_block_i (size,
                                    buffer_allocator,
                                    dblock_allocator,
                                    lock_strategy);
}

ACE_Data_Block *
TAO_ORB_Core::create_data_block_i (size_t size,
                                   ACE_Allocator *buffer_allocator,
                                   ACE_Allocator *dblock_allocator,
                                   ACE_Lock *lock_strategy)
{
  ACE_Data_Block *nb = nullptr;

  ACE_NEW_MALLOC_RETURN (
                         nb,
                         static_cast<ACE_Data_Block*> (
                           dblock_allocator->malloc (sizeof (ACE_Data_Block))),
                         ACE_Data_Block (size,
                                         ACE_Message_Block::MB_DATA,
                                         nullptr,
                                         buffer_allocator,
                                         lock_strategy,
                                         0,
                                         dblock_allocator),
                         nullptr);

  return nb;
}

TAO_Connector_Registry *
TAO_ORB_Core::connector_registry ()
{
  TAO_Connector_Registry *conn =
    this->lane_resources ().connector_registry ();

  return conn;
}

TAO_GIOP_Fragmentation_Strategy*
TAO_ORB_Core::fragmentation_strategy (TAO_Transport * transport)
{
  return
    this->resource_factory ()->create_fragmentation_strategy (
      transport,
      this->orb_params_.max_message_size ());
}

ACE_Reactor *
TAO_ORB_Core::reactor ()
{
  return this->leader_follower ().reactor ();
}

CORBA::Object_ptr
TAO_ORB_Core::implrepo_service ()
{
  if (!this->use_implrepo_)
    return CORBA::Object::_nil ();

  if (CORBA::is_nil (this->implrepo_service_))
    {
      try
        {
          CORBA::Object_var temp =
            this->orb_->resolve_initial_references ("ImplRepoService");

          ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, CORBA::Object::_nil ());

          // @@ Worry about assigning a different IOR? (brunsch)
          this->implrepo_service_ = temp._retn ();
        }
      catch (const ::CORBA::Exception&)
        {
          // Just make sure that we have a null pointer.  Ignore the exception
          // anyway.
          this->implrepo_service_ = CORBA::Object::_nil ();
        }
    }

  return CORBA::Object::_duplicate (this->implrepo_service_);
}

void
TAO_ORB_Core::default_sync_scope_hook (TAO_ORB_Core *oc,
                                       TAO_Stub *,
                                       bool &has_synchronization,
                                       Messaging::SyncScope &scope)
{
  has_synchronization = true;
  scope = (oc == nullptr) ? Messaging::SYNC_WITH_TRANSPORT : oc->default_sync_scope_;
}

void
TAO_ORB_Core::call_sync_scope_hook (TAO_Stub *stub,
                                    bool &has_synchronization,
                                    Messaging::SyncScope &scope)
{
  Sync_Scope_Hook sync_scope_hook = this->sync_scope_hook_;

  if (sync_scope_hook == nullptr)
    {
      has_synchronization = false;
      return;
    }

  (*sync_scope_hook) (this, stub, has_synchronization, scope);
}

#if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)

TAO::Transport_Queueing_Strategy *
TAO_ORB_Core::get_transport_queueing_strategy (TAO_Stub *,
                                               Messaging::SyncScope &scope)
{
  switch (scope)
  {
    case Messaging::SYNC_WITH_TRANSPORT:
    case Messaging::SYNC_WITH_SERVER:
    case Messaging::SYNC_WITH_TARGET:
    {
      return this->flush_transport_queueing_strategy_;
    }
    break;
    case Messaging::SYNC_NONE:
    {
      return this->eager_transport_queueing_strategy_;
    }
    break;
    case TAO::SYNC_DELAYED_BUFFERING:
    {
      return this->delayed_transport_queueing_strategy_;
    }
    break;
    default:
    {
      return nullptr;
    }
  }
}

#endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */

int
TAO_ORB_Core::add_tss_cleanup_func (ACE_CLEANUP_FUNC cleanup, size_t &slot_id)
{
  return this->tss_cleanup_funcs_.register_cleanup_function (cleanup, slot_id);
}

void
TAO_ORB_Core::call_timeout_hook (TAO_Stub *stub,
                                 bool &has_timeout,
                                 ACE_Time_Value &time_value)
{
  Timeout_Hook timeout_hook = this->timeout_hook_;

  if (timeout_hook == nullptr)
    {
      has_timeout = false;
      return;
    }
  (*timeout_hook) (this, stub, has_timeout, time_value);
}

void
TAO_ORB_Core::connection_timeout (TAO_Stub *stub,
                                  bool &has_timeout,
                                  ACE_Time_Value &time_value)
{
  Timeout_Hook connection_timeout_hook =
    TAO_ORB_Core_Static_Resources::instance ()->connection_timeout_hook_;

  if (connection_timeout_hook == nullptr)
    {
      has_timeout = false;
      return;
    }

  (*connection_timeout_hook) (this, stub, has_timeout, time_value);

  Timeout_Hook alt_connection_timeout_hook =
    TAO_ORB_Core_Static_Resources::instance ()->alt_connection_timeout_hook_;

  if (alt_connection_timeout_hook == nullptr)
    return;

  if (!has_timeout || time_value == ACE_Time_Value::zero )
    {
      (*alt_connection_timeout_hook) (this, stub, has_timeout,time_value);
      return;
    }

  // At this point, both the primary and alternate hooks are defined, and
  // the primary did indeed set a value
  ACE_Time_Value tv1;
  bool ht1;
  (*alt_connection_timeout_hook) (this, stub, ht1,tv1);
  if (ht1 && tv1 > ACE_Time_Value::zero && tv1 < time_value)
    time_value = tv1;
}

void
TAO_ORB_Core::connection_timeout_hook (Timeout_Hook hook)
{
  // Saving the hook pointer so that we can use it later when needed.
  // For now there are only two entry points that may supply a connection
  // timeout hook. But there might be future entry points, so this should
  // probably be addressed by a more sophisticated mechanism.

#define TOCSRi TAO_ORB_Core_Static_Resources::instance ()

  // A concern was raised that since this function is called by two
  // different initializers there may be a race condition that might
  // require a lock. We are not using a lock at this time because of
  // two callers, one happens only during service directive processing
  // and the other only during ORB Initialization time. The former
  // happens when the OC_Endpoint_Selector_Factory is loaded, the
  // latter is part of the messaging library. The messaging library
  // calls this function as part of pre_init processing, and this call
  // happens for every ORB instance. This was the case before these The
  // latter call occurs when the messaging library is loaded. The
  // redundant calls occurred then as well. Second, it isn't clear how
  // a lock in this static method would react in the face of windows
  // dlls, shared memory segments, etc. Therefore we are continuing to
  // keep this code lockless as it always was, assuming no
  // simultaneous overwrite will occur.
  if (TOCSRi->connection_timeout_hook_ == nullptr)
    {
      if (TAO_debug_level > 2)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT("TAO (%P|%t) - Setting primary connection ")
                      ACE_TEXT("timeout hook\n")));
        }
      TOCSRi->connection_timeout_hook_ = hook;
    }
  else if (TOCSRi->connection_timeout_hook_ != hook &&
           TOCSRi->alt_connection_timeout_hook_ == nullptr)
    {
      if (TAO_debug_level > 2)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT("TAO (%P|%t) - Setting alternate connection ")
                      ACE_TEXT("timeout hook\n")));
        }
      TOCSRi->alt_connection_timeout_hook_ = hook;
    }
  else
    if (TAO_debug_level > 2)
      {
        TAOLIB_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) - Not overwriting alternate ")
                    ACE_TEXT ("connection timeout hook. It is %@\n"),
                    TOCSRi->alt_connection_timeout_hook_));
      }

#undef TOCSRi
}

#if (TAO_HAS_CORBA_MESSAGING == 1)

CORBA::Policy_ptr
TAO_ORB_Core::get_policy (CORBA::PolicyType type)
{
  CORBA::Policy_var result;

  TAO_Policy_Manager *policy_manager = this->policy_manager ();
  if (policy_manager != nullptr)
    {
      result = policy_manager->get_policy (type);
    }

  if (CORBA::is_nil (result.in ()))
    {
      result = this->get_default_policies ()->get_policy (type);
    }

  return result._retn ();
}

CORBA::Policy_ptr
TAO_ORB_Core::get_policy_including_current (CORBA::PolicyType type)
{
  TAO_Policy_Current &policy_current = this->policy_current ();

  CORBA::Policy_var result = policy_current.get_policy (type);

  if (CORBA::is_nil (result.in ()))
    {
      result = this->get_policy (type);
    }

  return result._retn ();
}

CORBA::Policy_ptr
TAO_ORB_Core::get_cached_policy (TAO_Cached_Policy_Type type)
{
  CORBA::Policy_var result;

  TAO_Policy_Manager *policy_manager = this->policy_manager ();
  if (policy_manager != nullptr)
    {
      result = policy_manager->get_cached_policy (type);
    }

  if (CORBA::is_nil (result.in ()))
    {
      result = this->get_default_policies ()->get_cached_policy (type);
    }

  return result._retn ();
}

CORBA::Policy_ptr
TAO_ORB_Core::get_cached_policy_including_current (TAO_Cached_Policy_Type type)
{
  TAO_Policy_Current &policy_current = this->policy_current ();

  CORBA::Policy_var result = policy_current.get_cached_policy (type);

  if (CORBA::is_nil (result.in ()))
    {
      result = this->get_cached_policy (type);
    }

  return result._retn ();
}

#endif /* (TAO_HAS_CORBA_MESSAGING == 1) */

CORBA::Environment *
TAO_ORB_Core::default_environment () const
{
  return TAO_TSS_Resources::instance ()->default_environment_;
}

void
TAO_ORB_Core::default_environment (CORBA::Environment *env)
{
  TAO_TSS_Resources::instance ()->default_environment_ = env;
}

void
TAO_ORB_Core::add_interceptor (
   PortableInterceptor::IORInterceptor_ptr interceptor)
{
  if (this->ior_interceptor_adapter ())
    {
      this->ior_interceptor_adapter_->add_interceptor (interceptor);
    }
  else
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - %p\n"),
                  ACE_TEXT ("ERROR: ORB Core unable to find the ")
                  ACE_TEXT ("IORInterceptor Adapter Factory instance")));

      throw ::CORBA::INTERNAL ();
    }
}

TAO_IORInterceptor_Adapter *
TAO_ORB_Core::ior_interceptor_adapter ()
{
  if (this->ior_interceptor_adapter_ == nullptr)
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                        ace_mon,
                        this->lock_,
                        nullptr);

      if (this->ior_interceptor_adapter_ == nullptr)
        {
          try
            {
              TAO_IORInterceptor_Adapter_Factory * ior_ap_factory =
                ACE_Dynamic_Service<TAO_IORInterceptor_Adapter_Factory>::instance
                  (this->configuration (),
                   ACE_TEXT_CHAR_TO_TCHAR (TAO_ORB_Core::iorinterceptor_adapter_factory_name ()));

              if (ior_ap_factory)
                {
                  this->ior_interceptor_adapter_ = ior_ap_factory->create ();
                }
            }
          catch (const ::CORBA::Exception& ex)
            {
              ex._tao_print_exception (
                "Cannot initialize the ior_interceptor_adapter\n");
            }
        }
    }

  return this->ior_interceptor_adapter_;
}

#if TAO_HAS_INTERCEPTORS == 1

void
TAO_ORB_Core::add_interceptor (
   PortableInterceptor::ClientRequestInterceptor_ptr interceptor
   )
{
  if (this->clientrequestinterceptor_adapter_i ())
    {
      this->client_request_interceptor_adapter_->add_interceptor (interceptor);
    }
  else
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - %p\n"),
                  ACE_TEXT ("ERROR: ORB Core unable to find the ")
                  ACE_TEXT ("Client Request Interceptor Adapter Factory ")
                  ACE_TEXT ("instance")));

      throw ::CORBA::INTERNAL ();
    }
}

TAO::ClientRequestInterceptor_Adapter *
TAO_ORB_Core::clientrequestinterceptor_adapter_i ()
{
  if (this->client_request_interceptor_adapter_ == nullptr)
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                        ace_mon,
                        this->lock_,
                        nullptr);

      if (this->client_request_interceptor_adapter_ == nullptr)
        {
          TAO_ClientRequestInterceptor_Adapter_Factory *factory =
            ACE_Dynamic_Service<TAO_ClientRequestInterceptor_Adapter_Factory>::instance
              (this->configuration (),
               ACE_TEXT ("ClientRequestInterceptor_Adapter_Factory"));

          if (factory)
            {
              this->client_request_interceptor_adapter_ =
                factory->create ();
            }
        }
    }

  return this->client_request_interceptor_adapter_;
}

void
TAO_ORB_Core::add_interceptor (
   PortableInterceptor::ServerRequestInterceptor_ptr interceptor
   )
{
  if (this->serverrequestinterceptor_adapter_i ())
    {
      this->server_request_interceptor_adapter_->add_interceptor (interceptor);
    }
  else
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - %p\n"),
                  ACE_TEXT ("ERROR: ORB Core unable to find the ")
                  ACE_TEXT ("Server Request Interceptor Adapter Factory ")
                  ACE_TEXT ("instance")));

      throw ::CORBA::INTERNAL ();
    }
}

void
TAO_ORB_Core::add_interceptor (
   PortableInterceptor::ClientRequestInterceptor_ptr interceptor,
   const CORBA::PolicyList& policies)
{
  if (this->clientrequestinterceptor_adapter_i ())
    {
      this->client_request_interceptor_adapter_->add_interceptor (
        interceptor,
        policies);
    }
  else
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - %p\n"),
                  ACE_TEXT ("ERROR: ORB Core unable to find the ")
                  ACE_TEXT ("Client Request Interceptor Adapter Factory ")
                  ACE_TEXT ("instance")));

      throw ::CORBA::INTERNAL ();
    }
}

void
TAO_ORB_Core::add_interceptor (
   PortableInterceptor::ServerRequestInterceptor_ptr interceptor,
   const CORBA::PolicyList& policies)
{
  if (this->serverrequestinterceptor_adapter_i ())
    {
      this->server_request_interceptor_adapter_->add_interceptor (
        interceptor,
        policies);
    }
  else
    {
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - %p\n"),
                  ACE_TEXT ("ERROR: ORB Core unable to find the ")
                  ACE_TEXT ("Server Request Interceptor Adapter Factory ")
                  ACE_TEXT ("instance")));

      throw ::CORBA::INTERNAL ();
    }
}

TAO::ServerRequestInterceptor_Adapter *
TAO_ORB_Core::serverrequestinterceptor_adapter_i ()
{
  if (this->server_request_interceptor_adapter_ == nullptr)
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                        ace_mon,
                        this->lock_,
                        nullptr);

      if (this->server_request_interceptor_adapter_ == nullptr)
        {
          TAO_ServerRequestInterceptor_Adapter_Factory *factory =
            ACE_Dynamic_Service<TAO_ServerRequestInterceptor_Adapter_Factory>::instance
              (this->configuration (),
               ACE_TEXT ("ServerRequestInterceptor_Adapter_Factory"));

          if (factory)
            {
              this->server_request_interceptor_adapter_ =
                factory->create ();
            }
        }
    }

  return this->server_request_interceptor_adapter_;
}

#endif  /* TAO_HAS_INTERCEPTORS == 1  */

TAO_Valuetype_Adapter *
TAO_ORB_Core::valuetype_adapter ()
{
  if (this->valuetype_adapter_ == nullptr)
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                        ace_mon,
                        this->lock_,
                        nullptr);

      if (this->valuetype_adapter_ == nullptr)
        {
          try
            {
              TAO_Valuetype_Adapter_Factory * vt_ap_factory =
                ACE_Dynamic_Service<TAO_Valuetype_Adapter_Factory>::instance (
                    TAO_ORB_Core::valuetype_adapter_factory_name ());

              if (vt_ap_factory)
                {
                  this->valuetype_adapter_ = vt_ap_factory->create ();
                }
            }
          catch (const ::CORBA::Exception& ex)
            {
              ex._tao_print_exception (
                "Cannot initialize the valuetype_adapter\n");
            }
        }

      if (this->valuetype_adapter_ == nullptr)
        {
           throw ::CORBA::INTERNAL ();
        }
    }

  return this->valuetype_adapter_;
}

// *************************************************************
// Valuetype factory operations
// *************************************************************

#if !defined(CORBA_E_MICRO)
CORBA::ValueFactory
TAO_ORB_Core::register_value_factory (const char *repository_id,
                                      CORBA::ValueFactory factory)
{
  if (this->valuetype_adapter ())
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, nullptr);

      if (this->valuetype_adapter_ == nullptr)
        {
          return nullptr;
        }

      int const result =
        this->valuetype_adapter_->vf_map_rebind (repository_id, factory);

      if (result == 0) // No previous factory found
        {
          return nullptr;
        }

      if (result == -1)
        {
          // Error on bind.
          throw ::CORBA::MARSHAL ();
        }
    }

  return factory;    // previous factory was found
}
#endif

#if !defined(CORBA_E_MICRO)
void
TAO_ORB_Core::unregister_value_factory (const char *repository_id)
{
  if (this->valuetype_adapter ())
    {
      ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);

      if (this->valuetype_adapter_ == nullptr)
        {
          return;
        }

      // Dont care whther it was successful or not!
      (void) this->valuetype_adapter_->vf_map_unbind (repository_id);
    }
}
#endif

#if !defined(CORBA_E_MICRO)
CORBA::ValueFactory
TAO_ORB_Core::lookup_value_factory (const char *repository_id)
{
  if (this->valuetype_adapter ())
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, nullptr);

      if (this->valuetype_adapter_ == nullptr)
        {
          return nullptr;
        }

      return this->valuetype_adapter_->vf_map_find (repository_id);
    }

  return nullptr;
}
#endif

// ****************************************************************

TAO_Export TAO_ORB_Core *
TAO_ORB_Core_instance ()
{
  // @@ This is a slight violation of layering, we should use
  //    TAO_ORB_Core_instance(), but that breaks during startup.
  TAO::ORB_Table * const orb_table = TAO::ORB_Table::instance ();
  if (orb_table->first_orb () == nullptr)
    {
      ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard,
                                *ACE_Static_Object_Lock::instance (), nullptr));

      if (orb_table->first_orb () == nullptr)
        {
          // Calling CORBA::ORB_init() returns a duplicated ORB
          // reference, so make sure that reference is stored in an
          // ORB_var so that no leak occurs.  The duplicate ORB
          // reference isn't needed outside the scope of this function
          // since the corresponding ORB Core instance will still
          // exist in the ORB table after the ORB reference is
          // destroyed.

          try
            {
              int argc = 0;
              ACE_TCHAR **const argv= nullptr;
              CORBA::ORB_var orb =
                CORBA::ORB_init (argc, argv);
            }
          catch (const ::CORBA::Exception&)
            {
              // @@ What should we do here?
            }
        }
    }

  return orb_table->first_orb ();
}

TAO_END_VERSIONED_NAMESPACE_DECL