Skip to content

[23169] Add WireProtocolConfigQos to optionals serialization and make Monitor Service always serialize optionals #5812

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

Closed
wants to merge 12 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ constexpr uint16_t DEFAULT_ROS2_SERVER_PORT = 11811;
constexpr uint16_t DEFAULT_TCP_SERVER_PORT = 42100;

//! Filtering flags when discovering participants
FASTDDS_TODO_BEFORE(4, 0, "Change it to uint8_t (implies also changing [de]serializations)");
enum ParticipantFilteringFlags : uint32_t
{
NO_FILTER = 0,
Expand Down
8 changes: 4 additions & 4 deletions src/cpp/fastdds/core/policy/ParameterSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ inline bool ParameterSerializer<ParameterLocator_t>::add_content_to_cdr_message(
const ParameterLocator_t& parameter,
rtps::CDRMessage_t* cdr_message)
{
return rtps::CDRMessage::addLocator(cdr_message, parameter.locator);
return rtps::CDRMessage::add_locator(cdr_message, parameter.locator);
}

template<>
Expand All @@ -256,7 +256,7 @@ inline bool ParameterSerializer<ParameterLocator_t>::read_content_from_cdr_messa
return false;
}
parameter.length = parameter_length;
return rtps::CDRMessage::readLocator(cdr_message, &parameter.locator);
return rtps::CDRMessage::read_locator(cdr_message, &parameter.locator);
}

template<>
Expand Down Expand Up @@ -324,7 +324,7 @@ inline bool ParameterSerializer<ParameterString_t>::read_content_from_cdr_messag

parameter.length = parameter_length;
fastcdr::string_255 aux;
bool valid = rtps::CDRMessage::readString(cdr_message, &aux);
bool valid = rtps::CDRMessage::read_string(cdr_message, &aux);
parameter.setName(aux.c_str());
return valid;
}
Expand Down Expand Up @@ -963,7 +963,7 @@ class ParameterSerializer<rtps::ContentFilterProperty>
}
if (valid)
{
valid = rtps::CDRMessage::readString(cdr_message, &parameter.filter_expression) &&
valid = rtps::CDRMessage::read_string(cdr_message, &parameter.filter_expression) &&
(0 < parameter.filter_expression.size());
}

Expand Down
447 changes: 440 additions & 7 deletions src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp

Large diffs are not rendered by default.

45 changes: 43 additions & 2 deletions src/cpp/rtps/builtin/data/ParticipantProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ ParticipantProxyData::ParticipantProxyData(
, m_writers(nullptr)
, m_sample_identity(pdata.m_sample_identity)
, lease_duration_(pdata.lease_duration_)
, m_should_send_optional_qos(pdata.m_should_send_optional_qos)
{
}

Expand Down Expand Up @@ -138,7 +139,8 @@ ParticipantProxyData::~ParticipantProxyData()
}

uint32_t ParticipantProxyData::get_serialized_size(
bool include_encapsulation) const
bool include_encapsulation,
bool force_including_optional_qos) const
{
uint32_t ret_val = include_encapsulation ? 4 : 0;

Expand Down Expand Up @@ -239,13 +241,23 @@ uint32_t ParticipantProxyData::get_serialized_size(
}
#endif // if HAVE_SECURITY

if (force_including_optional_qos || should_send_optional_qos())
{
// No need for QosPoliciesSerializer::should_be_sent since it is always different from the default.
// For instance, the locator lists.

// PID_WIREPROTOCOL_CONFIG
ret_val += fastdds::dds::QosPoliciesSerializer<dds::WireProtocolConfigQos>::cdr_serialized_size(
wire_protocol.value());
}
// PID_SENTINEL
return ret_val + 4;
}

