1 #include "ace/Get_Opt.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");
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("a:b:y:z:"));
19 while ((c
= get_opts ()) != -1)
23 orb1_args
= get_opts
.opt_arg ();
26 orb2_args
= get_opts
.opt_arg ();
29 mapping_file1
= get_opts
.opt_arg ();
32 mapping_file2
= get_opts
.opt_arg ();
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>")
46 // Indicates successful parsing of the command line
51 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
55 if (parse_args (argc
, argv
) != 0)
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 "Cannot process args\n"),
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 ();
69 "Initialize ORB instances...\n"));
72 CORBA::ORB_init (orb1_argc
, orb1_argv
.argv (), mapping_file1
);
75 CORBA::ORB_init (orb2_argc
, orb2_argv
.argv (), mapping_file2
);
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 ();
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"));
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",
116 while (rtCorbaPriority1
< RTCORBA::maxPriority
)
120 status1
= priorityMapping1
->to_native (rtCorbaPriority1
,
125 ACE_ERROR ((LM_ERROR
,
126 "Could not map rtCorba priority %d "
127 "to a native priority.\n",
132 ACE_OS::fprintf (output_file
, "%d %d\n",
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
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"));
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",
173 while (rtCorbaPriority2
< RTCORBA::maxPriority
)
177 status2
= priorityMapping2
->to_native (rtCorbaPriority2
,
182 ACE_ERROR ((LM_ERROR
,
183 "Could not map rtCorba priority %d "
184 "to a native priority.\n",
189 ACE_OS::fprintf (output_file
, "%d %d\n",
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");