Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / AMI / server.cpp
blobfdaa47719f4cf17fd4cf638fea8eb2fddc3abde4
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,
51 priority);
53 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
54 priority);
56 // Enable FIFO scheduling
57 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
58 priority,
59 ACE_SCOPE_PROCESS)) != 0)
61 if (ACE_OS::last_error () == EPERM)
63 ACE_DEBUG ((LM_DEBUG,
64 "server (%P|%t): user is not superuser, "
65 "test runs in time-shared class\n"));
67 else
68 ACE_ERROR ((LM_ERROR,
69 "server (%P|%t): sched_params failed\n"));
72 try
74 CORBA::ORB_var orb =
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"),
83 1);
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)
92 return 1;
94 Roundtrip *roundtrip_impl;
95 ACE_NEW_RETURN (roundtrip_impl,
96 Roundtrip (orb.in ()),
97 1);
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",
111 ior_output_file),
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,
120 nthreads) != 0)
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);
133 orb->destroy ();
135 catch (const CORBA::Exception& ex)
137 ex._tao_print_exception ("Exception caught:");
138 return 1;
141 return 0;