2 #include <orbsvcs/Event_Utilities.h>
4 ///derive a class from the tie template class to release itself by ref_count
5 class MyTieStock
:public POA_RtecEventComm::PushSupplier_tie
<Quoter_Stock_i
>
7 friend class Quoter_Stock_i
;
8 ACE_Atomic_Op
<TAO_SYNCH_MUTEX
, long> ref_count_
;
11 MyTieStock (Quoter_Stock_i
*tp
,
12 CORBA::Boolean release
)
13 : POA_RtecEventComm::PushSupplier_tie
<Quoter_Stock_i
> (tp
,release
),
17 virtual void _add_ref ()
22 virtual void _remove_ref ()
24 CORBA::ULong new_count
= --this->ref_count_
;
31 Quoter_Stock_i::Quoter_Stock_i (const char *symbol
,
32 const char *full_name
,
34 : supplier_personality_ (*new MyTieStock (this, 0))
36 this->data_
.symbol
= symbol
;
37 this->data_
.full_name
= full_name
;
38 this->data_
.price
= price
;
41 Quoter_Stock_i::~Quoter_Stock_i ()
43 if (consumer_proxy_
.in ())
44 consumer_proxy_
->disconnect_push_consumer ();
48 Quoter_Stock_i::symbol ()
50 return CORBA::string_dup (this->data_
.symbol
.in ());
54 Quoter_Stock_i::full_name ()
56 return CORBA::string_dup (this->data_
.full_name
.in ());
60 Quoter_Stock_i::price ()
62 return this->data_
.price
;
66 Quoter_Stock_i::set_price (CORBA::Double new_price
)
68 this->data_
.price
= new_price
;
69 if (CORBA::is_nil (this->consumer_proxy_
.in ()))
73 RtecEventComm::EventSet
event (1);
75 RtecEventComm::Event
&e
= event
[0];
77 // Initialize the header
78 const char *symbol
= this->data_
.symbol
;
79 e
.header
.type
= int(symbol
[0]) << 24;
80 e
.header
.type
|= int(symbol
[1]) << 16;
81 e
.header
.type
|= int(symbol
[2]) << 8;
82 e
.header
.type
|= int(symbol
[3]);
85 // Initialize the payload
86 e
.data
.any_value
<<= this->data_
;
89 this->consumer_proxy_
->push (event
);
93 Quoter_Stock_i::disconnect_push_supplier ()
95 // Forget about the consumer it is not there anymore
96 this->consumer_proxy_
=
97 RtecEventChannelAdmin::ProxyPushConsumer::_nil ();
101 Quoter_Stock_i::connect (RtecEventChannelAdmin::SupplierAdmin_ptr supplier_admin
)
103 this->consumer_proxy_
=
104 supplier_admin
->obtain_push_consumer ();
105 RtecEventComm::PushSupplier_var supplier
=
106 this->supplier_personality_
._this ();
108 const char *symbol
= this->data_
.symbol
;
109 CORBA::ULong type
= int(symbol
[0]) << 24;
110 type
|= int(symbol
[1]) << 16;
111 type
|= int(symbol
[2]) << 8;
112 type
|= int(symbol
[3]);
114 CORBA::ULong source
= 1;
115 ACE_SupplierQOS_Factory publications
;
116 publications
.insert (source
, type
, 0, 1);
118 this->consumer_proxy_
->connect_push_supplier (supplier
.in (),
119 publications
.get_SupplierQOS ());