diff options
author | msmit <msmit@remedy.nl> | 2009-11-25 16:22:21 +0000 |
---|---|---|
committer | msmit <msmit@remedy.nl> | 2009-11-25 16:22:21 +0000 |
commit | f56c2bf097c52c9b3b4baab8e580363025544747 (patch) | |
tree | db4ff1c667c4f5b446bdbfe039a2e970e9225a26 | |
parent | ee51c9ab499d6d0a4a95cf50043830322144eab8 (diff) | |
download | ATCD-f56c2bf097c52c9b3b4baab8e580363025544747.tar.gz |
Wed Nov 25 16:22:26 UTC 2009 Marcel Smit <msmit@remedy.nl>
* connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.h:
* connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.cpp:
* connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.h:
* connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp:
Using the orb reactor thread in order to handle application specific
logic.
* connectors/dds4ccm/tests/KeyedSamples/Sender/Keyed_Test_Sender_exec.cpp:
Optimized logging.
6 files changed, 43 insertions, 249 deletions
diff --git a/CIAO/ChangeLog b/CIAO/ChangeLog index fff7347a876..f18f9f50efc 100644 --- a/CIAO/ChangeLog +++ b/CIAO/ChangeLog @@ -1,3 +1,15 @@ +Wed Nov 25 16:22:26 UTC 2009 Marcel Smit <msmit@remedy.nl> + + * connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.h: + * connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.cpp: + * connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.h: + * connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp: + Using the orb reactor thread in order to handle application specific + logic. + + * connectors/dds4ccm/tests/KeyedSamples/Sender/Keyed_Test_Sender_exec.cpp: + Optimized logging. + Wed Nov 25 15:50:57 UTC 2009 Marcel Smit <msmit@remedy.nl> * connectors/dds4ccm/examples/Hello/Receiver/Hello_Receiver_exec.cpp: diff --git a/CIAO/connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.cpp b/CIAO/connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.cpp index af5dfb2a406..33fc38e82b1 100644 --- a/CIAO/connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.cpp +++ b/CIAO/connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.cpp @@ -6,16 +6,14 @@ #include "ace/Reactor.h" #include "ace/OS_NS_time.h" #include "ace/OS_NS_unistd.h" +#include "tao/ORB_Core.h" namespace CIAO_Quoter_Broker_Impl { read_action_Generator::read_action_Generator (Broker_exec_i &callback) - : active_ (0), - pulse_callback_ (callback) + : pulse_callback_ (callback) { - // initialize the reactor - this->reactor (ACE_Reactor::instance ()); } read_action_Generator::~read_action_Generator () @@ -23,84 +21,6 @@ namespace CIAO_Quoter_Broker_Impl } int - read_action_Generator::open_h () - { - // convert the task into a active object that runs in separate thread - return this->activate (); - } - - int - read_action_Generator::close_h () - { - this->reactor ()->end_reactor_event_loop (); - // wait for all threads in the task to exit before it returns - return this->wait (); - } - - int - read_action_Generator::start (CORBA::ULong hertz) - { - // return if not valid - if (hertz == 0 || this->active_ != 0) - { - return -1; - } - - // calculate the interval time - long usec = 1000 / hertz; - - std::cerr << "Starting read_action_generator with hertz of " << hertz << ", interval of " - << usec << std::endl; - - if (this->reactor ()->schedule_timer (this, - 0, - ACE_Time_Value(0), - ACE_Time_Value(3)) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "Unable to setup Timer\n"), - -1); - - } - - ACE_OS::sleep (2); - this->active_ = 1; - return 0; - } - - int - read_action_Generator::stop (void) - { - // return if not valid. - if (this->active_ == 0) - { - return -1; - } - // cancle the timer - this->reactor ()->cancel_timer (this); - this->active_ = 0; - return 0; - } - - int - read_action_Generator::active (void) - { - return this->active_; - } - - int - read_action_Generator::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("[%x] handle = %d, close_mask = %d\n"), - this, - handle, - close_mask)); - return 0; - } - - int read_action_Generator::handle_timeout (const ACE_Time_Value &, const void *) { @@ -112,18 +32,6 @@ namespace CIAO_Quoter_Broker_Impl return 0; } - int - read_action_Generator::svc (void) - { - // define the owner of the reactor thread - this->reactor ()->owner (ACE_OS::thr_self ()); - - // run event loop to wait for event, and then dispatch them to corresponding handlers - this->reactor ()->run_reactor_event_loop (); - - return 0; - } - void Broker_exec_i::read_one (void) { @@ -378,14 +286,23 @@ namespace CIAO_Quoter_Broker_Impl Broker_exec_i::start (void) { std::cerr << ">>> Broker_exec_i::start" << endl; - this->ticker_->start (500); + // calculate the interval time + if (this->context_->get_CCM_object()->_get_orb ()->orb_core ()->reactor ()->schedule_timer ( + this->ticker_, + 0, + ACE_Time_Value (0, 2000), + ACE_Time_Value (0, 2000)) == -1) + { + std::cerr << ">>> Broker_exec_i::start : error scheduling timer" << endl; + } } void Broker_exec_i::stop (void) { + this->context_->get_CCM_object()->_get_orb ()->orb_core ()->reactor ()->cancel_timer (this->ticker_); std::cerr << ">>> Broker_exec_i::stop" << endl; - this->ticker_->stop (); + delete this->ticker_; } void @@ -418,7 +335,6 @@ namespace CIAO_Quoter_Broker_Impl Broker_exec_i::ccm_remove (void) { std::cerr << ">>> Broker_exec_i::ccm_remove" << endl; - this->ticker_->close_h (); } extern "C" BROKER_EXEC_Export ::Components::EnterpriseComponent_ptr diff --git a/CIAO/connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.h b/CIAO/connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.h index 858ede4e984..75714128f5e 100644 --- a/CIAO/connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.h +++ b/CIAO/connectors/dds4ccm/examples/Quoter/Broker/Broker_exec.h @@ -43,7 +43,6 @@ #include /**/ "Broker_exec_export.h" #include "tao/LocalObject.h" -#include "ace/Task.h" #include "ace/Reactor.h" namespace CIAO_Quoter_Broker_Impl @@ -56,44 +55,18 @@ namespace CIAO_Quoter_Broker_Impl * @brief an active object used by StockBroker to perform a periodical read action * */ - class read_action_Generator : public ACE_Task_Base + class read_action_Generator : public ACE_Event_Handler { public: read_action_Generator (Broker_exec_i &callback); ~read_action_Generator (); - /// Hook method that performs application-defined initialization activities - int open_h (void); - - /// Hook method that performs application-defined destruction activites - int close_h (void); - - /// appliation-defined method for starting the pulse-generation service - int start (CORBA::ULong hertz); - - /// application-defined method for stopping the pulse-generation service - int stop (void); - - /// Indicate whether the current object is active - int active (void); - /// Handle the timeout. virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); - /// Called when timer handler is removed. - virtual int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); - - /// Hook methods implemnting the task's service processing, - /// invoked by all threads activated by activate () method - virtual int svc (void); - private: - /// Tracking whether we are actively generating pulse or not. - int active_; - /// Maintains a handle that actually process the event Broker_exec_i &pulse_callback_; }; diff --git a/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp b/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp index c310548dbc2..5598c673fd8 100644 --- a/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp +++ b/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.cpp @@ -7,6 +7,7 @@ #include "ace/Guard_T.h" #include "ace/CORBA_macros.h" #include "ace/OS_NS_time.h" +#include "tao/ORB_Core.h" #include <iostream> namespace CIAO_Quoter_Distributor_Impl @@ -16,11 +17,8 @@ namespace CIAO_Quoter_Distributor_Impl //============================================================ pulse_Generator::pulse_Generator (Distributor_exec_i &callback) - : active_ (0), - pulse_callback_ (callback) + : pulse_callback_ (callback) { - // initialize the reactor - this->reactor (ACE_Reactor::instance ()); } pulse_Generator::~pulse_Generator () @@ -28,83 +26,6 @@ namespace CIAO_Quoter_Distributor_Impl } int - pulse_Generator::open_h () - { - // convert the task into a active object that runs in separate thread - return this->activate (); - } - - int - pulse_Generator::close_h () - { - this->reactor ()->end_reactor_event_loop (); - - // wait for all threads in the task to exit before it returns - return this->wait (); - } - - int - pulse_Generator::start (CORBA::ULong hertz) - { - // return if not valid - if (hertz == 0 || this->active_ != 0) - { - return -1; - } - - // calculate the interval time - long usec = 1000000 / hertz; - - 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), - ACE_Time_Value (0, usec)) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "Unable to setup Timer\n"), - -1); - } - - this->active_ = 1; - return 0; - } - - int - pulse_Generator::stop (void) - { - // return if not valid. - if (this->active_ == 0) - { - return -1; - } - // cancle the timer - this->reactor ()->cancel_timer (this); - this->active_ = 0; - return 0; - } - - int - pulse_Generator::active (void) - { - return this->active_; - } - - int - pulse_Generator::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("[%x] handle = %d, close_mask = %d\n"), - this, - handle, - close_mask)); - return 0; - } - - int pulse_Generator::handle_timeout (const ACE_Time_Value &, const void *) { @@ -121,17 +42,7 @@ namespace CIAO_Quoter_Distributor_Impl return 0; } - int - pulse_Generator::svc (void) - { - // define the owner of the reactor thread - this->reactor ()->owner (ACE_OS::thr_self ()); - - // run event loop to wait for event, and then dispatch them to corresponding handlers - this->reactor ()->run_reactor_event_loop (); - return 0; - } ConnectorStatusListener_exec_i::ConnectorStatusListener_exec_i (void) { } @@ -288,13 +199,24 @@ namespace CIAO_Quoter_Distributor_Impl void Distributor_exec_i::start (void) { - this->ticker_->start (this->rate_); + // calculate the interval time + long usec = 1000000 / this->rate_; + if (this->context_->get_CCM_object()->_get_orb ()->orb_core ()->reactor ()->schedule_timer ( + this->ticker_, + 0, + ACE_Time_Value (0, usec), + ACE_Time_Value (0, usec)) == -1) + { + std::cerr << ">>> Distributor_exec_i::start : error scheduling timer" << endl; + } } void Distributor_exec_i::stop (void) { - this->ticker_->stop (); + this->context_->get_CCM_object()->_get_orb ()->orb_core ()->reactor ()->cancel_timer (this->ticker_); + std::cerr << ">>> Distributor_exec_i::stop" << endl; + delete this->ticker_; } // Component attributes. @@ -341,7 +263,6 @@ namespace CIAO_Quoter_Distributor_Impl Distributor_exec_i::configuration_complete (void) { this->writer_ = this->context_->get_connection_info_in_data (); - this->ticker_->activate (); } void diff --git a/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.h b/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.h index 7a7a541d11d..1ab67b20547 100644 --- a/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.h +++ b/CIAO/connectors/dds4ccm/examples/Quoter/Distributor/Distributor_exec.h @@ -16,7 +16,6 @@ #include /**/ "Distributor_exec_export.h" #include "tao/LocalObject.h" #include "ace/Thread_Mutex.h" -#include "ace/Task.h" #include "ace/Reactor.h" #include <map> @@ -31,44 +30,17 @@ namespace CIAO_Quoter_Distributor_Impl * @brief an active object used by StockDistributor to perform periodical pulse generation * */ - class pulse_Generator : public ACE_Task_Base + class pulse_Generator : public ACE_Event_Handler { public: pulse_Generator (Distributor_exec_i &callback); ~pulse_Generator (); - /// Hook method that performs application-defined initialization activities - int open_h (void); - - /// Hook method that performs application-defined destruction activites - int close_h (void); - - /// appliation-defined method for starting the pulse-generation service - int start (CORBA::ULong hertz); - - /// application-defined method for stopping the pulse-generation service - int stop (void); - - /// Indicate whether the current object is active - int active (void); - /// Handle the timeout. virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); - - /// Called when timer handler is removed. - virtual int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); - - /// Hook methods implemnting the task's service processing, - /// invoked by all threads activated by activate () method - virtual int svc (void); - private: - /// Tracking whether we are actively generating pulse or not. - int active_; - /// Maintains a handle that actually process the event Distributor_exec_i &pulse_callback_; diff --git a/CIAO/connectors/dds4ccm/tests/KeyedSamples/Sender/Keyed_Test_Sender_exec.cpp b/CIAO/connectors/dds4ccm/tests/KeyedSamples/Sender/Keyed_Test_Sender_exec.cpp index 0630ce5ab91..95ab5fe6a03 100644 --- a/CIAO/connectors/dds4ccm/tests/KeyedSamples/Sender/Keyed_Test_Sender_exec.cpp +++ b/CIAO/connectors/dds4ccm/tests/KeyedSamples/Sender/Keyed_Test_Sender_exec.cpp @@ -53,7 +53,7 @@ namespace CIAO_Keyed_Test_Sender_Impl { ++this->last_key->second->iteration; this->writer_->write_one (this->last_key->second, ::DDS::HANDLE_NIL); - CIAO_DEBUG ((LM_ERROR, ACE_TEXT ("Written key <%C> with <%d>\n"), + CIAO_DEBUG ((LM_DEBUG, ACE_TEXT ("Written key <%C> with <%d>\n"), this->last_key->first.c_str (), this->last_key->second->iteration)); } |