2 #include "Server_Task.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
8 bool simulate_crashes
= true;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("xn:o:"));
18 while ((c
= get_opts ()) != -1)
22 ior_output_file
= get_opts
.opt_arg ();
26 simulate_crashes
= false;
30 nthreads
= ACE_OS::atoi(get_opts
.opt_arg());
35 ACE_ERROR_RETURN ((LM_ERROR
,
38 " -x (do not simulate crashes)"
44 // Indicates successful parsing of the command line
49 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
51 // Fetching the high res timer's global scale factor ensures that it
52 // is calibrated (if necessary on this platform) at the beginning of
53 // the test. While the timer would otherwise be calibrated on first
54 // use, this introduces delay in the middle of the test's execution.
55 // This leads to failures due to timing assumptions (timeouts, etc.)
56 // within the test itself.
57 (void) ACE_High_Res_Timer::global_scale_factor();
62 CORBA::ORB_init (argc
, argv
);
64 CORBA::Object_var poa_object
=
65 orb
->resolve_initial_references("RootPOA");
67 PortableServer::POA_var root_poa
=
68 PortableServer::POA::_narrow (poa_object
.in ());
70 if (CORBA::is_nil (root_poa
.in ()))
71 ACE_ERROR_RETURN ((LM_ERROR
,
72 " (%P|%t) Panic: nil RootPOA\n"),
75 PortableServer::POAManager_var poa_manager
=
76 root_poa
->the_POAManager ();
78 if (parse_args (argc
, argv
) != 0)
81 PortableServer::ServantBase_var
hello_impl(
82 new Hello(orb
.in(), simulate_crashes
));
84 PortableServer::ObjectId_var id
=
85 root_poa
->activate_object (hello_impl
.in ());
87 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
89 Test::Hello_var hello
=
90 Test::Hello::_narrow (object
.in ());
92 CORBA::String_var ior
=
93 orb
->object_to_string (hello
.in ());
95 // Output the IOR to the <ior_output_file>
96 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
98 ACE_ERROR_RETURN ((LM_ERROR
,
99 "Cannot open output file for writing IOR: %s",
102 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
103 ACE_OS::fclose (output_file
);
105 poa_manager
->activate ();
108 Server_Task
st (orb
.in (),
109 ACE_Thread_Manager::instance ());
111 if (st
.activate (THR_NEW_LWP
| THR_JOINABLE
, nthreads
, 1) == -1)
113 ACE_ERROR ((LM_ERROR
,
114 "Error activating server task\n"));
119 ACE_Thread_Manager::instance()->wait();
121 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
123 root_poa
->destroy (true, true);
127 catch (const CORBA::Exception
& ex
)
129 ex
._tao_print_exception ("Exception caught:");