bool ParticipantProxyData::write_to_cdr_message(
CDRMessage_t* msg,
bool write_encapsulation)
bool write_encapsulation,
bool force_write_optional_qos)
{
if (write_encapsulation)
{
Expand Down Expand Up @@ -447,6 +459,19 @@ bool ParticipantProxyData::write_to_cdr_message(
}
#endif // if HAVE_SECURITY

// serialize optional QoS if present
if (force_write_optional_qos || should_send_optional_qos())
{
// No need for QosPoliciesSerializer::should_be_sent since it is always different from the default.
// For instance, the discovery protocol is always different from NONE.
if (!fastdds::dds::QosPoliciesSerializer<dds::WireProtocolConfigQos>::add_to_cdr_message(
wire_protocol.value(),
msg))
{
return false;
}
}

return fastdds::dds::ParameterSerializer<Parameter_t>::add_parameter_sentinel(msg);
}

Expand Down Expand Up @@ -858,6 +883,20 @@ bool ParticipantProxyData::read_from_cdr_message(
#endif // if HAVE_SECURITY
break;
}
case fastdds::dds::PID_WIREPROTOCOL_CONFIG:
{
if (!wire_protocol)
{
wire_protocol.reset(true);
}

if (!fastdds::dds::QosPoliciesSerializer<dds::WireProtocolConfigQos>::read_from_cdr_message(
wire_protocol.value(), msg, plength))
{
return false;
}
break;
}
default:
{
break;
Expand Down Expand Up @@ -954,6 +993,8 @@ void ParticipantProxyData::copy(
std::chrono::microseconds(
fastdds::rtps::TimeConv::Duration_t2MicroSecondsInt64(
pdata.lease_duration));
m_should_send_optional_qos = pdata.m_should_send_optional_qos;

m_key = pdata.m_key;
is_alive = pdata.is_alive;
user_data = pdata.user_data;
Expand Down
30 changes: 28 additions & 2 deletions src/cpp/rtps/builtin/data/ParticipantProxyData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,24 @@ class ParticipantProxyData : public ParticipantBuiltinTopicData
/**
* Get the size in bytes of the CDR serialization of this object.
* @param include_encapsulation Whether to include the size of the encapsulation info.
* @param force_including_optional_qos Whether to force including of the optional Qos.
* @return size in bytes of the CDR serialization.
*/
uint32_t get_serialized_size(
bool include_encapsulation) const;
bool include_encapsulation,
bool force_including_optional_qos = false) const;

/**
* Write as a parameter list on a CDRMessage_t
* @param msg CDRMessage_t to write to
* @param write_encapsulation Whether to write the encapsulation info.
* @param force_write_optional_qos Whether to write the optional Qos.
* @return True on success
*/
bool write_to_cdr_message(
CDRMessage_t* msg,
bool write_encapsulation);
bool write_encapsulation,
bool force_write_optional_qos = false);

/**
* Read the parameter list from a received CDRMessage_t
Expand Down Expand Up @@ -209,13 +215,33 @@ class ParticipantProxyData : public ParticipantBuiltinTopicData
return last_received_message_tm_;
}

//! Getter for m_should_send_optional_qos.
bool should_send_optional_qos() const
{
return m_should_send_optional_qos;
}

/**
* Set whether optional QoS should be serialized and added to Data(p).
* @param should_send_optional_qos Boolean indicating whether optional QoS should be serialized
* and added to Data(p).
*/
void should_send_optional_qos(
bool should_send_optional_qos)
{
m_should_send_optional_qos = should_send_optional_qos;
}

private:

//! Store the last timestamp it was received a RTPS message from the remote participant.
std::chrono::steady_clock::time_point last_received_message_tm_;

//! Remote participant lease duration in microseconds.
std::chrono::microseconds lease_duration_;

//!Whether optional QoS should be serialized and added to Data(p)
bool m_should_send_optional_qos{false};
};

} // namespace rtps
Expand Down
10 changes: 6 additions & 4 deletions src/cpp/rtps/builtin/data/ReaderProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ void ReaderProxyData::init(
}

