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 "Low_Priority_Setup.h"
8 #include "EC_Destroyer.h"
9 #include "Auto_Disconnect.h"
11 #include "ORB_Task_Activator.h"
12 #include "Client_Group.h"
13 #include "Client_Options.h"
15 #include "orbsvcs/Event_Service_Constants.h"
17 #include "orbsvcs/Event/EC_Event_Channel.h"
18 #include "orbsvcs/Event/EC_Default_Factory.h"
20 #include "tao/PortableServer/PortableServer.h"
21 #include "tao/RTPortableServer/RTPortableServer.h"
22 #include "tao/Strategies/advanced_resource.h"
23 #include "tao/Messaging/Messaging.h"
24 #include "ace/Get_Opt.h"
25 #include "ace/High_Res_Timer.h"
26 #include "ace/Sample_History.h"
27 #include "ace/Basic_Stats.h"
28 #include "ace/Barrier.h"
31 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
33 const CORBA::Long experiment_id
= 1;
35 TAO_EC_Default_Factory::init_svcs ();
37 /// Move the test to the real-time class if it is possible.
42 ORB_Holder
orb (argc
, argv
, "");
44 Client_Options
options (argc
, argv
);
47 ACE_ERROR_RETURN ((LM_ERROR
,
49 "-i iterations (iterations) "
50 "-h high_priority_period (usecs) "
51 "-l low_priority_period (usecs) "
52 "-w high_priority_workload (usecs) "
53 "-v low_priority_workload (usecs) "
54 "-r (enable RT-CORBA) "
55 "-n nthreads (low priority thread) "
57 "-z (disable low priority) "
63 RTServer_Setup
rtserver_setup (options
.use_rt_corba
,
69 PortableServer::POA_var root_poa
=
70 RIR_Narrow
<PortableServer::POA
>::resolve (orb
,
73 PortableServer::POAManager_var poa_manager
=
74 root_poa
->the_POAManager ();
76 poa_manager
->activate ();
78 PortableServer::POA_var
ec_poa (rtserver_setup
.poa ());
80 ACE_Thread_Manager my_thread_manager
;
82 ORB_Task
orb_task (orb
);
83 orb_task
.thr_mgr (&my_thread_manager
);
84 ORB_Task_Activator
orb_task_activator (rt_class
.priority_high (),
85 rt_class
.thr_sched_class (),
89 ACE_DEBUG ((LM_DEBUG
, "Finished ORB and POA configuration\n"));
91 Servant_var
<TAO_EC_Event_Channel
> ec_impl (
92 RTEC_Initializer::create (ec_poa
.in (),
94 rtserver_setup
.rtcorba_setup ())
99 PortableServer::ObjectId_var ec_id
=
100 ec_poa
->activate_object (ec_impl
.in ());
101 CORBA::Object_var ec_object
=
102 ec_poa
->id_to_reference (ec_id
.in ());
104 RtecEventChannelAdmin::EventChannel_var ec
=
105 RtecEventChannelAdmin::EventChannel::_narrow (ec_object
.in ());
107 EC_Destroyer
ec_destroyer (ec
.in ());
109 ACE_DEBUG ((LM_DEBUG
, "Finished EC configuration and activation\n"));
111 int thread_count
= 1 + options
.nthreads
;
113 ACE_Barrier
the_barrier (thread_count
);
115 ACE_DEBUG ((LM_DEBUG
, "Calibrating high res timer ...."));
116 ACE_High_Res_Timer::calibrate ();
118 ACE_High_Res_Timer::global_scale_factor_type gsf
=
119 ACE_High_Res_Timer::global_scale_factor ();
120 ACE_DEBUG ((LM_DEBUG
, "Done (%d)\n", gsf
));
122 CORBA::Long event_range
= 1;
123 if (options
.funky_supplier_publication
)
125 if (options
.unique_low_priority_event
)
126 event_range
= 1 + options
.low_priority_consumers
;
131 Client_Group high_priority_group
;
132 high_priority_group
.init (experiment_id
,
133 ACE_ES_EVENT_UNDEFINED
,
136 options
.high_priority_workload
,
141 Auto_Disconnect
<Client_Group
> high_priority_disconnect
;
143 if (!options
.high_priority_is_last
)
145 high_priority_group
.connect (ec
.in ());
146 high_priority_disconnect
= &high_priority_group
;
149 int per_thread_period
= options
.low_priority_period
;
150 if (options
.global_low_priority_rate
)
151 per_thread_period
= options
.low_priority_period
* options
.nthreads
;
153 Low_Priority_Setup
<Client_Group
> low_priority_setup (
154 options
.low_priority_consumers
,
155 0, // no limit on the number of iterations
156 options
.unique_low_priority_event
,
158 ACE_ES_EVENT_UNDEFINED
+ 2,
159 options
.low_priority_workload
,
162 rt_class
.priority_low (),
163 rt_class
.thr_sched_class (),
170 if (options
.high_priority_is_last
)
172 high_priority_group
.connect (ec
.in ());
173 high_priority_disconnect
= &high_priority_group
;
175 Send_Task high_priority_task
;
176 high_priority_task
.init (options
.iterations
,
177 options
.high_priority_period
,
179 ACE_ES_EVENT_UNDEFINED
,
181 high_priority_group
.supplier (),
183 high_priority_task
.thr_mgr (&my_thread_manager
);
185 // Artificial scope to wait for the high priority task...
186 Task_Activator
<Send_Task
> high_priority_act (rt_class
.priority_high (),
187 rt_class
.thr_sched_class (),
189 &high_priority_task
);
192 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - high priority task completed\n"));
194 low_priority_setup
.stop_all_threads ();
196 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - low priority task(s) stopped\n"));
198 ACE_Sample_History
&history
=
199 high_priority_group
.consumer ()->sample_history ();
200 if (options
.dump_history
)
202 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
205 ACE_Basic_Stats high_priority_stats
;
206 history
.collect_basic_stats (high_priority_stats
);
207 high_priority_stats
.dump_results (ACE_TEXT("High Priority"), gsf
);
209 ACE_Basic_Stats low_priority_stats
;
210 low_priority_setup
.collect_basic_stats (low_priority_stats
);
211 low_priority_stats
.dump_results (ACE_TEXT("Low Priority"), gsf
);
213 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - starting cleanup\n"));
215 catch (const CORBA::Exception
& ex
)
217 ex
._tao_print_exception ("Exception caught:");