Merge pull request #2306 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / Roundtrip / server.cpp
blob394f38812425700759cec09fb8621e444036fbed
1 #include "RT_Class.h"
2 #include "ORB_Holder.h"
3 #include "Servant_var.h"
4 #include "RIR_Narrow.h"
5 #include "RTEC_Initializer.h"
6 #include "RTServer_Setup.h"
7 #include "ORB_Task.h"
8 #include "ORB_Task_Activator.h"
10 #include "orbsvcs/Event/EC_Event_Channel.h"
11 #include "orbsvcs/Event/EC_Default_Factory.h"
13 #include "tao/PortableServer/PortableServer.h"
14 #include "tao/RTPortableServer/RTPortableServer.h"
15 #include "tao/Strategies/advanced_resource.h"
16 #include "tao/Messaging/Messaging.h"
17 #include "ace/Get_Opt.h"
19 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
20 int use_rt_corba = 0;
21 int nthreads = 0;
23 int
24 parse_args (int argc, ACE_TCHAR *argv[])
26 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:n:r"));
27 int c;
29 while ((c = get_opts ()) != -1)
30 switch (c)
32 case 'o':
33 ior_output_file = get_opts.opt_arg ();
34 break;
36 case 'n':
37 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
38 break;
40 case 'r':
41 use_rt_corba = 1;
42 break;
44 case '?':
45 default:
46 ACE_ERROR_RETURN ((LM_ERROR,
47 "usage: %s "
48 "-o <iorfile> "
49 "-r (use RT-CORBA) "
50 "-n nthreads "
51 "\n",
52 argv [0]),
53 -1);
55 // Indicates successful parsing of the command line
56 return 0;
59 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
61 TAO_EC_Default_Factory::init_svcs ();
63 /// Move the test to the real-time class if it is possible.
64 RT_Class rt_class;
66 try
68 ORB_Holder orb (argc, argv, "");
70 if (parse_args (argc, argv) != 0)
71 return 1;
73 RTServer_Setup rtserver_setup (use_rt_corba,
74 orb,
75 rt_class,
76 nthreads);
78 PortableServer::POA_var root_poa =
79 RIR_Narrow<PortableServer::POA>::resolve (orb,
80 "RootPOA");
82 PortableServer::POAManager_var poa_manager =
83 root_poa->the_POAManager ();
85 poa_manager->activate ();
87 PortableServer::POA_var ec_poa (rtserver_setup.poa ());
89 ORB_Task orb_task (orb);
90 ORB_Task_Activator orb_task_activator (rt_class.priority_high (),
91 rt_class.thr_sched_class (),
92 nthreads,
93 &orb_task);
95 ACE_DEBUG ((LM_DEBUG, "Finished ORB and POA configuration\n"));
97 Servant_var<TAO_EC_Event_Channel> ec_impl (
98 RTEC_Initializer::create (ec_poa.in (),
99 ec_poa.in (),
100 rtserver_setup.rtcorba_setup ()));
102 ec_impl->activate ();
104 PortableServer::ObjectId_var ec_id =
105 ec_poa->activate_object (ec_impl.in ());
106 CORBA::Object_var ec_object =
107 ec_poa->id_to_reference (ec_id.in ());
109 RtecEventChannelAdmin::EventChannel_var ec =
110 RtecEventChannelAdmin::EventChannel::_narrow (ec_object.in ());
112 CORBA::String_var ior =
113 orb->object_to_string (ec.in ());
115 // Output the ior to the <ior_output_file>
116 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
117 if (output_file == 0)
118 ACE_ERROR_RETURN ((LM_ERROR,
119 "Cannot open output file for writing IOR: %s",
120 ior_output_file),
122 ACE_OS::fprintf (output_file, "%s", ior.in ());
123 ACE_OS::fclose (output_file);
125 do {
126 ACE_Time_Value tv (1, 0);
127 orb->run (tv);
128 } while (ec_impl->destroyed () == 0);
130 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
132 catch (const CORBA::Exception& ex)
134 ex._tao_print_exception ("Exception caught:");
135 return 1;
138 return 0;