summaryrefslogtreecommitdiff
path: root/tests/Bug_3755_Regression/server.cpp
blob: 692792be9b59a618ebb8d52ac1b9e369f52d227a (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
// $Id$

#include "ace/Get_Opt.h"
#include "ace/ARGV.h"
#include "tao/RTCORBA/RTCORBA.h"
#include "tao/RTCORBA/Priority_Mapping_Manager.h"

ACE_TCHAR const *orb1_args =
  ACE_TEXT ("AAA -ORBGestalt LOCAL -ORBSvcConf MY_TEST_ORB_1.conf");
ACE_TCHAR const *orb2_args =
  ACE_TEXT ("BBB -ORBGestalt LOCAL -ORBSvcConf MY_TEST_ORB_2.conf");
ACE_TCHAR const *mapping_file1 = ACE_TEXT ("TAO_PRIORITY_MAPPING1.dat");
ACE_TCHAR const *mapping_file2 = ACE_TEXT ("TAO_PRIORITY_MAPPING2.dat");

int
parse_args (int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("a:b:y:z:"));
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'a':
        orb1_args = get_opts.opt_arg ();
        break;
      case 'b':
        orb2_args = get_opts.opt_arg ();
        break;
      case 'y':
        mapping_file1 = get_opts.opt_arg ();
        break;
      case 'z':
        mapping_file2 = get_opts.opt_arg ();
        break;
      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("usage:  %s ")
                           ACE_TEXT ("-a <orb1_args> ")
                           ACE_TEXT ("-b <orb2_args> ")
                           ACE_TEXT ("-y <mapping_file_for_orb1> ")
                           ACE_TEXT ("-z <mapping_file_for_orb2>")
                           ACE_TEXT ("\n"),
                           argv [0]),
                          -1);
      }
  // Indicates successful parsing of the command line
  return 0;
}

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      if (parse_args (argc, argv) != 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Cannot process args\n"),
                            1);
        }

      ACE_ARGV orb1_argv (orb1_args);
      int orb1_argc = orb1_argv.argc ();

      ACE_ARGV orb2_argv (orb2_args);
      int orb2_argc = orb2_argv.argc ();

      ACE_DEBUG ((LM_DEBUG,
                  "Initialize ORB instances...\n"));

      CORBA::ORB_var orb1 =
        CORBA::ORB_init (orb1_argc, orb1_argv.argv (), mapping_file1);

      CORBA::ORB_var orb2 =
        CORBA::ORB_init (orb2_argc, orb2_argv.argv (), mapping_file2);

      ACE_DEBUG ((LM_DEBUG,
                  "After ORB_init...\n"));


      // Demonstrate the priority mapping  ====================================

      CORBA::Object_var pmMgrObj1 =
        orb1->resolve_initial_references ("PriorityMappingManager");

      RTCORBA::PriorityMappingManager_var mappingMgr1 =
        RTCORBA::PriorityMappingManager::_narrow (pmMgrObj1.in ());

      RTCORBA::PriorityMapping * priorityMapping1 = mappingMgr1->mapping ();

      ACE_DEBUG ((LM_DEBUG,
                  "Priority Manager & mapping interfaces resolved.\n"));

      // Write the mapping to a file
      FILE *output_file = 0;
      if (mapping_file1 != 0)
        {
          output_file = ACE_OS::fopen (mapping_file1, "w");

          if (output_file == 0)
            {
              ACE_ERROR ((LM_ERROR,
                          "Cannot open output file for mapping 1\n"));
              return -1;
            }
        }

      short rtCorbaPriority1 = RTCORBA::minPriority - 1;
      short nativePriority1 = 0;
      bool status1 = false;

      ACE_DEBUG ((LM_DEBUG,
                  "Sending mapped priorities to %s...\n",
                  mapping_file1));

      while (rtCorbaPriority1 < RTCORBA::maxPriority)
        {
          ++rtCorbaPriority1;

          status1 = priorityMapping1->to_native (rtCorbaPriority1,
                                                 nativePriority1);

          if (!status1)
            {
              ACE_ERROR ((LM_ERROR,
                          "Could not map rtCorba priority %d "
                          "to a native priority.\n",
                          rtCorbaPriority1));
            }
          else
            {
              ACE_OS::fprintf (output_file, "%d %d\n",
                               rtCorbaPriority1,
                               nativePriority1);
            }
        }

      ACE_OS::fclose (output_file);

      CORBA::Object_var pmMgrObj2 =
        orb2->resolve_initial_references ("PriorityMappingManager");

      RTCORBA::PriorityMappingManager_var mappingMgr2 =
        RTCORBA::PriorityMappingManager::_narrow (pmMgrObj2.in ());

      RTCORBA::PriorityMapping * priorityMapping2 = mappingMgr2->mapping ();

      ACE_DEBUG ((LM_DEBUG,
                  "Priority Manager & mapping interfaces resolved.\n"));

      // Write the mapping to a file
      output_file = 0;
      if (mapping_file2 != 0)
        {
          output_file = ACE_OS::fopen (mapping_file2, "w");

          if (output_file == 0)
            {
              ACE_ERROR ((LM_ERROR,
                          "Cannot open output file for mapping 1\n"));
              return -1;
            }
        }

      short rtCorbaPriority2 = RTCORBA::minPriority - 1;
      short nativePriority2 = 0;
      bool status2 = false;

      ACE_DEBUG ((LM_DEBUG,
                  "Sending mapped priorities to %s...\n",
                  mapping_file2));

      while (rtCorbaPriority2 < RTCORBA::maxPriority)
        {
          ++rtCorbaPriority2;

          status2 = priorityMapping2->to_native (rtCorbaPriority2,
                                                 nativePriority2);

          if (!status2)
            {
              ACE_ERROR ((LM_ERROR,
                          "Could not map rtCorba priority %d "
                          "to a native priority.\n",
                          rtCorbaPriority2));
            }
          else
            {
              ACE_OS::fprintf (output_file, "%d %d\n",
                               rtCorbaPriority2,
                               nativePriority2);
            }
        }

      ACE_OS::fclose (output_file);

      // END priority mapping demonstration
    }
  catch (CORBA::SystemException const &sysEx)
    {
      sysEx._tao_print_exception ("Caught SystemException in main:\n");
      return 1;
    }

  return 0;
}