Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / performance-tests / Latency / AMI / server.cpp
blob1ba7876caee6c618a8500164d8d3d7203cb322e7
1 #include "Roundtrip.h"
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");
10 int nthreads = 4;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:n:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'o':
22 ior_output_file = get_opts.opt_arg ();
23 break;
25 case 'n':
26 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
27 break;
29 case '?':
30 default:
31 ACE_ERROR_RETURN ((LM_ERROR,
32 "usage: %s "
33 "-o <iorfile> "
34 "-n <nthreads> "
35 "\n",
36 argv [0]),
37 -1);
39 // Indicates successful parsing of the command line
40 return 0;
43 int
44 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
46 int priority =
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,
55 priority,
56 ACE_SCOPE_PROCESS)) != 0)
58 if (ACE_OS::last_error () == EPERM)
60 ACE_DEBUG ((LM_DEBUG,
61 "server (%P|%t): user is not superuser, "
62 "test runs in time-shared class\n"));
64 else
65 ACE_ERROR ((LM_ERROR,
66 "server (%P|%t): sched_params failed\n"));
69 try
71 CORBA::ORB_var orb =
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"),
80 1);
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)
89 return 1;
91 Roundtrip *roundtrip_impl;
92 ACE_NEW_RETURN (roundtrip_impl,
93 Roundtrip (orb.in ()),
94 1);
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",
108 ior_output_file),
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,
117 nthreads) != 0)
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);
130 orb->destroy ();
132 catch (const CORBA::Exception& ex)
134 ex._tao_print_exception ("Exception caught:");
135 return 1;
138 return 0;