Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / Roundtrip / server.cpp
blob17fb3f4f5d07e72df1aa1e9d5722ceb2114b2a02
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"
18 #include "ace/Auto_Ptr.h"
20 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
21 int use_rt_corba = 0;
22 int nthreads = 0;
24 int
25 parse_args (int argc, ACE_TCHAR *argv[])
27 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:n:r"));
28 int c;
30 while ((c = get_opts ()) != -1)
31 switch (c)
33 case 'o':
34 ior_output_file = get_opts.opt_arg ();
35 break;
37 case 'n':
38 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
39 break;
41 case 'r':
42 use_rt_corba = 1;
43 break;
45 case '?':
46 default:
47 ACE_ERROR_RETURN ((LM_ERROR,
48 "usage: %s "
49 "-o <iorfile> "
50 "-r (use RT-CORBA) "
51 "-n nthreads "
52 "\n",
53 argv [0]),
54 -1);
56 // Indicates successful parsing of the command line
57 return 0;
60 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
62 TAO_EC_Default_Factory::init_svcs ();
64 /// Move the test to the real-time class if it is possible.
65 RT_Class rt_class;
67 try
69 ORB_Holder orb (argc, argv, "");
71 if (parse_args (argc, argv) != 0)
72 return 1;
74 RTServer_Setup rtserver_setup (use_rt_corba,
75 orb,
76 rt_class,
77 nthreads);
79 PortableServer::POA_var root_poa =
80 RIR_Narrow<PortableServer::POA>::resolve (orb,
81 "RootPOA");
83 PortableServer::POAManager_var poa_manager =
84 root_poa->the_POAManager ();
86 poa_manager->activate ();
88 PortableServer::POA_var ec_poa (rtserver_setup.poa ());
90 ORB_Task orb_task (orb);
91 ORB_Task_Activator orb_task_activator (rt_class.priority_high (),
92 rt_class.thr_sched_class (),
93 nthreads,
94 &orb_task);
96 ACE_DEBUG ((LM_DEBUG, "Finished ORB and POA configuration\n"));
98 Servant_var<TAO_EC_Event_Channel> ec_impl (
99 RTEC_Initializer::create (ec_poa.in (),
100 ec_poa.in (),
101 rtserver_setup.rtcorba_setup ()));
103 ec_impl->activate ();
105 PortableServer::ObjectId_var ec_id =
106 ec_poa->activate_object (ec_impl.in ());
107 CORBA::Object_var ec_object =
108 ec_poa->id_to_reference (ec_id.in ());
110 RtecEventChannelAdmin::EventChannel_var ec =
111 RtecEventChannelAdmin::EventChannel::_narrow (ec_object.in ());
113 CORBA::String_var ior =
114 orb->object_to_string (ec.in ());
116 // Output the ior to the <ior_output_file>
117 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
118 if (output_file == 0)
119 ACE_ERROR_RETURN ((LM_ERROR,
120 "Cannot open output file for writing IOR: %s",
121 ior_output_file),
123 ACE_OS::fprintf (output_file, "%s", ior.in ());
124 ACE_OS::fclose (output_file);
126 do {
127 ACE_Time_Value tv (1, 0);
128 orb->run (tv);
129 } while (ec_impl->destroyed () == 0);
131 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
133 catch (const CORBA::Exception& ex)
135 ex._tao_print_exception ("Exception caught:");
136 return 1;
139 return 0;