Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / CosEvent / Basic / Disconnect.cpp
blob7be8a6b6ed06575f93a800829f6de255bb144215
1 #include "Counting_Supplier.h"
2 #include "Counting_Consumer.h"
4 #include "orbsvcs/Time_Utilities.h"
5 #include "orbsvcs/CosEvent/CEC_EventChannel.h"
6 #include "orbsvcs/CosEvent/CEC_Default_Factory.h"
8 static void run_test (PortableServer::POA_ptr poa,
9 int use_callbacks);
11 int
12 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
14 TAO_CEC_Default_Factory::init_svcs ();
16 try
18 // ORB initialization boiler plate...
19 CORBA::ORB_var orb =
20 CORBA::ORB_init (argc, argv);
22 CORBA::Object_var object =
23 orb->resolve_initial_references ("RootPOA");
24 PortableServer::POA_var poa =
25 PortableServer::POA::_narrow (object.in ());
26 PortableServer::POAManager_var poa_manager =
27 poa->the_POAManager ();
28 poa_manager->activate ();
30 // ****************************************************************
32 run_test (poa.in (), 0);
34 run_test (poa.in (), 1);
36 // ****************************************************************
38 poa->destroy (true, true);
40 orb->destroy ();
42 catch (const CORBA::Exception& ex)
44 ex._tao_print_exception ("Service");
45 return 1;
47 return 0;
50 // ****************************************************************
52 void
53 deactivate_servant (PortableServer::Servant servant)
55 PortableServer::POA_var poa =
56 servant->_default_POA ();
57 PortableServer::ObjectId_var id =
58 poa->servant_to_id (servant);
59 poa->deactivate_object (id.in ());
62 void
63 run_test (PortableServer::POA_ptr poa,
64 int use_callbacks)
66 TAO_CEC_EventChannel_Attributes attributes (poa, poa);
67 attributes.disconnect_callbacks = use_callbacks;
69 TAO_CEC_EventChannel ec_impl (attributes);
70 ec_impl.activate ();
72 CosEventChannelAdmin::EventChannel_var event_channel =
73 ec_impl._this ();
75 // ****************************************************************
77 // Obtain the consumer admin..
78 CosEventChannelAdmin::ConsumerAdmin_var consumer_admin =
79 event_channel->for_consumers ();
81 // and the supplier admin..
82 CosEventChannelAdmin::SupplierAdmin_var supplier_admin =
83 event_channel->for_suppliers ();
85 // ****************************************************************
87 int iterations = 100;
89 CEC_Counting_Supplier supplier_0;
90 CEC_Counting_Supplier supplier_1;
91 CEC_Counting_Consumer consumer_0 ("Consumer/0");
92 CEC_Counting_Consumer consumer_1 ("Consumer/1");
94 for (int i = 0; i != iterations; ++i)
96 supplier_0.connect (supplier_admin.in ());
97 consumer_0.connect (consumer_admin.in ());
98 if (i % 2 == 1)
100 supplier_1.connect (supplier_admin.in ());
101 consumer_1.connect (consumer_admin.in ());
103 supplier_0.disconnect ();
104 consumer_0.disconnect ();
105 if (i % 2 == 1)
107 consumer_1.disconnect ();
108 supplier_1.disconnect ();
112 supplier_0.connect (supplier_admin.in ());
113 consumer_0.connect (consumer_admin.in ());
115 event_channel->destroy ();
117 deactivate_servant (&supplier_0);
119 deactivate_servant (&consumer_0);
121 deactivate_servant (&ec_impl);
123 CORBA::ULong count_0 = 1;
124 CORBA::ULong count_1 = 0;
125 if (use_callbacks)
127 count_0 += iterations;
128 count_1 += iterations / 2;
131 if (consumer_0.disconnect_count != count_0)
132 ACE_ERROR ((LM_ERROR,
133 "ERROR: incorrect number of disconnect calls (%d/%d) for "
134 "consumer 0 (%d)\n",
135 consumer_0.disconnect_count, count_0,
136 use_callbacks));
137 if (supplier_0.disconnect_count != count_0)
138 ACE_ERROR ((LM_ERROR,
139 "ERROR: incorrect number of disconnect calls (%d/%d) for "
140 "supplier 0 (%d)\n",
141 supplier_0.disconnect_count, count_0,
142 use_callbacks));
144 if (consumer_1.disconnect_count != count_1)
145 ACE_ERROR ((LM_ERROR,
146 "ERROR: incorrect number of disconnect calls (%d/%d) for "
147 "consumer 1 (%d)\n",
148 consumer_1.disconnect_count, count_1,
149 use_callbacks));
150 if (supplier_1.disconnect_count != count_1)
151 ACE_ERROR ((LM_ERROR,
152 "ERROR: incorrect number of disconnect calls (%d/%d) for "
153 "supplier 1 (%d)\n",
154 supplier_1.disconnect_count, count_1,
155 use_callbacks));