Skip to content

Commit

Permalink
Fixes after tests
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate committed Jul 17, 2024
1 parent 2d2bc76 commit 91c7487
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 73 deletions.
24 changes: 22 additions & 2 deletions ddspipe_yaml/include/ddspipe_yaml/YamlReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <functional>

#include <cpp_utils/types/Fuzzy.hpp>
#include <cpp_utils/enum/EnumBuilder.hpp>

Expand Down Expand Up @@ -157,13 +159,31 @@ class
const Yaml& yml,
const TagType& tag);

//! TODO comment
/**
* @brief Validate \c yml and build the object \c T
*
* This method calls \c get with the default validation function.
*
* @tparam T type of the object to build
* @param yml base yaml
* @param version configuration version
*/
template <typename T>
static T get(
const Yaml& yml,
const YamlReaderVersion version);

//! Get element inside \c tag
/**
* @brief Extracts the sub-yaml from the \c tag and then builds the object \c T
*
* This method calls \c get_value_in_tag to extract the sub-yaml from the \c tag and then it calls \c get to build
* and validate the object \c T.
*
* @tparam T type of the object to build
* @param yml base yaml
* @param tag key to yaml containing the object
* @param version configuration version
*/
template <typename T>
static T get(
const Yaml& yml,
Expand Down
118 changes: 71 additions & 47 deletions ddspipe_yaml/src/cpp/YamlReader_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ core::RoutesConfiguration YamlReader::get(
const Yaml& yml,
const YamlReaderVersion version)
{
// NOTE: The validation has to be done inside the fill method since the yml object is a list with the routes

core::RoutesConfiguration object;
fill<core::RoutesConfiguration>(object, yml, version);
return object;
Expand Down Expand Up @@ -229,6 +231,8 @@ core::TopicRoutesConfiguration YamlReader::get(
const Yaml& yml,
const YamlReaderVersion version)
{
// NOTE: The validation has to be done inside the fill method since the yml object is a list with the topic routes

core::TopicRoutesConfiguration object;
fill<core::TopicRoutesConfiguration>(object, yml, version);
return object;
Expand All @@ -241,109 +245,129 @@ core::TopicRoutesConfiguration YamlReader::get(
template <>
DDSPIPE_YAML_DllAPI
void YamlReader::fill(
core::MonitorConfiguration& object,
core::MonitorProducerConfiguration& object,
const Yaml& yml,
const YamlReaderVersion version)
{
core::types::DomainIdType domain = 0;

// Optional domain
if (is_tag_present(yml, MONITOR_DOMAIN_TAG))
{
domain = get<int>(yml, MONITOR_DOMAIN_TAG, version);
}

/////
// Get optional monitor status tag
if (YamlReader::is_tag_present(yml, MONITOR_STATUS_TAG))
// Optional enable
if (is_tag_present(yml, MONITOR_ENABLE_TAG))
{
object.producers[core::STATUS_MONITOR_PRODUCER_ID] = YamlReader::get<core::MonitorProducerConfiguration>(yml,
MONITOR_STATUS_TAG,
version);
object.consumers[core::STATUS_MONITOR_PRODUCER_ID].domain = domain;
YamlReader::fill<core::DdsPublishingConfiguration>(object.consumers[core::STATUS_MONITOR_PRODUCER_ID],
get_value_in_tag(yml, MONITOR_STATUS_TAG), version);
object.enabled = get<bool>(yml, MONITOR_ENABLE_TAG, version);
}

/////
// Get optional monitor topics tag
if (YamlReader::is_tag_present(yml, MONITOR_TOPICS_TAG))
// Optional period
if (is_tag_present(yml, MONITOR_PERIOD_TAG))
{
object.producers[core::TOPICS_MONITOR_PRODUCER_ID] = YamlReader::get<core::MonitorProducerConfiguration>(yml,
MONITOR_TOPICS_TAG,
version);
object.consumers[core::TOPICS_MONITOR_PRODUCER_ID].domain = domain;
YamlReader::fill<core::DdsPublishingConfiguration>(object.consumers[core::TOPICS_MONITOR_PRODUCER_ID],
get_value_in_tag(yml, MONITOR_TOPICS_TAG), version);
object.period = get_positive_double(yml, MONITOR_PERIOD_TAG);
}
}

template <>
DDSPIPE_YAML_DllAPI
bool YamlValidator::validate<core::MonitorConfiguration>(
bool YamlValidator::validate<core::MonitorProducerConfiguration>(
const Yaml& yml,
const YamlReaderVersion& /* version */)
{
static const std::set<TagType> tags{
MONITOR_DOMAIN_TAG,
MONITOR_STATUS_TAG,
MONITOR_TOPICS_TAG};
MONITOR_ENABLE_TAG,
MONITOR_PERIOD_TAG};

return YamlValidator::validate_tags(yml, tags);
}

template <>
DDSPIPE_YAML_DllAPI
core::MonitorConfiguration YamlReader::get(
core::MonitorProducerConfiguration YamlReader::get(
const Yaml& yml,
const YamlReaderVersion version)
{
core::MonitorConfiguration object;
fill<core::MonitorConfiguration>(object, yml, version);
YamlValidator::validate<core::MonitorProducerConfiguration>(yml, version);

core::MonitorProducerConfiguration object;
fill<core::MonitorProducerConfiguration>(object, yml, version);
return object;
}

template <>
DDSPIPE_YAML_DllAPI
void YamlReader::fill(
core::MonitorProducerConfiguration& object,
core::MonitorConfiguration& object,
const Yaml& yml,
const YamlReaderVersion version)
{
// Optional enable
if (is_tag_present(yml, MONITOR_ENABLE_TAG))
core::types::DomainIdType domain = 0;

// Optional domain
if (is_tag_present(yml, MONITOR_DOMAIN_TAG))
{
object.enabled = get<bool>(yml, MONITOR_ENABLE_TAG, version);
domain = get<int>(yml, MONITOR_DOMAIN_TAG, version);
}

// Optional period
if (is_tag_present(yml, MONITOR_PERIOD_TAG))
static const std::set<TagType> tags{
MONITOR_ENABLE_TAG,
MONITOR_PERIOD_TAG,
DDS_PUBLISHING_ENABLE_TAG,
DDS_PUBLISHING_DOMAIN_TAG,
DDS_PUBLISHING_TOPIC_NAME_TAG,
DDS_PUBLISHING_PUBLISH_TYPE_TAG};

/////
// Get optional monitor status tag
if (is_tag_present(yml, MONITOR_STATUS_TAG))
{
object.period = get_positive_double(yml, MONITOR_PERIOD_TAG);
YamlValidator::validate_tags(yml[MONITOR_STATUS_TAG], tags);

// NOTE: Use fill instead of get to avoid throwing exceptions if tags are not present
fill<core::MonitorProducerConfiguration>(object.producers[core::STATUS_MONITOR_PRODUCER_ID],
get_value_in_tag(yml, MONITOR_STATUS_TAG), version);

// NOTE: Set the generic domain first so it can be overwritten by the specific domain if present
object.consumers[core::STATUS_MONITOR_PRODUCER_ID].domain = domain;
fill<core::DdsPublishingConfiguration>(object.consumers[core::STATUS_MONITOR_PRODUCER_ID],
get_value_in_tag(yml, MONITOR_STATUS_TAG), version);
}

/////
// Get optional monitor topics tag
if (is_tag_present(yml, MONITOR_TOPICS_TAG))
{
YamlValidator::validate_tags(yml[MONITOR_TOPICS_TAG], tags);

// NOTE: Use fill instead of get to avoid throwing exceptions if tags are not present
fill<core::MonitorProducerConfiguration>(object.producers[core::TOPICS_MONITOR_PRODUCER_ID],
get_value_in_tag(yml, MONITOR_TOPICS_TAG), version);

// NOTE: Set the generic domain first so it can be overwritten by the specific domain if present
object.consumers[core::TOPICS_MONITOR_PRODUCER_ID].domain = domain;
fill<core::DdsPublishingConfiguration>(object.consumers[core::TOPICS_MONITOR_PRODUCER_ID],
get_value_in_tag(yml, MONITOR_TOPICS_TAG), version);
}
}

template <>
DDSPIPE_YAML_DllAPI
bool YamlValidator::validate<core::MonitorProducerConfiguration>(
bool YamlValidator::validate<core::MonitorConfiguration>(
const Yaml& yml,
const YamlReaderVersion& /* version */)
{
static const std::set<TagType> tags{
MONITOR_ENABLE_TAG,
MONITOR_PERIOD_TAG};
MONITOR_DOMAIN_TAG,
MONITOR_STATUS_TAG,
MONITOR_TOPICS_TAG};

return YamlValidator::validate_tags(yml, tags);
}

template <>
DDSPIPE_YAML_DllAPI
core::MonitorProducerConfiguration YamlReader::get(
core::MonitorConfiguration YamlReader::get(
const Yaml& yml,
const YamlReaderVersion version)
{
core::MonitorProducerConfiguration object;
fill<core::MonitorProducerConfiguration>(object, yml, version);
YamlValidator::validate<core::MonitorConfiguration>(yml, version);

core::MonitorConfiguration object;
fill<core::MonitorConfiguration>(object, yml, version);
return object;
}

Expand Down
2 changes: 0 additions & 2 deletions ddspipe_yaml/src/cpp/YamlReader_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include <ddspipe_core/types/dds/DomainId.hpp>
#include <ddspipe_core/types/dds/GuidPrefix.hpp>
#include <ddspipe_core/types/participant/ParticipantId.hpp>
#include <ddspipe_core/types/topic/dds/DdsTopic.hpp>
#include <ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp>

#include <ddspipe_participants/types/address/Address.hpp>
#include <ddspipe_participants/types/address/DiscoveryServerConnectionAddress.hpp>
Expand Down
24 changes: 6 additions & 18 deletions ddspipe_yaml/src/cpp/YamlReader_participants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ bool YamlValidator::validate<participants::SimpleParticipantConfiguration>(
static const std::set<TagType> tags{
PARTICIPANT_NAME_TAG,
PARTICIPANT_KIND_TAG,
PARTICIPANT_QOS_TAG,
DOMAIN_ID_TAG,
WHITELIST_INTERFACES_TAG,
TRANSPORT_DESCRIPTORS_TRANSPORT_TAG,
IGNORE_PARTICIPANT_FLAGS_TAG,
PARTICIPANT_QOS_TAG};
IGNORE_PARTICIPANT_FLAGS_TAG};

return YamlValidator::validate_tags(yml, tags);
}
Expand Down Expand Up @@ -270,10 +270,7 @@ void YamlReader::fill(
// Optional TLS
if (YamlReader::is_tag_present(yml, TLS_TAG))
{
YamlReader::fill<TlsConfiguration>(
object.tls_configuration,
YamlReader::get_value_in_tag(yml, TLS_TAG),
version);
object.tls_configuration = YamlReader::get<TlsConfiguration>(yml, TLS_TAG, version);
}

// NOTE: The only field that change regarding the version is the GuidPrefix.
Expand All @@ -300,11 +297,10 @@ bool YamlValidator::validate<participants::DiscoveryServerParticipantConfigurati
static const std::set<TagType> tags{
PARTICIPANT_NAME_TAG,
PARTICIPANT_KIND_TAG,
DOMAIN_ID_TAG,
PARTICIPANT_QOS_TAG,
WHITELIST_INTERFACES_TAG,
TRANSPORT_DESCRIPTORS_TRANSPORT_TAG,
IGNORE_PARTICIPANT_FLAGS_TAG,
PARTICIPANT_QOS_TAG,
LISTENING_ADDRESSES_TAG,
CONNECTION_ADDRESSES_TAG,
TLS_TAG,
Expand Down Expand Up @@ -362,10 +358,7 @@ void YamlReader::fill(
// Optional TLS
if (YamlReader::is_tag_present(yml, TLS_TAG))
{
YamlReader::fill<TlsConfiguration>(
object.tls_configuration,
YamlReader::get_value_in_tag(yml, TLS_TAG),
version);
object.tls_configuration = YamlReader::get<TlsConfiguration>(yml, TLS_TAG, version);
}

// Optional Repeater
Expand All @@ -384,11 +377,10 @@ bool YamlValidator::validate<participants::InitialPeersParticipantConfiguration>
static const std::set<TagType> tags{
PARTICIPANT_NAME_TAG,
PARTICIPANT_KIND_TAG,
DOMAIN_ID_TAG,
PARTICIPANT_QOS_TAG,
WHITELIST_INTERFACES_TAG,
TRANSPORT_DESCRIPTORS_TRANSPORT_TAG,
IGNORE_PARTICIPANT_FLAGS_TAG,
PARTICIPANT_QOS_TAG,
LISTENING_ADDRESSES_TAG,
CONNECTION_ADDRESSES_TAG,
TLS_TAG,
Expand Down Expand Up @@ -435,10 +427,6 @@ bool YamlValidator::validate<participants::XmlParticipantConfiguration>(
static const std::set<TagType> tags{
PARTICIPANT_NAME_TAG,
PARTICIPANT_KIND_TAG,
DOMAIN_ID_TAG,
WHITELIST_INTERFACES_TAG,
TRANSPORT_DESCRIPTORS_TRANSPORT_TAG,
IGNORE_PARTICIPANT_FLAGS_TAG,
PARTICIPANT_QOS_TAG,
XML_PARTICIPANT_PROFILE_TAG};

Expand Down
12 changes: 8 additions & 4 deletions ddspipe_yaml/src/cpp/YamlReader_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Address YamlReader::get<Address>(
// If neither set, get default
if (ip_set && domain_name_set)
{
logWarning(ddspipe_YAML,
logWarning(DDSPIPE_YAML,
"Tag <" << ADDRESS_DNS_TAG << "> will not be used as <" << ADDRESS_IP_TAG << "> is set.");
domain_name_set = false;
}
Expand Down Expand Up @@ -581,7 +581,7 @@ TopicQoS YamlReader::get<TopicQoS>(

template <>
DDSPIPE_YAML_DllAPI
void YamlReader::fill<utils::LogFilter>(
void YamlReader::fill(
utils::LogFilter& object,
const Yaml& yml,
const YamlReaderVersion version)
Expand Down Expand Up @@ -622,6 +622,8 @@ utils::LogFilter YamlReader::get(
const Yaml& yml,
const YamlReaderVersion version)
{
YamlValidator::validate<utils::LogFilter>(yml, version);

utils::LogFilter object;
fill<utils::LogFilter>(object, yml, version);
return object;
Expand Down Expand Up @@ -662,7 +664,7 @@ void YamlReader::fill(
// Filter optional
if (is_tag_present(yml, LOG_FILTER_TAG))
{
fill<utils::LogFilter>(object.filter, get_value_in_tag(yml, LOG_FILTER_TAG), version);
object.filter = get<utils::LogFilter>(yml, LOG_FILTER_TAG, version);
}
}

Expand All @@ -687,6 +689,8 @@ core::DdsPipeLogConfiguration YamlReader::get(
const Yaml& yml,
const YamlReaderVersion version)
{
YamlValidator::validate<core::DdsPipeLogConfiguration>(yml, version);

core::DdsPipeLogConfiguration object;
fill<core::DdsPipeLogConfiguration>(object, yml, version);
return object;
Expand Down Expand Up @@ -795,7 +799,7 @@ void YamlReader::fill(
{
// Avoid calling YamlReader::get to avoid validation at a lower level
WildcardDdsFilterTopic manual_topic;
YamlReader::fill<WildcardDdsFilterTopic>(manual_topic, yml, version);
fill<WildcardDdsFilterTopic>(manual_topic, yml, version);

object.first = utils::Heritable<WildcardDdsFilterTopic>::make_heritable(manual_topic);

Expand Down

0 comments on commit 91c7487

Please sign in to comment.