uint32_t ReaderProxyData::get_serialized_size(
bool include_encapsulation) const
bool include_encapsulation,
bool force_including_optional_qos) const
{
uint32_t ret_val = include_encapsulation ? 4 : 0;

Expand Down Expand Up @@ -370,7 +371,7 @@ uint32_t ReaderProxyData::get_serialized_size(
}

// Send the optional QoS policies if they are enabled
if (should_send_optional_qos())
if (force_including_optional_qos || should_send_optional_qos())
{
if (dds::QosPoliciesSerializer<dds::ResourceLimitsQosPolicy>::should_be_sent(resource_limits))
{
Expand Down Expand Up @@ -408,7 +409,8 @@ uint32_t ReaderProxyData::get_serialized_size(

bool ReaderProxyData::write_to_cdr_message(
CDRMessage_t* msg,
bool write_encapsulation) const
bool write_encapsulation,
bool force_write_optional_qos) const
{
if (write_encapsulation)
{
Expand Down Expand Up @@ -696,7 +698,7 @@ bool ReaderProxyData::write_to_cdr_message(
}

// Send the optional QoS policies if they are enabled
if (should_send_optional_qos())
if (force_write_optional_qos || should_send_optional_qos())
{
if (dds::QosPoliciesSerializer<dds::ResourceLimitsQosPolicy>::should_be_sent(resource_limits))
{
Expand Down
12 changes: 9 additions & 3 deletions src/cpp/rtps/builtin/data/ReaderProxyData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,24 @@ class ReaderProxyData : public SubscriptionBuiltinTopicData
/**
* Get the size in bytes of the CDR serialization of this object.
* @param include_encapsulation Whether to include the size of the encapsulation info.
* @param force_including_optional_qos Whether to force including the optional QoS in the size.
* @return size in bytes of the CDR serialization.
*/
uint32_t get_serialized_size(
bool include_encapsulation) const;
bool include_encapsulation,
bool force_including_optional_qos = false) const;

/**
* Write as a parameter list on a CDRMessage_t
* @param msg Pointer to the CDRmessage.
* @param write_encapsulation Whether to write the encapsulation info.
* @param force_write_optional_qos Whether to force writing the optional QoS.
* @return True on success
*/
bool write_to_cdr_message(
CDRMessage_t* msg,
bool write_encapsulation) const;
bool write_encapsulation,
bool force_write_optional_qos = false) const;

/**
* Read the information from a CDRMessage_t. The position of the message must be in the beginning on the
Expand Down Expand Up @@ -442,7 +448,7 @@ class ReaderProxyData : public SubscriptionBuiltinTopicData
dds::TypeObjectV1* m_type;

//!Whether optional QoS should be serialized and added to Data(r)
bool m_should_send_optional_qos;
bool m_should_send_optional_qos{false};
};

} // namespace rtps
Expand Down
13 changes: 8 additions & 5 deletions src/cpp/rtps/builtin/data/WriterProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ void WriterProxyData::init(
}

uint32_t WriterProxyData::get_serialized_size(
bool include_encapsulation) const
bool include_encapsulation,
bool force_including_optional_qos) const
{
uint32_t ret_val = include_encapsulation ? 4 : 0;

Expand Down Expand Up @@ -357,7 +358,7 @@ uint32_t WriterProxyData::get_serialized_size(
}

// Send the optional QoS policies if they are enabled
if (should_send_optional_qos())
if (force_including_optional_qos || should_send_optional_qos())
{
if (dds::QosPoliciesSerializer<dds::ResourceLimitsQosPolicy>::should_be_sent(resource_limits))
{
Expand Down Expand Up @@ -407,7 +408,8 @@ uint32_t WriterProxyData::get_serialized_size(

bool WriterProxyData::write_to_cdr_message(
CDRMessage_t* msg,
bool write_encapsulation) const
bool write_encapsulation,
bool force_write_optional_qos) const
{
if (write_encapsulation)
{
Expand Down Expand Up @@ -677,8 +679,9 @@ bool WriterProxyData::write_to_cdr_message(
}
}

// Send the optional QoS policies if they are enabled
if (should_send_optional_qos())
// Send the optional QoS policies if required
// Should_send_optional_qos() is true if `fastdds.serialize_optional_qos` property is set to true
if (force_write_optional_qos || should_send_optional_qos())
{
if (dds::QosPoliciesSerializer<dds::ResourceLimitsQosPolicy>::should_be_sent(resource_limits))
{
Expand Down
17 changes: 13 additions & 4 deletions src/cpp/rtps/builtin/data/WriterProxyData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,24 @@ class WriterProxyData : public PublicationBuiltinTopicData
/**
* Get the size in bytes of the CDR serialization of this object.
* @param include_encapsulation Whether to include the size of the encapsulation info.
* @param force_including_optional_qos Whether to force including the optional QoS in the size.
* @return size in bytes of the CDR serialization.
*/
uint32_t get_serialized_size(
bool include_encapsulation) const;
bool include_encapsulation,
bool force_including_optional_qos = false) const;

//!Write as a parameter list on a CDRMessage_t
/**
* Write as a parameter list on a CDRMessage_t
* @param msg Pointer to the CDRmessage.
* @param write_encapsulation Whether to write the encapsulation info.
* @param force_write_optional_qos Whether to write the optional QoS.
* @return True on success
*/
bool write_to_cdr_message(
CDRMessage_t* msg,
bool write_encapsulation) const;
bool write_encapsulation,
bool force_write_optional_qos = false) const;

/**
* Read the information from a CDRMessage_t. The position of the message must be in the beginning on the
Expand Down Expand Up @@ -438,7 +447,7 @@ class WriterProxyData : public PublicationBuiltinTopicData
dds::TypeObjectV1* m_type;

//!Whether optional QoS should be serialized and added to Data(r)
bool m_should_send_optional_qos;
bool m_should_send_optional_qos{false};
};

} // namespace rtps
Expand Down
Loading
Loading