1 #include "Counting_Consumer.h"
2 #include "Counting_Supplier.h"
4 #include "orbsvcs/Time_Utilities.h"
5 #include "orbsvcs/Event_Utilities.h"
6 #include "orbsvcs/Event/EC_Event_Channel.h"
7 #include "orbsvcs/Event/EC_Default_Factory.h"
10 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
12 TAO_EC_Default_Factory::init_svcs ();
16 // ORB initialization boiler plate...
18 CORBA::ORB_init (argc
, argv
);
20 CORBA::Object_var object
=
21 orb
->resolve_initial_references ("RootPOA");
22 PortableServer::POA_var poa
=
23 PortableServer::POA::_narrow (object
.in ());
24 PortableServer::POAManager_var poa_manager
=
25 poa
->the_POAManager ();
26 poa_manager
->activate ();
28 // ****************************************************************
30 TAO_EC_Event_Channel_Attributes
attributes (poa
.in (),
32 attributes
.consumer_reconnect
= 1;
33 attributes
.supplier_reconnect
= 1;
35 TAO_EC_Event_Channel
ec_impl (attributes
);
38 RtecEventChannelAdmin::EventChannel_var event_channel
=
42 // ****************************************************************
44 // Obtain the consumer admin..
45 RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin
=
46 event_channel
->for_consumers ();
48 // Obtain the supplier admin..
49 RtecEventChannelAdmin::SupplierAdmin_var supplier_admin
=
50 event_channel
->for_suppliers ();
52 // ****************************************************************
54 const int event_type
= 20;
55 const int event_source
= 10;
56 const int milliseconds
= 50;
58 EC_Counting_Supplier first_supplier
;
60 first_supplier
.activate (consumer_admin
.in (),
62 first_supplier
.connect (supplier_admin
.in (),
68 EC_Counting_Supplier second_supplier
;
70 second_supplier
.activate (consumer_admin
.in (),
72 second_supplier
.connect (supplier_admin
.in (),
78 EC_Counting_Supplier third_supplier
;
80 third_supplier
.activate (consumer_admin
.in (),
82 third_supplier
.connect (supplier_admin
.in (),
88 // ****************************************************************
90 EC_Counting_Consumer
regular_consumer ("Consumer/regular");
91 // Create a consumer, intialize its RT_Info structures, and
92 // connnect to the event channel....
96 ACE_ConsumerQOS_Factory consumer_qos
;
97 consumer_qos
.start_disjunction_group ();
98 consumer_qos
.insert (event_source
, event_type
, 0);
100 regular_consumer
.connect (consumer_admin
.in (),
101 consumer_qos
.get_ConsumerQOS ());
104 // ****************************************************************
106 EC_Counting_Consumer
negation_consumer ("Consumer/negation");
107 // Create a consumer, intialize its RT_Info structures, and
108 // connnect to the event channel....
111 ACE_ConsumerQOS_Factory consumer_qos
;
112 consumer_qos
.start_negation ();
113 consumer_qos
.start_disjunction_group ();
114 consumer_qos
.insert (event_source
, event_type
, 0);
116 negation_consumer
.connect (consumer_admin
.in (),
117 consumer_qos
.get_ConsumerQOS ());
120 // ****************************************************************
122 ACE_Time_Value
tv (5, 0);
123 // Wait for events, using work_pending()/perform_work() may help
124 // or using another thread, this example is too simple for that.
127 // ****************************************************************
129 negation_consumer
.disconnect ();
131 // ****************************************************************
133 regular_consumer
.disconnect ();
135 // ****************************************************************
137 third_supplier
.deactivate ();
138 third_supplier
.disconnect ();
139 second_supplier
.deactivate ();
140 second_supplier
.disconnect ();
141 first_supplier
.deactivate ();
142 first_supplier
.disconnect ();
144 // ****************************************************************
146 event_channel
->destroy ();
148 // ****************************************************************
152 // ****************************************************************
154 CORBA::ULong expected
=
155 third_supplier
.event_count
156 + second_supplier
.event_count
;
157 negation_consumer
.dump_results (expected
, 5);
159 first_supplier
.event_count
;
160 regular_consumer
.dump_results (expected
, 5);
164 catch (const CORBA::Exception
& ex
)
166 ex
._tao_print_exception ("Service");