Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / performance-tests / POA / Implicit_Activation / server.cpp
blob1d9054487c8edb7daba901bab517fcae6c863f82
1 #include "Factory.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 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int
36 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
38 int priority =
39 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
40 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
41 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
42 priority);
43 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
45 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
46 priority,
47 ACE_SCOPE_PROCESS)) != 0)
49 if (ACE_OS::last_error () == EPERM)
51 ACE_DEBUG ((LM_DEBUG,
52 "server (%P|%t): user is not superuser, "
53 "test runs in time-shared class\n"));
55 else
56 ACE_ERROR ((LM_ERROR,
57 "server (%P|%t): sched_params failed\n"));
60 try
62 CORBA::ORB_var orb =
63 CORBA::ORB_init (argc, argv);
65 CORBA::Object_var poa_object =
66 orb->resolve_initial_references("RootPOA");
68 if (CORBA::is_nil (poa_object.in ()))
69 ACE_ERROR_RETURN ((LM_ERROR,
70 " (%P|%t) Unable to initialize the POA.\n"),
71 1);
73 PortableServer::POA_var root_poa =
74 PortableServer::POA::_narrow (poa_object.in ());
76 PortableServer::POAManager_var poa_manager =
77 root_poa->the_POAManager ();
79 if (parse_args (argc, argv) != 0)
80 return 1;
82 Factory *factory_impl;
83 ACE_NEW_RETURN (factory_impl,
84 Factory (orb.in ()),
85 1);
86 PortableServer::ServantBase_var owner_transfer(factory_impl);
88 Test::Factory_var factory =
89 factory_impl->_this ();
91 CORBA::String_var ior =
92 orb->object_to_string (factory.in ());
94 // If the ior_output_file exists, output the ior to it
95 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
96 if (output_file == 0)
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "Cannot open output file for writing IOR: %s",
99 ior_output_file),
101 ACE_OS::fprintf (output_file, "%s", ior.in ());
102 ACE_OS::fclose (output_file);
104 poa_manager->activate ();
106 orb->run ();
108 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
110 root_poa->destroy (1, 1);
112 orb->destroy ();
114 catch (const CORBA::Exception& ex)
116 ex._tao_print_exception ("Exception caught:");
117 return 1;
120 return 0;