2 #include "Server_Task.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");
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:n:"));
18 while ((c
= get_opts ()) != -1)
22 ior_output_file
= get_opts
.opt_arg ();
26 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
31 ACE_ERROR_RETURN ((LM_ERROR
,
39 // Indicates successful parsing of the command line
44 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
47 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
48 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
50 priority
= ACE_Sched_Params::next_priority (ACE_SCHED_FIFO
,
53 priority
= ACE_Sched_Params::next_priority (ACE_SCHED_FIFO
,
56 // Enable FIFO scheduling
57 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
59 ACE_SCOPE_PROCESS
)) != 0)
61 if (ACE_OS::last_error () == EPERM
)
64 "server (%P|%t): user is not superuser, "
65 "test runs in time-shared class\n"));
69 "server (%P|%t): sched_params failed\n"));
75 CORBA::ORB_init (argc
, argv
);
77 CORBA::Object_var poa_object
=
78 orb
->resolve_initial_references("RootPOA");
80 if (CORBA::is_nil (poa_object
.in ()))
81 ACE_ERROR_RETURN ((LM_ERROR
,
82 " (%P|%t) Unable to initialize the POA.\n"),
85 PortableServer::POA_var root_poa
=
86 PortableServer::POA::_narrow (poa_object
.in ());
88 PortableServer::POAManager_var poa_manager
=
89 root_poa
->the_POAManager ();
91 if (parse_args (argc
, argv
) != 0)
94 Roundtrip
*roundtrip_impl
;
95 ACE_NEW_RETURN (roundtrip_impl
,
96 Roundtrip (orb
.in ()),
98 PortableServer::ServantBase_var
owner_transfer(roundtrip_impl
);
100 Test::Roundtrip_var roundtrip
=
101 roundtrip_impl
->_this ();
103 CORBA::String_var ior
=
104 orb
->object_to_string (roundtrip
.in ());
106 // If the ior_output_file exists, output the ior to it
107 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
108 if (output_file
== 0)
109 ACE_ERROR_RETURN ((LM_ERROR
,
110 "Cannot open output file for writing IOR: %s",
113 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
114 ACE_OS::fclose (output_file
);
116 poa_manager
->activate ();
118 Server_Task
server_task (orb
.in ());
119 if (server_task
.activate (THR_NEW_LWP
| THR_JOINABLE
,
121 ACE_ERROR_RETURN ((LM_ERROR
,
122 "Cannot activate server threads\n"),
125 server_task
.thr_mgr ()->wait ();
127 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
129 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
131 root_poa
->destroy (true, true);
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("Exception caught:");