Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_2503_Regression / server.cpp
blob81c8557b8d6359d1bf70ab214c2447fd16233d0a
1 #include "test_i.h"
2 #include "common.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/High_Res_Timer.h"
7 void parse_args(int argc, ACE_TCHAR* argv[]);
8 void write_ior_to_file(char const * ior);
10 int
11 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
13 // Fetching the high res timer's global scale factor ensures that it
14 // is calibrated (if necessary on this platform) at the beginning of
15 // the test. While the timer would otherwise be calibrated on first
16 // use, this introduces delay in the middle of the test's execution.
17 // This leads to failures due to timing assumptions (timeouts, etc.)
18 // within the test itself.
19 (void) ACE_High_Res_Timer::global_scale_factor();
21 try
23 CORBA::ORB_var orb = initialize_orb_and_poa(argc, argv);
25 parse_args(argc, argv);
27 test_i servant (orb.in());
28 CORBA::String_var ior =
29 servant.create_and_activate_server();
31 write_ior_to_file(ior.in());
33 orb->run();
35 catch(...)
37 report_exception();
38 return 1;
40 return 0;
43 namespace
45 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
48 void
49 parse_args(int argc, ACE_TCHAR* argv[])
51 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
52 int c;
54 while ((c = get_opts ()) != -1)
56 switch (c)
58 case 'o':
59 ior_output_file = get_opts.opt_arg ();
60 break;
62 case '?':
63 default:
64 throw "Usage: server [-o iorfile]\n";
69 void write_ior_to_file(char const * ior)
71 if (ior_output_file == 0)
73 return;
76 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
77 if (output_file == 0)
79 throw "Cannot open output file to write the IOR";
82 ACE_OS::fprintf (output_file, "%s", ior);
83 ACE_OS::fclose (output_file);