1 #include "Counting_Consumer.h"
2 #include "Counting_Supplier.h"
3 #include "orbsvcs/CosEvent/CEC_EventChannel.h"
4 #include "orbsvcs/CosEvent/CEC_Default_Factory.h"
5 #include "ace/OS_NS_unistd.h"
8 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
10 TAO_CEC_Default_Factory::init_svcs ();
14 // ORB initialization boiler plate...
16 CORBA::ORB_init (argc
, argv
);
18 CORBA::Object_var object
=
19 orb
->resolve_initial_references ("RootPOA");
20 PortableServer::POA_var poa
=
21 PortableServer::POA::_narrow (object
.in ());
22 PortableServer::POAManager_var poa_manager
=
23 poa
->the_POAManager ();
24 poa_manager
->activate ();
26 // ****************************************************************
28 TAO_CEC_EventChannel_Attributes
attributes (poa
.in (),
31 TAO_CEC_EventChannel
ec_impl (attributes
);
34 CosEventChannelAdmin::EventChannel_var event_channel
=
37 // ****************************************************************
39 // Obtain the consumer admin..
40 CosEventChannelAdmin::ConsumerAdmin_var consumer_admin
=
41 event_channel
->for_consumers ();
43 // Obtain the supplier admin..
44 CosEventChannelAdmin::SupplierAdmin_var supplier_admin
=
45 event_channel
->for_suppliers ();
47 // ****************************************************************
49 const int milliseconds
= 50;
51 CEC_Counting_Supplier supplier_00
;
53 supplier_00
.connect (supplier_admin
.in ());
55 // ****************************************************************
57 CEC_Counting_Supplier supplier_01
;
59 supplier_01
.connect (supplier_admin
.in ());
61 // ****************************************************************
63 CEC_Pull_Counting_Supplier supplier_10
;
65 supplier_10
.connect (supplier_admin
.in ());
67 // ****************************************************************
69 CEC_Pull_Counting_Supplier supplier_11
;
71 supplier_11
.connect (supplier_admin
.in ());
73 // ****************************************************************
75 // Create a consumer, intialize its RT_Info structures, and
76 // connnect to the event channel....
77 CEC_Counting_Consumer
consumer_00 ("Consumer/00");
78 consumer_00
.connect (consumer_admin
.in ());
80 // ****************************************************************
82 CEC_Pull_Counting_Consumer
consumer_01 ("Consumer/01");
83 consumer_01
.connect (consumer_admin
.in ());
85 // ****************************************************************
87 CEC_Pull_Counting_Consumer
consumer_10 ("Consumer/10");
88 consumer_10
.connect (consumer_admin
.in ());
90 // ****************************************************************
92 CEC_Counting_Supplier_Task
task_00 (&supplier_00
,
94 CEC_Counting_Supplier_Task
task_01 (&supplier_01
,
97 if (task_00
.activate (THR_BOUND
|THR_NEW_LWP
, 1) != 0)
99 ACE_ERROR ((LM_ERROR
, "Cannot activate task 00\n"));
101 if (task_01
.activate (THR_BOUND
|THR_NEW_LWP
, 1) != 0)
103 ACE_ERROR ((LM_ERROR
, "Cannot activate task 01\n"));
106 // ****************************************************************
108 CEC_Counting_Consumer_Task
consumer_task_01 (&consumer_01
,
110 if (consumer_task_01
.activate (THR_BOUND
|THR_NEW_LWP
, 1) != 0)
112 ACE_ERROR ((LM_ERROR
, "Cannot activate task 01\n"));
115 // ****************************************************************
117 CEC_Counting_Consumer_Task
consumer_task_10 (&consumer_10
,
119 if (consumer_task_10
.activate (THR_BOUND
|THR_NEW_LWP
, 1) != 0)
121 ACE_ERROR ((LM_ERROR
, "Cannot activate task 10\n"));
124 // ****************************************************************
126 ACE_Time_Value
tv (15, 0);
132 ACE_DEBUG ((LM_DEBUG
,
133 "Events pulled (so far) by Consumer/01 = %d\n",
134 consumer_task_01
.pull_count ()));
136 tv
= ACE_Time_Value (5, 0);
139 consumer_task_10
.stop ();
140 consumer_task_01
.stop ();
142 // Wait for all the threads to complete and the return
143 ACE_Thread_Manager::instance ()->wait ();
145 // ****************************************************************
147 consumer_10
.disconnect ();
149 consumer_01
.disconnect ();
151 consumer_00
.disconnect ();
153 supplier_11
.disconnect ();
154 supplier_10
.disconnect ();
155 supplier_01
.disconnect ();
156 supplier_00
.disconnect ();
158 // ****************************************************************
160 event_channel
->destroy ();
162 // ****************************************************************
164 poa
->destroy (true, true);
168 // ****************************************************************
170 CORBA::ULong expected
=
171 task_00
.push_count ()
172 + task_01
.push_count ()
173 + supplier_10
.event_count
174 + supplier_11
.event_count
;
176 consumer_00
.dump_results (expected
, 5);
179 consumer_task_01
.pull_count ();
180 consumer_01
.dump_results (expected
, 5);
182 consumer_task_10
.pull_count ();
183 consumer_10
.dump_results (expected
, 5);
185 catch (const CORBA::Exception
& ex
)
187 ex
._tao_print_exception ("Service");