Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / performance-tests / Latency / DSI / server.cpp
blob71b0808a4fd3692d12bb3dbd1b4835d94e1399aa
1 #include "Roundtrip.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Sched_Params.h"
4 #include "ace/OS_NS_errno.h"
6 #include "tao/Strategies/advanced_resource.h"
8 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'o':
20 ior_output_file = get_opts.opt_arg ();
21 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-o <iorfile>"
28 "\n",
29 argv [0]),
30 -1);
32 // Indicates successful parsing of the command line
33 return 0;
36 int
37 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
39 int priority =
40 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
41 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
42 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
43 priority);
44 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
46 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
47 priority,
48 ACE_SCOPE_PROCESS)) != 0)
50 if (ACE_OS::last_error () == EPERM)
52 ACE_DEBUG ((LM_DEBUG,
53 "server (%P|%t): user is not superuser, "
54 "test runs in time-shared class\n"));
56 else
57 ACE_ERROR ((LM_ERROR,
58 "server (%P|%t): sched_params failed\n"));
61 try
63 CORBA::ORB_var orb =
64 CORBA::ORB_init (argc, argv);
66 CORBA::Object_var poa_object =
67 orb->resolve_initial_references("RootPOA");
69 if (CORBA::is_nil (poa_object.in ()))
70 ACE_ERROR_RETURN ((LM_ERROR,
71 " (%P|%t) Unable to initialize the POA.\n"),
72 1);
74 PortableServer::POA_var root_poa =
75 PortableServer::POA::_narrow (poa_object.in ());
77 PortableServer::POAManager_var poa_manager =
78 root_poa->the_POAManager ();
80 if (parse_args (argc, argv) != 0)
81 return 1;
83 Roundtrip *roundtrip_impl;
84 ACE_NEW_RETURN (roundtrip_impl,
85 Roundtrip (orb.in ()),
86 1);
87 PortableServer::ServantBase_var owner_transfer(roundtrip_impl);
89 PortableServer::ObjectId_var oid =
90 root_poa->activate_object (roundtrip_impl);
92 CORBA::Object_var roundtrip =
93 root_poa->id_to_reference (oid.in ());
95 CORBA::String_var ior =
96 orb->object_to_string (roundtrip.in ());
98 // If the ior_output_file exists, output the ior to it
99 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
100 if (output_file == 0)
101 ACE_ERROR_RETURN ((LM_ERROR,
102 "Cannot open output file for writing IOR: %s",
103 ior_output_file),
105 ACE_OS::fprintf (output_file, "%s", ior.in ());
106 ACE_OS::fclose (output_file);
108 poa_manager->activate ();
110 orb->run ();
112 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
114 root_poa->destroy (1, 1);
116 orb->destroy ();
118 catch (const CORBA::Exception& ex)
120 ex._tao_print_exception ("Exception caught:");
121 return 1;
124 return 0;