From 88e12fc88923c83bb79cb1db4b1ee0d490abdf29 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Fri, 8 Jun 2012 13:04:51 +0000 Subject: Fri Jun 8 13:01:47 UTC 2012 Johnny Willemsen * connectors/dds4ccm/impl/ConditionManager.h: * connectors/dds4ccm/impl/ConditionManager.cpp: * connectors/dds4ccm/impl/Getter_T.cpp: Simplified the condition manager and getter by using the get_trigger_status call on the condition. The condition manager wait method now only returns true when one of the conditions has triggered, which means we don't have to check the conditions anymore in the getter * connectors/dds4ccm/impl/ndds/WaitSet.h: * connectors/dds4ccm/impl/ndds/WaitSet.cpp: Removed check_condition, this isn't a spec defined method but was only here for the condition manager --- CIAO/connectors/dds4ccm/impl/ConditionManager.cpp | 42 +-- CIAO/connectors/dds4ccm/impl/ConditionManager.h | 19 +- CIAO/connectors/dds4ccm/impl/Getter_T.cpp | 385 ++++++++++------------ CIAO/connectors/dds4ccm/impl/ndds/WaitSet.cpp | 16 - CIAO/connectors/dds4ccm/impl/ndds/WaitSet.h | 12 +- 5 files changed, 207 insertions(+), 267 deletions(-) (limited to 'CIAO/connectors/dds4ccm/impl') diff --git a/CIAO/connectors/dds4ccm/impl/ConditionManager.cpp b/CIAO/connectors/dds4ccm/impl/ConditionManager.cpp index 9b38c1d430d..b5bf96e647b 100644 --- a/CIAO/connectors/dds4ccm/impl/ConditionManager.cpp +++ b/CIAO/connectors/dds4ccm/impl/ConditionManager.cpp @@ -75,22 +75,6 @@ namespace CIAO return ret; } - bool - ConditionManager::check_condition ( - ::DDS::Condition_ptr condition) - { - DDS4CCM_TRACE ("CIAO::DDS4CCM::ConditionManager::check_condition"); - - ::DDS::ReadCondition_var rc = this->get_readcondition (); - ::DDS::QueryCondition_var qc = this->get_querycondition_getter (); - -#if (CIAO_DDS4CCM_NDDS==1) - return this->ws_.check_condition (rc.in (), qc.in (), condition); -#else - return (condition == rc.ptr () || condition == qc.ptr ()); -#endif - } - void ConditionManager::init_readcondition (void) { @@ -311,9 +295,7 @@ namespace CIAO } bool - ConditionManager::wait ( - ::DDS::ConditionSeq & active_conditions, - ::DDS::Duration_t & time_out) + ConditionManager::wait (const ::DDS::Duration_t & time_out) { DDS4CCM_TRACE ("CIAO::DDS4CCM::ConditionManager::wait"); @@ -321,6 +303,7 @@ namespace CIAO ACE_Time_Value const start = ACE_OS::gettimeofday (); #endif + DDS::ConditionSeq active_conditions; ::DDS::ReturnCode_t const retcode = this->ws_.wait (active_conditions, time_out); @@ -341,7 +324,26 @@ namespace CIAO ACE_TEXT ("No data available after timeout.\n"))); return false; } - return true; + + ::DDS::ReadCondition_var rc = this->get_readcondition (); + if (!CORBA::is_nil (rc.in ())) + { + if (rc->get_trigger_value() == true) + { + return true; + } + } + + ::DDS::QueryCondition_var qc = this->get_querycondition_getter (); + if (!CORBA::is_nil (qc.in ())) + { + if (qc->get_trigger_value() == true) + { + return true; + } + } + + return false; } void diff --git a/CIAO/connectors/dds4ccm/impl/ConditionManager.h b/CIAO/connectors/dds4ccm/impl/ConditionManager.h index 1a0215fb029..b584a5a0a04 100644 --- a/CIAO/connectors/dds4ccm/impl/ConditionManager.h +++ b/CIAO/connectors/dds4ccm/impl/ConditionManager.h @@ -66,13 +66,6 @@ namespace CIAO DDS_INSTANCE_HANDLE_T_IN instance_handle, DDS_INSTANCE_HANDLE_T_IN lookup_handle); - /** - * Proxy method. - * See WaitSet::check_condition in ndds/WaitSet.h - * for more information on this. - */ - bool check_condition (::DDS::Condition_ptr condition); - /** * Getter functionality. * Creates a read_condition for the getter. @@ -82,15 +75,11 @@ namespace CIAO void init_readcondition (void); /** - * Getter functionality - * waits for the attached conditions. If a condition is - * triggered, DDS has filled active_conditions with - * the triggered conditions. - * See WaitSet::wait in ndds/WaitSet.h for more - * information. + * Getter functionality, waits for the attached conditions. + * Only returns true when one of the getter conditions has triggered + * and we have data */ - bool wait (::DDS::ConditionSeq & active_conditions, - ::DDS::Duration_t & time_out); + bool wait (const ::DDS::Duration_t & time_out); /** * Returns the internal filter. This is the diff --git a/CIAO/connectors/dds4ccm/impl/Getter_T.cpp b/CIAO/connectors/dds4ccm/impl/Getter_T.cpp index 0ecb028b92f..a1b2e604ed0 100644 --- a/CIAO/connectors/dds4ccm/impl/Getter_T.cpp +++ b/CIAO/connectors/dds4ccm/impl/Getter_T.cpp @@ -125,8 +125,7 @@ namespace CIAO { DDS4CCM_TRACE ("Getter_Base_T::get_many"); - ::DDS::ConditionSeq active_conditions; - if (!this->condition_manager_->wait (active_conditions, this->time_out_)) + if (!this->condition_manager_->wait (this->time_out_)) { // Wait hasn't been triggered (no samples which match the attached // conditions are received). @@ -142,81 +141,74 @@ namespace CIAO ::DDS::SampleInfoSeq sample_info; SEQ_VALUE_TYPE data; - // Check which conditions have triggered the wait method to 'wake up'. - for (::CORBA::ULong i = 0; i < active_conditions.length(); i++) + ::DDS::ReturnCode_t const retcode = this->get (data, + sample_info, + max_samples); + + if (retcode == ::DDS::RETCODE_OK && data.length () >= 1) { - // Check whether this condition is the one we were waiting for. - if (this->condition_manager_->check_condition (active_conditions[i].in ())) + // Determine which samples are valid and return these to + // the caller. + ::CORBA::ULong number_read = 0; + for (::CORBA::ULong index = 0; index < sample_info.length (); index ++) { - ::DDS::ReturnCode_t const retcode = this->get (data, - sample_info, - max_samples); - - if (retcode == ::DDS::RETCODE_OK && data.length () >= 1) + if (sample_info[index].valid_data) { - // Determine which samples are valid and return these to - // the caller. - ::CORBA::ULong number_read = 0; - for (::CORBA::ULong index = 0; index < sample_info.length (); index ++) - { - if (sample_info[index].valid_data) - { - ++number_read; - } - } - DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, - ACE_TEXT ("Getter_Base_T::get_many: ") - ACE_TEXT ("read <%d> - valid <%d>\n"), - sample_info.length (), - number_read)); - infos.length (number_read); - instances.length (number_read); - number_read = 0; - for (::CORBA::ULong j = 0; j < data.length (); j ++) - { - if (sample_info[j].valid_data) - { - infos.operator[](number_read) <<= sample_info[j]; - instances.operator[](number_read) = data[j]; - ++number_read; - } - } + ++number_read; } - else + } + DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, + ACE_TEXT ("Getter_Base_T::get_many: ") + ACE_TEXT ("read <%d> - valid <%d>\n"), + sample_info.length (), + number_read)); + infos.length (number_read); + instances.length (number_read); + number_read = 0; + for (::CORBA::ULong j = 0; j < data.length (); j ++) + { + if (sample_info[j].valid_data) { - // RETCODE_NO_DATA should be an error - // because after a timeout there should be - // data. - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO - "Getter_Base_T::get_many - " - "Error while reading from DDS: <%C>\n", - translate_retcode (retcode))); - - ::DDS::ReturnCode_t const retval = - this->dds_reader ()->return_loan (data, sample_info); - if (retval != ::DDS::RETCODE_OK) - { - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO - "Getter_Base_T::get_many - " - "Error returning loan to DDS - <%C>\n", - translate_retcode (retval))); - } - throw ::CCM_DDS::InternalError (retcode, 1); + infos.operator[](number_read) <<= sample_info[j]; + instances.operator[](number_read) = data[j]; + ++number_read; } + } + } + else + { + // RETCODE_NO_DATA should be an error + // because after a timeout there should be + // data. + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_Base_T::get_many - " + "Error while reading from DDS: <%C>\n", + translate_retcode (retcode))); - ::DDS::ReturnCode_t const retval = - this->dds_reader ()->return_loan (data, sample_info); - if (retval != ::DDS::RETCODE_OK) - { - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO - "Getter_Base_T::get_many - " - "Error returning loan to DDS - <%C>\n", - translate_retcode (retval))); - - throw ::CCM_DDS::InternalError (retcode, 1); - } + ::DDS::ReturnCode_t const retval = + this->dds_reader ()->return_loan (data, sample_info); + if (retval != ::DDS::RETCODE_OK) + { + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_Base_T::get_many - " + "Error returning loan to DDS - <%C>\n", + translate_retcode (retval))); } + throw ::CCM_DDS::InternalError (retcode, 1); + } + + ::DDS::ReturnCode_t const retval = + this->dds_reader ()->return_loan (data, sample_info); + if (retval != ::DDS::RETCODE_OK) + { + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_Base_T::get_many - " + "Error returning loan to DDS - <%C>\n", + translate_retcode (retval))); + + throw ::CCM_DDS::InternalError (retcode, 1); } + return true; } @@ -291,8 +283,7 @@ namespace CIAO { DDS4CCM_TRACE ("Getter_T::get_one"); - ::DDS::ConditionSeq active_conditions; - if (!this->condition_manager_->wait (active_conditions, this->time_out_)) + if (!this->condition_manager_->wait (this->time_out_)) { // None of the attached conditions have triggered wait. return false; @@ -300,83 +291,75 @@ namespace CIAO bool valid_data_read = false; - // Check which conditions have triggered the wait method to 'wake up'. - for (::CORBA::ULong i = 0; i < active_conditions.length(); ++i) + // Read the samples one by one until a valid sample + // has been found. + while (!valid_data_read) { - // Check whether this condition is the one we were waiting for. - if (this->condition_manager_->check_condition (active_conditions[i].in ())) + ::DDS::SampleInfoSeq sample_info; + SEQ_VALUE_TYPE data; + + ::DDS::ReturnCode_t const retcode = this->get (data, + sample_info, + 1); + + if (retcode == ::DDS::RETCODE_NO_DATA) { - // Read the samples one by one until a valid sample - // has been found. - while (!valid_data_read) - { - ::DDS::SampleInfoSeq sample_info; - SEQ_VALUE_TYPE data; - - ::DDS::ReturnCode_t const retcode = this->get (data, - sample_info, - 1); - - if (retcode == ::DDS::RETCODE_NO_DATA) - { - DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO - "Getter_T::get_one - " - "DDS returned <%C>. No data available in DDS.\n", - translate_retcode (retcode))); - return false; - } - else if (retcode != ::DDS::RETCODE_OK) - { - // Something went wrong. - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO "Getter_T::get_one - " - "Error while reading from DDS: <%C>\n", + "DDS returned <%C>. No data available in DDS.\n", translate_retcode (retcode))); + return false; + } + else if (retcode != ::DDS::RETCODE_OK) + { + // Something went wrong. + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_T::get_one - " + "Error while reading from DDS: <%C>\n", + translate_retcode (retcode))); - ::DDS::ReturnCode_t const retval = - this->dds_reader ()->return_loan (data, sample_info); - if (retval != ::DDS::RETCODE_OK) - { - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO - "Getter_Base_T::get_one - " - "Error returning loan to DDS - <%C>\n", - translate_retcode (retval))); - } - - throw ::CCM_DDS::InternalError (retcode, 1); - } - else if (data.length () == 1 && sample_info[0].valid_data) - { - DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO - "Getter_T::get_one - " - "Read one valid sample from DDS.\n")); - - // Add the valid sample to the list which will be returned - // to the caller - info <<= sample_info[0]; - an_instance = data[0]; - valid_data_read = true; - } - else - { - DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO - "Getter_T::get_one - " - "No valid data available in DDS.\n")); - } - - // Return the loan of each read. - ::DDS::ReturnCode_t const retval = - this->dds_reader ()->return_loan (data, sample_info); - if (retval != ::DDS::RETCODE_OK) - { - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO - "Getter_T::get_one - " - "Error returning loan to DDS - <%C>\n", - translate_retcode (retval))); - - throw ::CCM_DDS::InternalError (retcode, 1); - } + ::DDS::ReturnCode_t const retval = + this->dds_reader ()->return_loan (data, sample_info); + if (retval != ::DDS::RETCODE_OK) + { + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_Base_T::get_one - " + "Error returning loan to DDS - <%C>\n", + translate_retcode (retval))); } + + throw ::CCM_DDS::InternalError (retcode, 1); + } + else if (data.length () == 1 && sample_info[0].valid_data) + { + DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO + "Getter_T::get_one - " + "Read one valid sample from DDS.\n")); + + // Add the valid sample to the list which will be returned + // to the caller + info <<= sample_info[0]; + an_instance = data[0]; + valid_data_read = true; + } + else + { + DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO + "Getter_T::get_one - " + "No valid data available in DDS.\n")); + } + + // Return the loan of each read. + ::DDS::ReturnCode_t const retval = + this->dds_reader ()->return_loan (data, sample_info); + if (retval != ::DDS::RETCODE_OK) + { + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_T::get_one - " + "Error returning loan to DDS - <%C>\n", + translate_retcode (retval))); + + throw ::CCM_DDS::InternalError (retcode, 1); } } @@ -395,8 +378,7 @@ namespace CIAO ACE_NEW_THROW_EX (an_instance, VALUE_TYPE, ::CORBA::NO_MEMORY ()); - ::DDS::ConditionSeq active_conditions; - if (!this->condition_manager_->wait (active_conditions, this->time_out_)) + if (!this->condition_manager_->wait (this->time_out_)) { // None of the attached conditions have triggered wait. return false; @@ -405,72 +387,65 @@ namespace CIAO bool valid_data_read = false; ::DDS::SampleInfoSeq sample_info; SEQ_VALUE_TYPE data; - // Check which conditions have triggered the wait method to 'wake up'. - for (::CORBA::ULong i = 0; i < active_conditions.length(); ++i) + + // Read the samples one by one until a valid sample + // has been found. + while (!valid_data_read) { - // Check whether this condition is the one we were waiting for. - if (this->condition_manager_->check_condition (active_conditions[i].in ())) + ::DDS::SampleInfoSeq sample_info; + SEQ_VALUE_TYPE data; + ::DDS::ReturnCode_t const retcode = this->get (data, + sample_info, + 1); + if (retcode == ::DDS::RETCODE_NO_DATA) { - // Read the samples one by one until a valid sample - // has been found. - while (!valid_data_read) - { - ::DDS::SampleInfoSeq sample_info; - SEQ_VALUE_TYPE data; - ::DDS::ReturnCode_t const retcode = this->get (data, - sample_info, - 1); - if (retcode == ::DDS::RETCODE_NO_DATA) - { - DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO - "Getter_T::get_one - " - "DDS returned <%C>. No data available in DDS.\n", - translate_retcode (retcode))); - return false; - } - else if (retcode != ::DDS::RETCODE_OK) - { - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO - "Getter_T::get_one - " - "Error while reading from DDS: <%C>\n", - translate_retcode (retcode))); + DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO + "Getter_T::get_one - " + "DDS returned <%C>. No data available in DDS.\n", + translate_retcode (retcode))); + return false; + } + else if (retcode != ::DDS::RETCODE_OK) + { + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_T::get_one - " + "Error while reading from DDS: <%C>\n", + translate_retcode (retcode))); - ::DDS::ReturnCode_t const retval = - this->dds_reader ()->return_loan (data, sample_info); - if (retval != ::DDS::RETCODE_OK) - { - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO - "Getter_T::get_one - " - "Error returning loan to DDS - <%C>\n", - translate_retcode (retval))); - } - throw ::CCM_DDS::InternalError (retcode, 1); - } - else if (data.length () == 1 && sample_info[0].valid_data) - { - // Add the valid sample to the list which will be returned - // to the caller - info <<= sample_info[0]; - *an_instance = data[0]; - valid_data_read = true; - } - else - { - DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO - "Getter_T::get_one - " - "No valid available in DDS.\n")); - } - // Return the loan of each read. - ::DDS::ReturnCode_t const retval = this->dds_reader ()->return_loan (data, sample_info); - if (retval != ::DDS::RETCODE_OK) - { - DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO - "Getter_T::get_one - " - "Error returning loan to DDS - <%C>\n", - translate_retcode (retval))); - throw ::CCM_DDS::InternalError (retval, 0); - } + ::DDS::ReturnCode_t const retval = + this->dds_reader ()->return_loan (data, sample_info); + if (retval != ::DDS::RETCODE_OK) + { + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_T::get_one - " + "Error returning loan to DDS - <%C>\n", + translate_retcode (retval))); } + throw ::CCM_DDS::InternalError (retcode, 1); + } + else if (data.length () == 1 && sample_info[0].valid_data) + { + // Add the valid sample to the list which will be returned + // to the caller + info <<= sample_info[0]; + *an_instance = data[0]; + valid_data_read = true; + } + else + { + DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO + "Getter_T::get_one - " + "No valid available in DDS.\n")); + } + // Return the loan of each read. + ::DDS::ReturnCode_t const retval = this->dds_reader ()->return_loan (data, sample_info); + if (retval != ::DDS::RETCODE_OK) + { + DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO + "Getter_T::get_one - " + "Error returning loan to DDS - <%C>\n", + translate_retcode (retval))); + throw ::CCM_DDS::InternalError (retval, 0); } } diff --git a/CIAO/connectors/dds4ccm/impl/ndds/WaitSet.cpp b/CIAO/connectors/dds4ccm/impl/ndds/WaitSet.cpp index 463ddcaefad..eefaa2444e5 100644 --- a/CIAO/connectors/dds4ccm/impl/ndds/WaitSet.cpp +++ b/CIAO/connectors/dds4ccm/impl/ndds/WaitSet.cpp @@ -162,22 +162,6 @@ namespace CIAO return ret; } - bool - DDS_WaitSet_i::check_condition ( - ::DDS::ReadCondition_ptr rc, - ::DDS::QueryCondition_ptr qc, - ::DDS::Condition_ptr condition) - { - DDS_ReadCondition_i * dds_rc = dynamic_cast (rc); - DDS_QueryCondition_i * dds_qc = dynamic_cast (qc); - - DDS_ReadCondition_i * rc_cond = dynamic_cast (condition); - DDS_QueryCondition_i * qc_cond = dynamic_cast (condition); - - return ((rc_cond && dds_rc && rc_cond->get_rti_entity () == dds_rc->get_rti_entity ()) || - (qc_cond && dds_qc && qc_cond->get_rti_entity () == dds_qc->get_rti_entity ()) ); - } - DDSWaitSet * DDS_WaitSet_i::get_rti_entity (void) { diff --git a/CIAO/connectors/dds4ccm/impl/ndds/WaitSet.h b/CIAO/connectors/dds4ccm/impl/ndds/WaitSet.h index 3dbc8f0d7d7..a2c88a0abdc 100644 --- a/CIAO/connectors/dds4ccm/impl/ndds/WaitSet.h +++ b/CIAO/connectors/dds4ccm/impl/ndds/WaitSet.h @@ -44,9 +44,7 @@ namespace CIAO * Waits for DDS until the attached read/query conditions are met * or when a timeout occurs. * - * active_conditions will contain conditions DDS has found. The - * caller should check whether the appropriate conditions for him - * has been set, using check_conditions + * active_conditions will contain conditions DDS has found. */ virtual ::DDS::ReturnCode_t wait (::DDS::ConditionSeq & active_conditions, @@ -102,14 +100,6 @@ namespace CIAO bool & error, bool & non_existent); - /** - * With this method, the caller is able to find out - * which conditions had triggered 'wait'. - */ - bool check_condition (::DDS::ReadCondition_ptr rc, - ::DDS::QueryCondition_ptr qc, - ::DDS::Condition_ptr condition); - /** * Creates the RTI waitset. */ -- cgit v1.2.1