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
, priority
);
51 priority
= ACE_Sched_Params::next_priority (ACE_SCHED_FIFO
, priority
);
53 // Enable FIFO scheduling
54 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
56 ACE_SCOPE_PROCESS
)) != 0)
58 if (ACE_OS::last_error () == EPERM
)
61 "server (%P|%t): user is not superuser, "
62 "test runs in time-shared class\n"));
66 "server (%P|%t): sched_params failed\n"));
72 CORBA::ORB_init (argc
, argv
);
74 CORBA::Object_var poa_object
=
75 orb
->resolve_initial_references("RootPOA");
77 if (CORBA::is_nil (poa_object
.in ()))
78 ACE_ERROR_RETURN ((LM_ERROR
,
79 " (%P|%t) Unable to initialize the POA.\n"),
82 PortableServer::POA_var root_poa
=
83 PortableServer::POA::_narrow (poa_object
.in ());
85 PortableServer::POAManager_var poa_manager
=
86 root_poa
->the_POAManager ();
88 if (parse_args (argc
, argv
) != 0)
91 Roundtrip
*roundtrip_impl
;
92 ACE_NEW_RETURN (roundtrip_impl
,
93 Roundtrip (orb
.in ()),
95 PortableServer::ServantBase_var
owner_transfer(roundtrip_impl
);
97 Test::Roundtrip_var roundtrip
=
98 roundtrip_impl
->_this ();
100 CORBA::String_var ior
=
101 orb
->object_to_string (roundtrip
.in ());
103 // If the ior_output_file exists, output the ior to it
104 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
105 if (output_file
== 0)
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 "Cannot open output file for writing IOR: %s",
110 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
111 ACE_OS::fclose (output_file
);
113 poa_manager
->activate ();
115 Server_Task
server_task (orb
.in ());
116 if (server_task
.activate (THR_NEW_LWP
| THR_JOINABLE
,
118 ACE_ERROR_RETURN ((LM_ERROR
,
119 "Cannot activate server threads\n"),
122 server_task
.thr_mgr ()->wait ();
124 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
126 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
128 root_poa
->destroy (true, true);
132 catch (const CORBA::Exception
& ex
)
134 ex
._tao_print_exception ("Exception caught:");