Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / performance-tests / Latency / Thread_Pool / server.cpp
blobcd5e70115aa797a793d2d9da5aebe7e6f85e6a29
1 #include "Roundtrip.h"
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");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior_output_file = get_opts.opt_arg ();
22 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-o <iorfile>"
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
40 int priority =
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,
44 priority);
45 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
47 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
48 priority,
49 ACE_SCOPE_PROCESS)) != 0)
51 if (ACE_OS::last_error () == EPERM)
53 ACE_DEBUG ((LM_DEBUG,
54 "server (%P|%t): user is not superuser, "
55 "test runs in time-shared class\n"));
57 else
58 ACE_ERROR ((LM_ERROR,
59 "server (%P|%t): sched_params failed\n"));
62 try
64 CORBA::ORB_var orb =
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"),
73 1);
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)
82 return 1;
84 Roundtrip *roundtrip_impl;
85 ACE_NEW_RETURN (roundtrip_impl,
86 Roundtrip (orb.in ()),
87 1);
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",
106 ior_output_file),
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);
122 orb->destroy ();
124 catch (const CORBA::Exception& ex)
126 ex._tao_print_exception ("Exception caught:");
127 return 1;
130 return 0;