Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Event / Basic / Negation.cpp
blobcede269c38a9e8e17d18445d1e8573eb09995978
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"
9 int
10 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
12 TAO_EC_Default_Factory::init_svcs ();
14 try
16 // ORB initialization boiler plate...
17 CORBA::ORB_var orb =
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 (),
31 poa.in ());
32 attributes.consumer_reconnect = 1;
33 attributes.supplier_reconnect = 1;
35 TAO_EC_Event_Channel ec_impl (attributes);
36 ec_impl.activate ();
38 RtecEventChannelAdmin::EventChannel_var event_channel =
39 ec_impl._this ();
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 (),
61 milliseconds);
62 first_supplier.connect (supplier_admin.in (),
63 event_source,
64 event_type,
65 event_source,
66 event_type);
68 EC_Counting_Supplier second_supplier;
70 second_supplier.activate (consumer_admin.in (),
71 milliseconds);
72 second_supplier.connect (supplier_admin.in (),
73 event_source,
74 event_type + 1,
75 event_source,
76 event_type + 1);
78 EC_Counting_Supplier third_supplier;
80 third_supplier.activate (consumer_admin.in (),
81 milliseconds);
82 third_supplier.connect (supplier_admin.in (),
83 event_source,
84 event_type + 1,
85 event_source,
86 event_type + 1);
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.
125 orb->run (tv);
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 // ****************************************************************
150 poa->destroy (1, 1);
152 // ****************************************************************
154 CORBA::ULong expected =
155 third_supplier.event_count
156 + second_supplier.event_count;
157 negation_consumer.dump_results (expected, 5);
158 expected =
159 first_supplier.event_count;
160 regular_consumer.dump_results (expected, 5);
162 orb->destroy ();
164 catch (const CORBA::Exception& ex)
166 ex._tao_print_exception ("Service");
167 return 1;
169 return 0;