ACE+TAO-7_0_8
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / Federated_Roundtrip / server.cpp
blob7c7e0fbe6cc402bc941d7b6ce1066aee734f38c7
1 #include "RT_Class.h"
2 #include "ORB_Holder.h"
3 #include "Servant_var.h"
4 #include "RIR_Narrow.h"
5 #include "RTServer_Setup.h"
6 #include "Control.h"
8 #include "tao/PortableServer/PortableServer.h"
9 #include "tao/RTPortableServer/RTPortableServer.h"
10 #include "tao/Strategies/advanced_resource.h"
11 #include "tao/Messaging/Messaging.h"
12 #include "ace/Get_Opt.h"
13 #include "ace/Auto_Ptr.h"
15 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
16 int iterations = 10000;
17 int nthreads = 1;
18 int peer_count = 2;
19 int do_dump_history = 0;
20 int use_rt_corba = 0;
22 int
23 parse_args (int argc, ACE_TCHAR *argv[])
25 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:i:p:n:rd"));
26 int c;
28 while ((c = get_opts ()) != -1)
29 switch (c)
31 case 'o':
32 ior_output_file = get_opts.opt_arg ();
33 break;
35 case 'n':
36 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
37 break;
39 case 'i':
40 iterations = ACE_OS::atoi (get_opts.opt_arg ());
41 break;
43 case 'p':
44 peer_count = ACE_OS::atoi (get_opts.opt_arg ());
45 break;
47 case 'r':
48 use_rt_corba = 1;
49 break;
51 case 'd':
52 do_dump_history = 1;
53 break;
55 case '?':
56 default:
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "usage: %s "
59 "-o <iorfile> "
60 "-n nthreads "
61 "-i iterations "
62 "-p peer_count "
63 "-r (use RT-CORBA) "
64 "-d (dump full history) "
65 "\n",
66 argv [0]),
67 -1);
69 // Indicates successful parsing of the command line
70 return 0;
73 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
75 RT_Class rt_class;
77 try
79 ORB_Holder orb (argc, argv, "");
81 if (parse_args (argc, argv) != 0)
82 return 1;
84 RTServer_Setup rtserver_setup (use_rt_corba,
85 orb,
86 rt_class,
87 nthreads);
89 PortableServer::POA_var root_poa =
90 RIR_Narrow<PortableServer::POA>::resolve (orb,
91 "RootPOA");
93 PortableServer::POAManager_var poa_manager =
94 root_poa->the_POAManager ();
96 poa_manager->activate ();
98 PortableServer::POA_var control_poa (rtserver_setup.poa ());
99 Servant_var<Control> control_impl (
100 new Control (peer_count,
101 iterations,
102 do_dump_history,
103 orb,
104 control_poa.in ())
107 Federated_Test::Control_var control =
108 control_impl->_this ();
110 CORBA::String_var ior =
111 orb->object_to_string (control.in ());
113 // Output the ior to the <ior_output_file>
114 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
115 if (output_file == 0)
116 ACE_ERROR_RETURN ((LM_ERROR,
117 "Cannot open output file for writing IOR: %s",
118 ior_output_file),
120 ACE_OS::fprintf (output_file, "%s", ior.in ());
121 ACE_OS::fclose (output_file);
123 poa_manager->activate ();
125 orb->run ();
127 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
129 catch (const CORBA::Exception& ex)
131 ex._tao_print_exception ("Exception caught:");
132 return 1;
135 return 0;