Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14925] Add interfaces for ReadCondition #2778

Merged
merged 6 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions include/fastdds/dds/subscriber/DataReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,15 @@ 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.
*/
RTPS_DllAPI ReturnCode_t read_w_condition(
LoanableCollection& data_values,
SampleInfoSeq& sample_infos,
int32_t max_samples = LENGTH_UNLIMITED,
MiguelBarro marked this conversation as resolved.
Show resolved Hide resolved
ReadCondition* a_condition = nullptr);
int32_t max_samples,
ReadCondition* a_condition);

/**
* Access a collection of data samples from the DataReader.
Expand Down Expand Up @@ -478,16 +478,16 @@ 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.
*/
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,
MiguelBarro marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -570,15 +570,15 @@ 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.
*/
RTPS_DllAPI ReturnCode_t take_w_condition(
LoanableCollection& data_values,
SampleInfoSeq& sample_infos,
int32_t max_samples = LENGTH_UNLIMITED,
MiguelBarro marked this conversation as resolved.
Show resolved Hide resolved
ReadCondition* a_condition = nullptr);
int32_t max_samples,
ReadCondition* a_condition);

/**
* Access a collection of data samples from the DataReader.
Expand Down Expand Up @@ -682,16 +682,16 @@ 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.
*/
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,
MiguelBarro marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -989,31 +989,33 @@ 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(
const std::vector<SampleStateKind>& sample_states,
const std::vector<ViewStateKind>& view_states,
const std::vector<InstanceStateKind>& 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
* 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(
const std::vector<SampleStateKind>& sample_states,
const std::vector<ViewStateKind>& view_states,
const std::vector<InstanceStateKind>& instance_states,
SampleStateMask sample_states,
ViewStateMask view_states,
InstanceStateMask instance_states,
const std::string& query_expression,
const std::vector<std::string>& query_parameters);

Expand Down
122 changes: 122 additions & 0 deletions include/fastdds/dds/subscriber/ReadCondition.hpp
Original file line number Diff line number Diff line change
@@ -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 <fastdds/dds/core/condition/Condition.hpp>
#include <fastdds/dds/subscriber/InstanceState.hpp>
#include <fastdds/dds/subscriber/SampleState.hpp>
#include <fastdds/dds/subscriber/ViewState.hpp>
#include <fastrtps/fastrtps_dll.h>

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<detail::ReadConditionImpl> impl_;

};

} // namespace dds
} // namespace fastdds
} // namespace eprosima

#endif // _FASTDDS_DDS_SUBSCRIBER_READCONDITION_HPP_
1 change: 1 addition & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/cpp/fastdds/subscriber/DataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ ReturnCode_t DataReader::get_matched_publications(
}

ReadCondition* DataReader::create_readcondition(
const std::vector<SampleStateKind>& sample_states,
const std::vector<ViewStateKind>& view_states,
const std::vector<InstanceStateKind>& instance_states)
SampleStateMask sample_states,
ViewStateMask view_states,
InstanceStateMask instance_states)
{
logWarning(DATA_READER, "create_readcondition method not implemented");
static_cast<void> (sample_states);
Expand All @@ -395,9 +395,9 @@ ReadCondition* DataReader::create_readcondition(
}

QueryCondition* DataReader::create_querycondition(
const std::vector<SampleStateKind>& sample_states,
const std::vector<ViewStateKind>& view_states,
const std::vector<InstanceStateKind>& instance_states,
SampleStateMask sample_states,
ViewStateMask view_states,
InstanceStateMask instance_states,
const std::string& query_expression,
const std::vector<std::string>& query_parameters)
{
Expand Down
75 changes: 75 additions & 0 deletions src/cpp/fastdds/subscriber/ReadCondition.cpp
Original file line number Diff line number Diff line change
@@ -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 <fastdds/dds/subscriber/ReadCondition.hpp>
#include <fastdds/dds/subscriber/InstanceState.hpp>
#include <fastdds/dds/subscriber/SampleState.hpp>
#include <fastdds/dds/subscriber/ViewState.hpp>

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
6 changes: 3 additions & 3 deletions test/unittest/dds/participant/ParticipantTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SampleStateKind> mock_sample_state_kind;
const std::vector<ViewStateKind> mock_view_state_kind;
const std::vector<InstanceStateKind> 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<std::string> mock_query_parameters;

Expand Down
Loading