1 #include "Counting_Supplier.h"
2 #include "ace/OS_NS_unistd.h"
5 CEC_Counting_Supplier::CEC_Counting_Supplier ()
12 CEC_Counting_Supplier::connect (
13 CosEventChannelAdmin::SupplierAdmin_ptr supplier_admin
)
15 CosEventComm::PushSupplier_var supplier
=
18 if (CORBA::is_nil (this->consumer_proxy_
.in ()))
20 this->consumer_proxy_
=
21 supplier_admin
->obtain_push_consumer ();
24 this->consumer_proxy_
->connect_push_supplier (supplier
.in ());
28 CEC_Counting_Supplier::disconnect ()
30 if (!CORBA::is_nil (this->consumer_proxy_
.in ()))
32 this->consumer_proxy_
->disconnect_push_consumer ();
35 PortableServer::POA_var supplier_poa
=
36 this->_default_POA ();
37 PortableServer::ObjectId_var supplier_id
=
38 supplier_poa
->servant_to_id (this);
39 supplier_poa
->deactivate_object (supplier_id
.in ());
41 this->consumer_proxy_
=
42 CosEventChannelAdmin::ProxyPushConsumer::_nil ();
46 CEC_Counting_Supplier::push (const CORBA::Any
&)
48 if (CORBA::is_nil (this->consumer_proxy_
.in ()))
52 event
<<= CORBA::Long(0);
54 this->consumer_proxy_
->push (event
);
59 CEC_Counting_Supplier::disconnect_push_supplier ()
61 this->disconnect_count
++;
62 this->consumer_proxy_
=
63 CosEventChannelAdmin::ProxyPushConsumer::_nil ();
66 // ****************************************************************
68 CEC_Counting_Supplier_Task::
69 CEC_Counting_Supplier_Task (CEC_Counting_Supplier
*s
,
74 milliseconds_ (milliseconds
)
79 CEC_Counting_Supplier_Task::svc ()
85 catch (const CORBA::Exception
&)
93 CEC_Counting_Supplier_Task::stop ()
95 ACE_GUARD (TAO_SYNCH_MUTEX
, ace_mon
, this->lock_
);
100 CEC_Counting_Supplier_Task::push_count ()
102 return this->push_count_
;
106 CEC_Counting_Supplier_Task::run ()
109 event
<<= CORBA::Long(0);
113 this->supplier_
->push (event
);
115 if (this->milliseconds_
!= 0)
117 ACE_Time_Value
tv (0, 1000 * this->milliseconds_
);
122 // Sleep for a short time to avoid spinning... kind of klugy
126 ACE_GUARD (TAO_SYNCH_MUTEX
, ace_mon
, this->lock_
);
130 stop
= this->stop_flag_
;
134 // ****************************************************************
136 CEC_Pull_Counting_Supplier::CEC_Pull_Counting_Supplier ()
143 CEC_Pull_Counting_Supplier::connect (
144 CosEventChannelAdmin::SupplierAdmin_ptr supplier_admin
)
146 CosEventComm::PullSupplier_var supplier
=
149 if (CORBA::is_nil (this->consumer_proxy_
.in ()))
151 this->consumer_proxy_
=
152 supplier_admin
->obtain_pull_consumer ();
155 this->consumer_proxy_
->connect_pull_supplier (supplier
.in ());
159 CEC_Pull_Counting_Supplier::disconnect ()
161 if (!CORBA::is_nil (this->consumer_proxy_
.in ()))
163 this->consumer_proxy_
->disconnect_pull_consumer ();
166 PortableServer::POA_var supplier_poa
=
167 this->_default_POA ();
168 PortableServer::ObjectId_var supplier_id
=
169 supplier_poa
->servant_to_id (this);
170 supplier_poa
->deactivate_object (supplier_id
.in ());
172 this->consumer_proxy_
=
173 CosEventChannelAdmin::ProxyPullConsumer::_nil ();
177 CEC_Pull_Counting_Supplier::pull ()
179 if (CORBA::is_nil (this->consumer_proxy_
.in ()))
180 throw CosEventComm::Disconnected ();
182 if (this->event_count
% 2)
184 // Sleep for 1 second, to simulate blocking calls.
190 event
<<= CORBA::Long(0);
192 return new CORBA::Any (event
);
196 CEC_Pull_Counting_Supplier::try_pull (CORBA::Boolean_out has_event
)
198 if (CORBA::is_nil (this->consumer_proxy_
.in ()))
199 throw CosEventComm::Disconnected ();
201 if (this->event_count
% 2)
214 event
<<= CORBA::Long(0);
216 return new CORBA::Any (event
);
220 CEC_Pull_Counting_Supplier::disconnect_pull_supplier ()
222 this->disconnect_count
++;
223 this->consumer_proxy_
=
224 CosEventChannelAdmin::ProxyPullConsumer::_nil ();