2 #include "Worker_Thread.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Sched_Params.h"
5 #include "ace/OS_NS_errno.h"
7 #include "tao/Strategies/advanced_resource.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
38 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
41 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
42 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
43 priority
= ACE_Sched_Params::next_priority (ACE_SCHED_FIFO
,
45 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
47 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
49 ACE_SCOPE_PROCESS
)) != 0)
51 if (ACE_OS::last_error () == EPERM
)
54 "server (%P|%t): user is not superuser, "
55 "test runs in time-shared class\n"));
59 "server (%P|%t): sched_params failed\n"));
65 CORBA::ORB_init (argc
, argv
);
67 CORBA::Object_var poa_object
=
68 orb
->resolve_initial_references("RootPOA");
70 if (CORBA::is_nil (poa_object
.in ()))
71 ACE_ERROR_RETURN ((LM_ERROR
,
72 " (%P|%t) Unable to initialize the POA.\n"),
75 PortableServer::POA_var root_poa
=
76 PortableServer::POA::_narrow (poa_object
.in ());
78 PortableServer::POAManager_var poa_manager
=
79 root_poa
->the_POAManager ();
81 if (parse_args (argc
, argv
) != 0)
84 Roundtrip
*roundtrip_impl
;
85 ACE_NEW_RETURN (roundtrip_impl
,
86 Roundtrip (orb
.in ()),
88 PortableServer::ServantBase_var
owner_transfer(roundtrip_impl
);
90 PortableServer::ObjectId_var id
=
91 root_poa
->activate_object (roundtrip_impl
);
93 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
95 Test::Roundtrip_var roundtrip
=
96 Test::Roundtrip::_narrow (object
.in ());
98 CORBA::String_var ior
=
99 orb
->object_to_string (roundtrip
.in ());
101 // If the ior_output_file exists, output the ior to it
102 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
103 if (output_file
== 0)
104 ACE_ERROR_RETURN ((LM_ERROR
,
105 "Cannot open output file for writing IOR: %s",
108 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
109 ACE_OS::fclose (output_file
);
111 poa_manager
->activate ();
113 Worker_Thread
worker (orb
.in ());
115 worker
.activate (THR_NEW_LWP
| THR_JOINABLE
, 4, 1);
116 worker
.thr_mgr ()->wait ();
118 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
120 root_poa
->destroy (1, 1);
124 catch (const CORBA::Exception
& ex
)
126 ex
._tao_print_exception ("Exception caught:");