diff options
author | msmit <msmit@remedy.nl> | 2009-11-26 09:31:42 +0000 |
---|---|---|
committer | msmit <msmit@remedy.nl> | 2009-11-26 09:31:42 +0000 |
commit | 1943510ce6d9fdec716bfc20e2b024b36055e4f6 (patch) | |
tree | 6ed0a058bd60edd5aa9d0607f7a28376b0271b44 | |
parent | 05c63626ad6690f5a3b40fc080af7f7a5e97a717 (diff) | |
download | ATCD-1943510ce6d9fdec716bfc20e2b024b36055e4f6.tar.gz |
Thu Nov 26 09:28:25 UTC 2009 Marcel Smit <msmit@remedy.nl>
* examples/Hello/Receiver/Receiver.idl:
* examples/Hello/Receiver/Receiver_exec.h:
* examples/Hello/Receiver/Receiver_exec.cpp:
Reviced this example a bit. The receiver now uses the
orb reator thread to call the sender periodically. Therefore
the receiver is not blocked in the receiving CCM event method.
Also introduced a rate in the deployment plan; no hard coded
sleep of 200 seconds anymore.
* examples/Hello/Sender/Sender.idl:
* examples/Hello/Sender/Sender_exec.h:
* examples/Hello/Sender/Sender_exec.cpp:
Removed attribute Hertz since it was not used
* examples/Hello/descriptors/DeploymentPlan.cdp:
Introduced rate for the receiver (see above).
* examples/Hello/descriptors/run_test.pl:
Added a sleep of 60 seconds.
-rw-r--r-- | CIAO/ChangeLog | 22 | ||||
-rw-r--r-- | CIAO/examples/Hello/Receiver/Receiver.idl | 3 | ||||
-rw-r--r-- | CIAO/examples/Hello/Receiver/Receiver_exec.cpp | 87 | ||||
-rw-r--r-- | CIAO/examples/Hello/Receiver/Receiver_exec.h | 37 | ||||
-rw-r--r-- | CIAO/examples/Hello/Sender/Sender.idl | 2 | ||||
-rw-r--r-- | CIAO/examples/Hello/Sender/Sender_exec.cpp | 16 | ||||
-rw-r--r-- | CIAO/examples/Hello/Sender/Sender_exec.h | 9 | ||||
-rw-r--r-- | CIAO/examples/Hello/descriptors/DeploymentPlan.cdp | 11 | ||||
-rwxr-xr-x | CIAO/examples/Hello/descriptors/run_test.pl | 3 |
9 files changed, 148 insertions, 42 deletions
diff --git a/CIAO/ChangeLog b/CIAO/ChangeLog index 6920b178f43..1712c79ea89 100644 --- a/CIAO/ChangeLog +++ b/CIAO/ChangeLog @@ -1,3 +1,25 @@ +Thu Nov 26 09:28:25 UTC 2009 Marcel Smit <msmit@remedy.nl> + + * examples/Hello/Receiver/Receiver.idl: + * examples/Hello/Receiver/Receiver_exec.h: + * examples/Hello/Receiver/Receiver_exec.cpp: + Reviced this example a bit. The receiver now uses the + orb reator thread to call the sender periodically. Therefore + the receiver is not blocked in the receiving CCM event method. + Also introduced a rate in the deployment plan; no hard coded + sleep of 200 seconds anymore. + + * examples/Hello/Sender/Sender.idl: + * examples/Hello/Sender/Sender_exec.h: + * examples/Hello/Sender/Sender_exec.cpp: + Removed attribute Hertz since it was not used + + * examples/Hello/descriptors/DeploymentPlan.cdp: + Introduced rate for the receiver (see above). + + * examples/Hello/descriptors/run_test.pl: + Added a sleep of 60 seconds. + Thu Nov 26 08:09:39 UTC 2009 Marcel Smit <msmit@remedy.nl> * connectors/dds4ccm/examples/Hello/Receiver/Hello_Receiver_exec.cpp: diff --git a/CIAO/examples/Hello/Receiver/Receiver.idl b/CIAO/examples/Hello/Receiver/Receiver.idl index f64c3be26db..c66b02e9cd4 100644 --- a/CIAO/examples/Hello/Receiver/Receiver.idl +++ b/CIAO/examples/Hello/Receiver/Receiver.idl @@ -11,8 +11,9 @@ module Hello { uses ReadMessage read_message; consumes TimeOut click_in; - + attribute short iterations; + attribute short rate; }; home ReceiverHome manages Receiver diff --git a/CIAO/examples/Hello/Receiver/Receiver_exec.cpp b/CIAO/examples/Hello/Receiver/Receiver_exec.cpp index 588ac8ecf84..0e0aeaebb6c 100644 --- a/CIAO/examples/Hello/Receiver/Receiver_exec.cpp +++ b/CIAO/examples/Hello/Receiver/Receiver_exec.cpp @@ -4,11 +4,33 @@ #include "ace/High_Res_Timer.h" #include "ace/Date_Time.h" #include "ace/OS_NS_unistd.h" +#include "tao/ORB_Core.h" namespace CIAO_Hello_Receiver_Impl { + read_action_Generator::read_action_Generator (Receiver_exec_i &callback) + : pulse_callback_ (callback) + { + } + + read_action_Generator::~read_action_Generator () + { + } + + int + read_action_Generator::handle_timeout (const ACE_Time_Value &, const void *) + { + this->pulse_callback_.tick (); + return 0; + } + + Receiver_exec_i::Receiver_exec_i () + : iterations_ (10), + iteration_ (0), + rate_ (1) { + this->ticker_ = new read_action_Generator (*this); } Receiver_exec_i::~Receiver_exec_i () @@ -27,24 +49,25 @@ namespace CIAO_Hello_Receiver_Impl return this->iterations_; } - void - Receiver_exec_i::push_click_in (::Hello::TimeOut * ev) + Receiver_exec_i::rate (CORBA::Short rate) { - //Get the message from the Sender first. - ACE_DEBUG ((LM_DEBUG, - "Receiver - Informed by the Sender with message [%C]\n", - ev->data ())); - - Hello::ReadMessage_var rev - = this->context_->get_connection_read_message(); + this->rate_ = rate; + } - if (CORBA::is_nil (rev.in ())) - throw CORBA::BAD_INV_ORDER (); + CORBA::Short + Receiver_exec_i::rate () + { + return this->rate_; + } - for (CORBA::Short i = 0; i < this->iterations_; ++i) + void + Receiver_exec_i::tick () + { + if (this->iteration_ < this->iterations_) { - CORBA::String_var str = rev->get_message (); + ++this->iteration_; + CORBA::String_var str = this->rev_->get_message (); ACE_hrtime_t now = ACE_OS::gethrtime(); ACE_CString tm_rec (str.in ()); ACE_hrtime_t received = ACE_OS::strtoull (tm_rec.substr(0, 15).c_str(), 0, 0); @@ -54,19 +77,42 @@ namespace CIAO_Hello_Receiver_Impl ACE_High_Res_Timer::hrtime_to_tv (tv, now - received); ACE_DEBUG ((LM_DEBUG, - "Receiver - Got message from the server [%C]. difference <%d>\n", + "Receiver - Got message from the sender [%C] - timing difference <%d>\n", str.in (), tv.usec ())); } else { ACE_DEBUG ((LM_DEBUG, - "Receiver - Got message from the server [%C].\n", + "Receiver - Got message from the sender [%C].\n", str.in ())); } - ACE_Time_Value tv(0, 200000000); - ACE_OS::sleep (tv); } } + + void + Receiver_exec_i::push_click_in (::Hello::TimeOut * ev) + { + //Get the message from the Sender first. + ACE_DEBUG ((LM_DEBUG, + "Receiver - Informed by the Sender with message [%C]\n", + ev->data ())); + // scheduling a timer, using the orb reactor thread, using the + // read_action_Generator as it's callback + // that way, one don't have to create it's own thread (although allowed) + // and CCM isn't blocked in this method. + + // 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) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Receiver_exec_i::start : ") + ACE_TEXT ("Error scheduling timer"))); + } + } // Operations from Components::SessionComponen void @@ -94,6 +140,11 @@ namespace CIAO_Hello_Receiver_Impl Receiver_exec_i::ccm_activate () { ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::ccm_activate\n")); + // get the connection to the sender, providing the + // read_message interface + this->rev_ = this->context_->get_connection_read_message(); + if (CORBA::is_nil (this->rev_.in ())) + throw CORBA::BAD_INV_ORDER (); } void @@ -106,6 +157,8 @@ namespace CIAO_Hello_Receiver_Impl Receiver_exec_i::ccm_remove () { ACE_DEBUG ((LM_DEBUG, "Receiver_exec_i::ccm_remove\n")); + this->context_->get_CCM_object()->_get_orb ()->orb_core ()->reactor ()->cancel_timer (this->ticker_); + delete this->ticker_; } diff --git a/CIAO/examples/Hello/Receiver/Receiver_exec.h b/CIAO/examples/Hello/Receiver/Receiver_exec.h index 0d64ea1c537..54257e2f9da 100644 --- a/CIAO/examples/Hello/Receiver/Receiver_exec.h +++ b/CIAO/examples/Hello/Receiver/Receiver_exec.h @@ -13,9 +13,34 @@ #include "Receiver_exec_export.h" #include "tao/LocalObject.h" +#include "ace/Reactor.h" namespace CIAO_Hello_Receiver_Impl { + class Receiver_exec_i; + /** + * @class reader activity generator + * + * @brief an active object used by Receiver to perform a periodical read action + * + */ + class read_action_Generator + : public ACE_Event_Handler + { + public: + read_action_Generator (Receiver_exec_i &callback); + + ~read_action_Generator (); + + /// Handle the timeout. + virtual int handle_timeout (const ACE_Time_Value &tv, + const void *arg); + + private: + /// Maintains a handle that actually process the event + Receiver_exec_i &pulse_callback_; + + }; /** * @class Receiver_exec_i * @@ -39,10 +64,18 @@ namespace CIAO_Hello_Receiver_Impl /// Operation to get the value of the attribute "iterations" virtual CORBA::Short iterations (); + /// Operation to set the value of the attribute "rate" + virtual void rate (CORBA::Short rate); + + /// Operation to get the value of the attribute "rate" + virtual CORBA::Short rate (); + // Operation which will be called upon receiving the timeout event. virtual void push_click_in (::Hello::TimeOut *ev); + void tick (); + // Operations from Components::SessionComponent virtual void set_session_context (::Components::SessionContext_ptr ctx); @@ -59,6 +92,10 @@ namespace CIAO_Hello_Receiver_Impl private: CORBA::String_var message_; CORBA::Short iterations_; + CORBA::Short iteration_; + CORBA::Short rate_; + read_action_Generator *ticker_; + Hello::ReadMessage_var rev_; }; /** diff --git a/CIAO/examples/Hello/Sender/Sender.idl b/CIAO/examples/Hello/Sender/Sender.idl index eb5f30f5581..e8e4f88ba57 100644 --- a/CIAO/examples/Hello/Sender/Sender.idl +++ b/CIAO/examples/Hello/Sender/Sender.idl @@ -30,8 +30,8 @@ module Hello { provides ReadMessage push_message; publishes TimeOut click_out; + attribute string local_message; - readonly attribute long hertz; attribute boolean log_time; // A test attribute to test setting attributes through XML attribute COLOR_SELECTION color; diff --git a/CIAO/examples/Hello/Sender/Sender_exec.cpp b/CIAO/examples/Hello/Sender/Sender_exec.cpp index 2282184d71e..2eca26d27c7 100644 --- a/CIAO/examples/Hello/Sender/Sender_exec.cpp +++ b/CIAO/examples/Hello/Sender/Sender_exec.cpp @@ -27,11 +27,12 @@ namespace CIAO_Hello_Sender_Impl strcpy(message, tm.in ()); strcat(message, " "); strcat(message, this->component_.message_.in ()); + ACE_DEBUG ((LM_EMERGENCY, "Sender returning message: [%C]\n", component_.message_.in ())); return CORBA::string_dup(message); } else { - ACE_DEBUG ((LM_EMERGENCY, "Sender sending out message: [%C]\n", component_.message_.in ())); + ACE_DEBUG ((LM_EMERGENCY, "Sender returning message: [%C]\n", component_.message_.in ())); return CORBA::string_dup (message); } } @@ -64,19 +65,6 @@ namespace CIAO_Hello_Sender_Impl return log_time_; } - void - Sender_exec_i::hertz (CORBA::Long hertz) - { - this->hertz_ = hertz; - ACE_DEBUG ((LM_EMERGENCY, "Sender_exec_i::Hertz:%d\n", this->hertz_)); - } - - CORBA::Long - Sender_exec_i::hertz () - { - return this->hertz_; - } - ::Hello::COLOR_SELECTION Sender_exec_i::color () { diff --git a/CIAO/examples/Hello/Sender/Sender_exec.h b/CIAO/examples/Hello/Sender/Sender_exec.h index 585463f974e..c2ee31084c0 100644 --- a/CIAO/examples/Hello/Sender/Sender_exec.h +++ b/CIAO/examples/Hello/Sender/Sender_exec.h @@ -56,13 +56,6 @@ namespace CIAO_Hello_Sender_Impl /// Operation to get the value of the attribute "log_time" virtual bool log_time (); - - /// Operation to set the value of the attribute "hertz" - virtual void hertz (CORBA::Long hertz); - - /// Operation to get the value of the attribute "hertz" - virtual CORBA::Long hertz (); - /* Operations for obtaining the interface reference. */ /* This method will be used in the assembly face so the * ObjRef of this read_message facet will be sent to the @@ -101,8 +94,6 @@ namespace CIAO_Hello_Sender_Impl CORBA::Boolean log_time_; - CORBA::Long hertz_; - ::Hello::COLOR_SELECTION color_; friend class Message_Impl; diff --git a/CIAO/examples/Hello/descriptors/DeploymentPlan.cdp b/CIAO/examples/Hello/descriptors/DeploymentPlan.cdp index b1ba4709c16..8f59456f3ee 100644 --- a/CIAO/examples/Hello/descriptors/DeploymentPlan.cdp +++ b/CIAO/examples/Hello/descriptors/DeploymentPlan.cdp @@ -197,6 +197,17 @@ </value> </configProperty> <configProperty> + <name>rate</name> + <value> + <type> + <kind>tk_short</kind> + </type> + <value> + <short>1</short> + </value> + </value> + </configProperty> + <configProperty> <name>edu.vanderbilt.dre.DAnCE.RegisterNaming</name> <value> <type> diff --git a/CIAO/examples/Hello/descriptors/run_test.pl b/CIAO/examples/Hello/descriptors/run_test.pl index a34d57731eb..d1995530566 100755 --- a/CIAO/examples/Hello/descriptors/run_test.pl +++ b/CIAO/examples/Hello/descriptors/run_test.pl @@ -187,6 +187,9 @@ if ($result != 0) { $status = 1; } +print "Let the application run for 60 seconds\n"; +sleep (60); + # Invoke executor - stop the application -. print "Invoking executor - stop the application -\n"; print "by running dance_plan_launcher.exe with -k file://EM.ior -x DeploymentPlan.cdp -q\n"; |