summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_2503_Regression/server.cpp
blob: 558335e4e37a03798708649f2392ba111e9a0c5f (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
// $Id$

#include "test_i.h"
#include "common.h"
#include "ace/Get_Opt.h"
#include "ace/OS_NS_stdio.h"

void parse_args(int argc, char * argv[]);
void write_ior_to_file(char const * ior);

int
main(int argc, char * argv[])
{
  try
  {
    CORBA::ORB_var orb = initialize_orb_and_poa(argc, argv);

    parse_args(argc, argv);

    test_i servant (orb.in());
    CORBA::String_var ior =
      servant.create_and_activate_server();

    write_ior_to_file(ior.in());

    orb->run();
  }
  catch(...)
  {
    report_exception();
    return 1;
  }
  return 0;
}

namespace
{
const char *ior_output_file = "test.ior";
}

void
parse_args(int argc, char * argv[])
{
  ACE_Get_Opt get_opts (argc, argv, "o:");
  int c;

  while ((c = get_opts ()) != -1)
  {
    switch (c)
      {
      case 'o':
        ior_output_file = get_opts.opt_arg ();
        break;

      case '?':
      default:
        throw "Usage: server [-o iorfile]\n";
      }
  }
}

void write_ior_to_file(char const * ior)
{
  if (ior_output_file == 0)
  {
    return;
  }

  FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
  if (output_file == 0)
  {
    throw "Cannot open output file to write the IOR";
  }

  ACE_OS::fprintf (output_file, "%s", ior);
  ACE_OS::fclose (output_file);
}