Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_3755_Regression / server.cpp
blob24ba8277b2021206194a12b2d744d240bd1a79b7
1 #include "ace/Get_Opt.h"
2 #include "ace/ARGV.h"
3 #include "tao/RTCORBA/RTCORBA.h"
4 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
6 ACE_TCHAR const *orb1_args =
7 ACE_TEXT ("AAA -ORBGestalt LOCAL -ORBSvcConf MY_TEST_ORB_1.conf");
8 ACE_TCHAR const *orb2_args =
9 ACE_TEXT ("BBB -ORBGestalt LOCAL -ORBSvcConf MY_TEST_ORB_2.conf");
10 ACE_TCHAR const *mapping_file1 = ACE_TEXT ("TAO_PRIORITY_MAPPING1.dat");
11 ACE_TCHAR const *mapping_file2 = ACE_TEXT ("TAO_PRIORITY_MAPPING2.dat");
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("a:b:y:z:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'a':
23 orb1_args = get_opts.opt_arg ();
24 break;
25 case 'b':
26 orb2_args = get_opts.opt_arg ();
27 break;
28 case 'y':
29 mapping_file1 = get_opts.opt_arg ();
30 break;
31 case 'z':
32 mapping_file2 = get_opts.opt_arg ();
33 break;
34 case '?':
35 default:
36 ACE_ERROR_RETURN ((LM_ERROR,
37 ACE_TEXT ("usage: %s ")
38 ACE_TEXT ("-a <orb1_args> ")
39 ACE_TEXT ("-b <orb2_args> ")
40 ACE_TEXT ("-y <mapping_file_for_orb1> ")
41 ACE_TEXT ("-z <mapping_file_for_orb2>")
42 ACE_TEXT ("\n"),
43 argv [0]),
44 -1);
46 // Indicates successful parsing of the command line
47 return 0;
50 int
51 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
53 try
55 if (parse_args (argc, argv) != 0)
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "Cannot process args\n"),
59 1);
62 ACE_ARGV orb1_argv (orb1_args);
63 int orb1_argc = orb1_argv.argc ();
65 ACE_ARGV orb2_argv (orb2_args);
66 int orb2_argc = orb2_argv.argc ();
68 ACE_DEBUG ((LM_DEBUG,
69 "Initialize ORB instances...\n"));
71 CORBA::ORB_var orb1 =
72 CORBA::ORB_init (orb1_argc, orb1_argv.argv (), mapping_file1);
74 CORBA::ORB_var orb2 =
75 CORBA::ORB_init (orb2_argc, orb2_argv.argv (), mapping_file2);
77 ACE_DEBUG ((LM_DEBUG,
78 "After ORB_init...\n"));
81 // Demonstrate the priority mapping ====================================
83 CORBA::Object_var pmMgrObj1 =
84 orb1->resolve_initial_references ("PriorityMappingManager");
86 RTCORBA::PriorityMappingManager_var mappingMgr1 =
87 RTCORBA::PriorityMappingManager::_narrow (pmMgrObj1.in ());
89 RTCORBA::PriorityMapping * priorityMapping1 = mappingMgr1->mapping ();
91 ACE_DEBUG ((LM_DEBUG,
92 "Priority Manager & mapping interfaces resolved.\n"));
94 // Write the mapping to a file
95 FILE *output_file = 0;
96 if (mapping_file1 != 0)
98 output_file = ACE_OS::fopen (mapping_file1, "w");
100 if (output_file == 0)
102 ACE_ERROR ((LM_ERROR,
103 "Cannot open output file for mapping 1\n"));
104 return -1;
108 short rtCorbaPriority1 = RTCORBA::minPriority - 1;
109 short nativePriority1 = 0;
110 bool status1 = false;
112 ACE_DEBUG ((LM_DEBUG,
113 "Sending mapped priorities to %s...\n",
114 mapping_file1));
116 while (rtCorbaPriority1 < RTCORBA::maxPriority)
118 ++rtCorbaPriority1;
120 status1 = priorityMapping1->to_native (rtCorbaPriority1,
121 nativePriority1);
123 if (!status1)
125 ACE_ERROR ((LM_ERROR,
126 "Could not map rtCorba priority %d "
127 "to a native priority.\n",
128 rtCorbaPriority1));
130 else
132 ACE_OS::fprintf (output_file, "%d %d\n",
133 rtCorbaPriority1,
134 nativePriority1);
138 ACE_OS::fclose (output_file);
140 CORBA::Object_var pmMgrObj2 =
141 orb2->resolve_initial_references ("PriorityMappingManager");
143 RTCORBA::PriorityMappingManager_var mappingMgr2 =
144 RTCORBA::PriorityMappingManager::_narrow (pmMgrObj2.in ());
146 RTCORBA::PriorityMapping * priorityMapping2 = mappingMgr2->mapping ();
148 ACE_DEBUG ((LM_DEBUG,
149 "Priority Manager & mapping interfaces resolved.\n"));
151 // Write the mapping to a file
152 output_file = 0;
153 if (mapping_file2 != 0)
155 output_file = ACE_OS::fopen (mapping_file2, "w");
157 if (output_file == 0)
159 ACE_ERROR ((LM_ERROR,
160 "Cannot open output file for mapping 1\n"));
161 return -1;
165 short rtCorbaPriority2 = RTCORBA::minPriority - 1;
166 short nativePriority2 = 0;
167 bool status2 = false;
169 ACE_DEBUG ((LM_DEBUG,
170 "Sending mapped priorities to %s...\n",
171 mapping_file2));
173 while (rtCorbaPriority2 < RTCORBA::maxPriority)
175 ++rtCorbaPriority2;
177 status2 = priorityMapping2->to_native (rtCorbaPriority2,
178 nativePriority2);
180 if (!status2)
182 ACE_ERROR ((LM_ERROR,
183 "Could not map rtCorba priority %d "
184 "to a native priority.\n",
185 rtCorbaPriority2));
187 else
189 ACE_OS::fprintf (output_file, "%d %d\n",
190 rtCorbaPriority2,
191 nativePriority2);
195 ACE_OS::fclose (output_file);
197 // END priority mapping demonstration
199 catch (const CORBA::SystemException &sysEx)
201 sysEx._tao_print_exception ("Caught SystemException in main:\n");
202 return 1;
205 return 0;