Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / performance-tests / RTCorba / Oneways / Reliable / server.cpp
blobf38ce3b0f299905cc9898162c80899ce745fadcd
1 #include "test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Sched_Params.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/OS_NS_errno.h"
7 // IOR file name
8 static const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
10 static 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 <ior file> "
28 "\n",
29 argv [0]),
30 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 set_rt_mode ()
40 int policy = ACE_SCHED_FIFO;
41 int priority =
42 (ACE_Sched_Params::priority_min (policy)
43 + ACE_Sched_Params::priority_max (policy)) / 2;
45 // Enable FIFO scheduling
46 int result =
47 ACE_OS::sched_params (ACE_Sched_Params (policy,
48 priority,
49 ACE_SCOPE_PROCESS));
50 if (result != 0)
52 if (ACE_OS::last_error () == EPERM)
54 ACE_DEBUG ((LM_DEBUG,
55 "client (%P|%t): user is not superuser, "
56 "test runs in time-shared class\n"));
58 else
59 ACE_ERROR ((LM_ERROR,
60 "client (%P|%t): sched_params failed %p\n",
61 "set_rt_mode"));
64 // Get our thread handle.
65 ACE_hthread_t self;
66 ACE_OS::thr_self (self);
68 // Set our thread priority.
69 if (ACE_OS::thr_setprio (self, priority) != 0)
70 ACE_ERROR ((LM_ERROR,
71 "server (%P|%t):thr_setprio failed %p\n",
72 "set_rt_mode"));
74 // Do a sanity check.
75 if (ACE_OS::thr_getprio (self, priority) == 0)
76 ACE_DEBUG ((LM_DEBUG,
77 "client (%P|%t): thread priority = %d.\n",
78 priority));
80 return 0;
83 int
84 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
86 int result = set_rt_mode ();
87 if (result != 0)
88 return result;
90 try
92 CORBA::ORB_var orb =
93 CORBA::ORB_init (argc,
94 argv);
96 // Get the command line options.
97 if (parse_args (argc, argv) != 0)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "parse_args failed\n"),
104 CORBA::Object_var poa_object =
105 orb->resolve_initial_references ("RootPOA");
107 PortableServer::POA_var root_poa =
108 PortableServer::POA::_narrow (poa_object.in ());
110 PortableServer::POAManager_var poa_manager =
111 root_poa->the_POAManager ();
113 Test_i server_impl (orb.in ());
115 Test_var server =
116 server_impl._this ();
118 CORBA::String_var ior =
119 orb->object_to_string (server.in ());
121 ACE_DEBUG ((LM_DEBUG,
122 "Activated as <%C>\n",
123 ior.in ()));
125 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
127 if (output_file == 0)
128 ACE_ERROR_RETURN ((LM_ERROR,
129 "Cannot open output file for writing IOR: %s",
130 ior_output_file),
133 ACE_OS::fprintf (output_file,
134 "%s",
135 ior.in ());
137 ACE_OS::fclose (output_file);
139 poa_manager->activate ();
141 orb->run ();
143 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
145 root_poa->destroy (true, true);
147 catch (const CORBA::Exception& ex)
149 ex._tao_print_exception ("server");
150 return 1;
153 return 0;