Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / docs / tutorials / Quoter / RT_Event_Service / Stock_i.cpp
blobfc37e33116346479ec9a826a2cae8a272d6aa16c
1 #include "Stock_i.h"
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_;
10 protected:
11 MyTieStock (Quoter_Stock_i *tp,
12 CORBA::Boolean release)
13 : POA_RtecEventComm::PushSupplier_tie<Quoter_Stock_i> (tp,release),
14 ref_count_(0) {}
16 public:
17 virtual void _add_ref ()
19 ++this->ref_count_;
22 virtual void _remove_ref ()
24 CORBA::ULong new_count = --this->ref_count_;
26 if (new_count == 0)
27 delete this;
31 Quoter_Stock_i::Quoter_Stock_i (const char *symbol,
32 const char *full_name,
33 CORBA::Double price)
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 ();
47 char *
48 Quoter_Stock_i::symbol ()
50 return CORBA::string_dup (this->data_.symbol.in ());
53 char *
54 Quoter_Stock_i::full_name ()
56 return CORBA::string_dup (this->data_.full_name.in ());
59 CORBA::Double
60 Quoter_Stock_i::price ()
62 return this->data_.price;
65 void
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 ()))
70 return;
72 // Create the event
73 RtecEventComm::EventSet event (1);
74 event.length (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]);
83 e.header.source = 1;
85 // Initialize the payload
86 e.data.any_value <<= this->data_;
88 // Push it
89 this->consumer_proxy_->push (event);
92 void
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 ();
100 void
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 ());