diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2009-10-08 14:37:51 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2009-10-08 14:37:51 +0000 |
commit | bf32d352bb837cf17e62b8f0df312b883781c941 (patch) | |
tree | 909889cf0bbc22295b9c1261f4a681a9b343a4c6 | |
parent | ee11dc553a4591362f5e1a5c3095f044a6878136 (diff) | |
download | ATCD-bf32d352bb837cf17e62b8f0df312b883781c941.tar.gz |
-rw-r--r-- | CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp b/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp index d396aeb6b09..e15652090c7 100644 --- a/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp +++ b/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp @@ -43,7 +43,7 @@ namespace CIAO_Quoter_Distributor_Impl //============================================================ // Component Executor Implementation Class: Distributor_exec_i //============================================================ - + pulse_Generator::pulse_Generator (Distributor_exec_i &callback) : active_ (0), pulse_callback_ (callback) @@ -80,13 +80,13 @@ namespace CIAO_Quoter_Distributor_Impl { return -1; } - + // calculate the interval time long usec = 1000000 / hertz; - std::cerr << "Starting pulse_generator with hertz of " << hertz << ", interval of " + std::cerr << "Starting pulse_generator with hertz of " << hertz << ", interval of " << usec << std::endl; - + if (this->reactor ()->schedule_timer (this, 0, ACE_Time_Value (0, usec), @@ -161,18 +161,18 @@ namespace CIAO_Quoter_Distributor_Impl ACE_OS::srand (static_cast <u_int> (ACE_OS::time ())); this->ticker_ = new pulse_Generator (*this); } - + Distributor_exec_i::~Distributor_exec_i (void) { } - + // Supported operations and attributes. - - void + + void Distributor_exec_i::tick (void) { std::cerr << "Ticking" << std::endl; - + for (Stock_Table::iterator i = this->stocks_.begin (); i != this->stocks_.end (); ++i) @@ -180,147 +180,147 @@ namespace CIAO_Quoter_Distributor_Impl if (ACE_OS::rand () % 2) { //std::cerr << "Updating stock: " << i->first.c_str () << std::endl; - - int delta = (ACE_OS::rand () % 10) - 5; - + + int delta = (ACE_OS::rand () % 10) - 2; + i->second->current += delta; - - if (i->second->current > i->second->high) + + if (i->second->current > i->second->high) i->second->high = i->second->current; - - if (i->second->current < i->second->low) + + if (i->second->current < i->second->low) i->second->low = i->second->current; - + if (!CORBA::is_nil (this->writer_)) this->writer_->write (i->second); else std::cerr << "Writer reference is nil!" << std::endl; - + } } } - + void Distributor_exec_i::add_stock ( const char * stock) { std::cerr << "Distributor_exec_i::add_stock - Adding stock: " << stock << std::endl; - + ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, _guard, this->mutex_, CORBA::INTERNAL ()); - + Quoter::Stock_Info *new_stock = new Quoter::Stock_Info; - + new_stock->low = 50; new_stock->high = 50; new_stock->current = 50; new_stock->symbol = stock; - + this->stocks_[stock] = new_stock; } - + void Distributor_exec_i::del_stock (const char * stock) { std::cerr << "Distributor_exec_i::del_stock - Removing stock: " << stock << std::endl; - - ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, _guard, + + ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, _guard, this->mutex_, CORBA::INTERNAL ()); - + Stock_Table::iterator pos = this->stocks_.find (stock); - + if (pos != this->stocks_.end ()) { this->stocks_.erase (pos); } - + std::cerr << "Distributor_exec_i::del_stock - Stock no present: " << stock; } - + void Distributor_exec_i::start (void) { this->ticker_->start (this->rate_); } - + void Distributor_exec_i::stop (void) { this->ticker_->stop (); } - + // Component attributes. - + ::CORBA::ULong Distributor_exec_i::rate (void) { return this->rate_; } - + void Distributor_exec_i::rate ( ::CORBA::ULong rate ) { this->rate_ = rate; } - + // Port operations. - + // Operations from Components::SessionComponent. - + void Distributor_exec_i::set_session_context ( ::Components::SessionContext_ptr ctx) { - ::Quoter::CCM_Distributor_Context_var lctx = + ::Quoter::CCM_Distributor_Context_var lctx = ::Quoter::CCM_Distributor_Context::_narrow (ctx); - + if ( ::CORBA::is_nil (lctx.in ())) { throw ::CORBA::INTERNAL (); } - + this->context_ = lctx; } - + void Distributor_exec_i::configuration_complete (void) { /* Your code here. */ this->writer_ = this->context_->get_connection_info_in_data (); - + this->ticker_->activate (); } - + void Distributor_exec_i::ccm_activate (void) { this->start (); this->add_stock ("MSFT"); } - + void Distributor_exec_i::ccm_passivate (void) { /* Your code here. */ } - + void Distributor_exec_i::ccm_remove (void) { /* Your code here. */ } - + extern "C" DISTRIBUTOR_EXEC_Export ::Components::EnterpriseComponent_ptr create_Quoter_Distributor_Impl (void) { ::Components::EnterpriseComponent_ptr retval = ::Components::EnterpriseComponent::_nil (); - + ACE_NEW_NORETURN ( retval, Distributor_exec_i); - + return retval; } } |