From b2b8ffc67582a0b830b3fac486d93fa4727a1906 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 10 Jun 2022 11:10:46 +0200 Subject: [PATCH 1/6] Refs #14925. Use state masks instead of vector. Signed-off-by: Miguel Company --- include/fastdds/dds/subscriber/DataReader.hpp | 12 ++++++------ src/cpp/fastdds/subscriber/DataReader.cpp | 12 ++++++------ test/unittest/dds/subscriber/DataReaderTests.cpp | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/fastdds/dds/subscriber/DataReader.hpp b/include/fastdds/dds/subscriber/DataReader.hpp index 65bfca8a9a2..ce5e1004257 100644 --- a/include/fastdds/dds/subscriber/DataReader.hpp +++ b/include/fastdds/dds/subscriber/DataReader.hpp @@ -995,9 +995,9 @@ class DataReader : public DomainEntity * @return ReadCondition pointer */ RTPS_DllAPI ReadCondition* create_readcondition( - const std::vector& sample_states, - const std::vector& view_states, - const std::vector& instance_states); + SampleStateMask sample_states, + ViewStateMask view_states, + InstanceStateMask instance_states); /** * @brief This operation creates a QueryCondition. The returned QueryCondition will be attached and belong to the @@ -1011,9 +1011,9 @@ class DataReader : public DomainEntity * @return QueryCondition pointer */ RTPS_DllAPI QueryCondition* create_querycondition( - const std::vector& sample_states, - const std::vector& view_states, - const std::vector& instance_states, + SampleStateMask sample_states, + ViewStateMask view_states, + InstanceStateMask instance_states, const std::string& query_expression, const std::vector& query_parameters); diff --git a/src/cpp/fastdds/subscriber/DataReader.cpp b/src/cpp/fastdds/subscriber/DataReader.cpp index 7fb7fe5e142..2bdaa331100 100644 --- a/src/cpp/fastdds/subscriber/DataReader.cpp +++ b/src/cpp/fastdds/subscriber/DataReader.cpp @@ -380,9 +380,9 @@ ReturnCode_t DataReader::get_matched_publications( } ReadCondition* DataReader::create_readcondition( - const std::vector& sample_states, - const std::vector& view_states, - const std::vector& instance_states) + SampleStateMask sample_states, + ViewStateMask view_states, + InstanceStateMask instance_states) { logWarning(DATA_READER, "create_readcondition method not implemented"); static_cast (sample_states); @@ -395,9 +395,9 @@ ReadCondition* DataReader::create_readcondition( } QueryCondition* DataReader::create_querycondition( - const std::vector& sample_states, - const std::vector& view_states, - const std::vector& instance_states, + SampleStateMask sample_states, + ViewStateMask view_states, + InstanceStateMask instance_states, const std::string& query_expression, const std::vector& query_parameters) { diff --git a/test/unittest/dds/subscriber/DataReaderTests.cpp b/test/unittest/dds/subscriber/DataReaderTests.cpp index 0a0956a50b6..9063cc46594 100644 --- a/test/unittest/dds/subscriber/DataReaderTests.cpp +++ b/test/unittest/dds/subscriber/DataReaderTests.cpp @@ -2348,18 +2348,18 @@ TEST_F(DataReaderUnsupportedTests, UnsupportedDataReaderMethods) data_reader->get_matched_publication_data(publication_data, publication_handle)); { - std::vector sample_states; - std::vector view_states; - std::vector instance_states; + SampleStateMask sample_states = ANY_SAMPLE_STATE; + ViewStateMask view_states = ANY_VIEW_STATE; + InstanceStateMask instance_states = ANY_INSTANCE_STATE; EXPECT_EQ( nullptr, data_reader->create_readcondition(sample_states, view_states, instance_states)); } { - std::vector sample_states; - std::vector view_states; - std::vector instance_states; + SampleStateMask sample_states = ANY_SAMPLE_STATE; + ViewStateMask view_states = ANY_VIEW_STATE; + InstanceStateMask instance_states = ANY_INSTANCE_STATE; std::string query_expression; std::vector query_parameters; EXPECT_EQ( From 9e069b3befee2cc2a870f08cfa4d92f48072729e Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 24 Jun 2022 09:20:47 +0200 Subject: [PATCH 2/6] Refs #14925. Improve doxydoc. Signed-off-by: Miguel Company --- include/fastdds/dds/subscriber/DataReader.hpp | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/include/fastdds/dds/subscriber/DataReader.hpp b/include/fastdds/dds/subscriber/DataReader.hpp index ce5e1004257..36e15641ee6 100644 --- a/include/fastdds/dds/subscriber/DataReader.hpp +++ b/include/fastdds/dds/subscriber/DataReader.hpp @@ -333,7 +333,7 @@ class DataReader : public DomainEntity * @param[in,out] data_values A LoanableCollection object where the received data samples will be returned. * @param[in,out] sample_infos A SampleInfoSeq object where the received sample info will be returned. * @param[in] max_samples The maximum number of samples to be returned. - * @param[in] a_condition A ReadCondition that returned @c sample_states must pass + * @param[in] a_condition A ReadCondition that returned @c data_values must pass * * @return Any of the standard return codes. */ @@ -478,7 +478,7 @@ class DataReader : public DomainEntity * available, up to the limits described in the documentation for @ref read(). * @param[in] previous_handle The 'next smallest' instance with a value greater than this value that has * available samples will be returned. - * @param[in] a_condition A ReadCondition that returned @c sample_states must pass + * @param[in] a_condition A ReadCondition that returned @c data_values must pass * * @return Any of the standard return codes. */ @@ -570,7 +570,7 @@ class DataReader : public DomainEntity * @param[in,out] sample_infos A SampleInfoSeq object where the received sample info will be returned. * @param[in] max_samples The maximum number of samples to be returned. If the special value * @ref LENGTH_UNLIMITED is provided, as many samples will be returned as are. - * @param[in] a_condition A ReadCondition that returned @c sample_states must pass + * @param[in] a_condition A ReadCondition that returned @c data_values must pass * * @return Any of the standard return codes. */ @@ -682,7 +682,7 @@ class DataReader : public DomainEntity * available, up to the limits described in the documentation for @ref read(). * @param[in] previous_handle The 'next smallest' instance with a value greater than this value that has * available samples will be returned. - * @param[in] a_condition A ReadCondition that returned @c sample_states must pass + * @param[in] a_condition A ReadCondition that returned @c data_values must pass * * @return Any of the standard return codes. */ @@ -989,10 +989,11 @@ class DataReader : public DomainEntity * @brief This operation creates a ReadCondition. The returned ReadCondition will be attached and belong to the * DataReader. * - * @param sample_states Vector of SampleStateKind - * @param view_states Vector of ViewStateKind - * @param instance_states Vector of InstanceStateKind - * @return ReadCondition pointer + * @param [in] sample_states Only data samples with @c sample_state matching one of these will trigger the created condition. + * @param [in] view_states Only data samples with @c view_state matching one of these will trigger the created condition. + * @param [in] instance_states Only data samples with @c instance_state matching one of these will trigger the created condition. + * + * @return pointer to the created ReadCondition, nullptr in case of error. */ RTPS_DllAPI ReadCondition* create_readcondition( SampleStateMask sample_states, @@ -1003,12 +1004,13 @@ class DataReader : public DomainEntity * @brief This operation creates a QueryCondition. The returned QueryCondition will be attached and belong to the * DataReader. * - * @param sample_states Vector of SampleStateKind - * @param view_states Vector of ViewStateKind - * @param instance_states Vector of InstanceStateKind - * @param query_expression string containing query - * @param query_parameters Vector of strings containing parameters of query expression - * @return QueryCondition pointer + * @param [in] sample_states Only data samples with @c sample_state matching one of these will trigger the created condition. + * @param [in] view_states Only data samples with @c view_state matching one of these will trigger the created condition. + * @param [in] instance_states Only data samples with @c instance_state matching one of these will trigger the created condition. + * @param [in] query_expression Only data samples matching this query will trigger the created condition. + * @param [in] query_parameters Value of the parameters on the query expression. + * + * @return pointer to the created QueryCondition, nullptr in case of error. */ RTPS_DllAPI QueryCondition* create_querycondition( SampleStateMask sample_states, From 3f5678cc1b8b0482d481d5bba97eedfdf67c2ab7 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 24 Jun 2022 10:43:36 +0200 Subject: [PATCH 3/6] Refs #14925. Added class declaration for ReadCondition. Signed-off-by: Miguel Company --- .../fastdds/dds/subscriber/ReadCondition.hpp | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 include/fastdds/dds/subscriber/ReadCondition.hpp diff --git a/include/fastdds/dds/subscriber/ReadCondition.hpp b/include/fastdds/dds/subscriber/ReadCondition.hpp new file mode 100644 index 00000000000..b25d7083f81 --- /dev/null +++ b/include/fastdds/dds/subscriber/ReadCondition.hpp @@ -0,0 +1,122 @@ +// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file ReadCondition.hpp + */ + +#ifndef _FASTDDS_DDS_SUBSCRIBER_READCONDITION_HPP_ +#define _FASTDDS_DDS_SUBSCRIBER_READCONDITION_HPP_ + +#include +#include +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +namespace detail { + +struct ReadConditionImpl; + +} // namespace detail + +class DataReader; + +/** + * @brief A Condition specifically dedicated to read operations and attached to one DataReader. + * + * ReadCondition objects allow an application to specify the data samples it is interested in (by specifying the + * desired sample_states, view_states, and instance_states). + * The condition will only be triggered when suitable information is available. + * They are to be used in conjunction with a WaitSet as normal conditions. + * More than one ReadCondition may be attached to the same DataReader. + */ +class ReadCondition : public Condition +{ +public: + + explicit ReadCondition( + DataReader* parent); + + ~ReadCondition() override; + + // Non-copyable + ReadCondition( + const ReadCondition&) = delete; + ReadCondition& operator =( + const ReadCondition&) = delete; + + // Non-movable + ReadCondition( + ReadCondition&&) = delete; + ReadCondition& operator =( + ReadCondition&&) = delete; + + /** + * @brief Retrieves the trigger_value of the Condition + * @return true if trigger_value is set to 'true', 'false' otherwise + */ + RTPS_DllAPI bool get_trigger_value() const override; + + /** + * @brief Retrieves the DataReader associated with the ReadCondition. + * + * Note that there is exactly one DataReader associated with each ReadCondition. + * + * @return pointer to the DataReader associated with this ReadCondition. + */ + RTPS_DllAPI DataReader* get_datareader() const; + + /** + * @brief Retrieves the set of sample_states taken into account to determine the trigger_value of this condition. + * + * @return the sample_states specified when the ReadCondition was created. + */ + RTPS_DllAPI SampleStateMask get_sample_state_mask() const; + + /** + * @brief Retrieves the set of view_states taken into account to determine the trigger_value of this condition. + * + * @return the view_states specified when the ReadCondition was created. + */ + RTPS_DllAPI ViewStateMask get_view_state_mask() const; + + /** + * @brief Retrieves the set of instance_states taken into account to determine the trigger_value of this condition. + * + * @return the instance_states specified when the ReadCondition was created. + */ + RTPS_DllAPI InstanceStateMask get_instance_state_mask() const; + + detail::ReadConditionImpl* get_impl() const + { + return impl_.get(); + } + +protected: + + //! Class implementation + std::unique_ptr impl_; + +}; + +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_DDS_SUBSCRIBER_READCONDITION_HPP_ From 60c01102d0f6adc042b7faa1ae73bc524dffafde Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 24 Jun 2022 10:44:08 +0200 Subject: [PATCH 4/6] Refs #14925. Added dummy definition for ReadCondition. Signed-off-by: Miguel Company --- src/cpp/CMakeLists.txt | 1 + src/cpp/fastdds/subscriber/ReadCondition.cpp | 75 ++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/cpp/fastdds/subscriber/ReadCondition.cpp diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 15694b57db2..95806f41860 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -109,6 +109,7 @@ set(${PROJECT_NAME}_source_files fastdds/subscriber/Subscriber.cpp fastdds/subscriber/DataReader.cpp fastdds/subscriber/DataReaderImpl.cpp + fastdds/subscriber/ReadCondition.cpp fastdds/subscriber/history/DataReaderHistory.cpp fastdds/domain/DomainParticipantFactory.cpp fastdds/domain/DomainParticipantImpl.cpp diff --git a/src/cpp/fastdds/subscriber/ReadCondition.cpp b/src/cpp/fastdds/subscriber/ReadCondition.cpp new file mode 100644 index 00000000000..ea992576f52 --- /dev/null +++ b/src/cpp/fastdds/subscriber/ReadCondition.cpp @@ -0,0 +1,75 @@ +// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file ReadCondition.cpp + */ + +#include +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +namespace detail { + +struct ReadConditionImpl +{ +}; + +} // namespace detail + + +ReadCondition::ReadCondition( + DataReader* /*parent*/) + : Condition() + , impl_(new detail::ReadConditionImpl()) +{ +} + +ReadCondition::~ReadCondition() +{ +} + +bool ReadCondition::get_trigger_value() const +{ + return false; +} + +DataReader* ReadCondition::get_datareader() const +{ + return nullptr; +} + +SampleStateMask ReadCondition::get_sample_state_mask() const +{ + return ANY_SAMPLE_STATE; +} + +ViewStateMask ReadCondition::get_view_state_mask() const +{ + return ANY_VIEW_STATE; +} + +InstanceStateMask ReadCondition::get_instance_state_mask() const +{ + return ANY_INSTANCE_STATE; +} + +} // namespace dds +} // namespace fastdds +} // namespace eprosima From 940be63ccc7c4580b5ab073e5a7b00987466cb8b Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 24 Jun 2022 11:12:57 +0200 Subject: [PATCH 5/6] Refs #14925. Fixed tests. Signed-off-by: Miguel Company --- test/unittest/dds/participant/ParticipantTests.cpp | 6 +++--- test/unittest/dds/subscriber/DataReaderTests.cpp | 6 +++--- test/unittest/dds/subscriber/SubscriberTests.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index 92c05ae3c4d..042482b3487 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -3048,9 +3048,9 @@ TEST(ParticipantTests, DeleteContainedEntities) DataWriter* data_writer_foo = publisher->create_datawriter(topic_foo, DATAWRITER_QOS_DEFAULT); ASSERT_NE(data_writer_foo, nullptr); - const std::vector mock_sample_state_kind; - const std::vector mock_view_state_kind; - const std::vector mock_instance_states; + SampleStateMask mock_sample_state_kind = ANY_SAMPLE_STATE; + ViewStateMask mock_view_state_kind = ANY_VIEW_STATE; + InstanceStateMask mock_instance_states = ANY_INSTANCE_STATE; const std::string mock_query_expression; const std::vector mock_query_parameters; diff --git a/test/unittest/dds/subscriber/DataReaderTests.cpp b/test/unittest/dds/subscriber/DataReaderTests.cpp index 9063cc46594..64024a7a6a3 100644 --- a/test/unittest/dds/subscriber/DataReaderTests.cpp +++ b/test/unittest/dds/subscriber/DataReaderTests.cpp @@ -2551,9 +2551,9 @@ TEST_F(DataReaderTests, delete_contained_entities) DataReader* data_reader = subscriber->create_datareader(topic, DATAREADER_QOS_DEFAULT); ASSERT_NE(data_reader, nullptr); - const std::vector mock_sample_state_kind; - const std::vector mock_view_state_kind; - const std::vector mock_instance_states; + SampleStateMask mock_sample_state_kind = ANY_SAMPLE_STATE; + ViewStateMask mock_view_state_kind = ANY_VIEW_STATE; + InstanceStateMask mock_instance_states = ANY_INSTANCE_STATE; const std::string mock_query_expression; const std::vector mock_query_parameters; diff --git a/test/unittest/dds/subscriber/SubscriberTests.cpp b/test/unittest/dds/subscriber/SubscriberTests.cpp index 73bd20d76cb..bd3d6d0cc6c 100644 --- a/test/unittest/dds/subscriber/SubscriberTests.cpp +++ b/test/unittest/dds/subscriber/SubscriberTests.cpp @@ -952,9 +952,9 @@ TEST(SubscriberTests, DeleteContainedEntities) ASSERT_EQ(data_reader_foo->return_loan(mock_coll, mock_seq), ReturnCode_t::RETCODE_OK); - const std::vector mock_sample_state_kind; - const std::vector mock_view_state_kind; - const std::vector mock_instance_states; + SampleStateMask mock_sample_state_kind = ANY_SAMPLE_STATE; + ViewStateMask mock_view_state_kind = ANY_VIEW_STATE; + InstanceStateMask mock_instance_states = ANY_INSTANCE_STATE; const std::string mock_query_expression; const std::vector mock_query_parameters; From 77612b42b7198c49e8f562d056c3b6fb8a5957d5 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 29 Jun 2022 17:00:46 +0200 Subject: [PATCH 6/6] Removed default argument values Signed-off-by: Miguel Company --- include/fastdds/dds/subscriber/DataReader.hpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/fastdds/dds/subscriber/DataReader.hpp b/include/fastdds/dds/subscriber/DataReader.hpp index 36e15641ee6..d27297945b9 100644 --- a/include/fastdds/dds/subscriber/DataReader.hpp +++ b/include/fastdds/dds/subscriber/DataReader.hpp @@ -340,8 +340,8 @@ class DataReader : public DomainEntity RTPS_DllAPI ReturnCode_t read_w_condition( LoanableCollection& data_values, SampleInfoSeq& sample_infos, - int32_t max_samples = LENGTH_UNLIMITED, - ReadCondition* a_condition = nullptr); + int32_t max_samples, + ReadCondition* a_condition); /** * Access a collection of data samples from the DataReader. @@ -485,9 +485,9 @@ class DataReader : public DomainEntity RTPS_DllAPI ReturnCode_t read_next_instance_w_condition( LoanableCollection& data_values, SampleInfoSeq& sample_infos, - int32_t max_samples = LENGTH_UNLIMITED, - const InstanceHandle_t& previous_handle = HANDLE_NIL, - ReadCondition* a_condition = nullptr); + int32_t max_samples, + const InstanceHandle_t& previous_handle, + ReadCondition* a_condition); /** * @brief This operation copies the next, non-previously accessed Data value from the DataReader; the operation @@ -577,8 +577,8 @@ class DataReader : public DomainEntity RTPS_DllAPI ReturnCode_t take_w_condition( LoanableCollection& data_values, SampleInfoSeq& sample_infos, - int32_t max_samples = LENGTH_UNLIMITED, - ReadCondition* a_condition = nullptr); + int32_t max_samples, + ReadCondition* a_condition); /** * Access a collection of data samples from the DataReader. @@ -689,9 +689,9 @@ class DataReader : public DomainEntity RTPS_DllAPI ReturnCode_t take_next_instance_w_condition( LoanableCollection& data_values, SampleInfoSeq& sample_infos, - int32_t max_samples = LENGTH_UNLIMITED, - const InstanceHandle_t& previous_handle = HANDLE_NIL, - ReadCondition* a_condition = nullptr); + int32_t max_samples, + const InstanceHandle_t& previous_handle, + ReadCondition* a_condition); /** * @brief This operation copies the next, non-previously accessed Data value from the DataReader and ‘removes’ it