From c3b67537ea4753592c64826b40a661f0aacfc433 Mon Sep 17 00:00:00 2001 From: tempate Date: Thu, 14 Dec 2023 11:07:29 +0100 Subject: [PATCH] Process an empty YAML when no YAML file is given Signed-off-by: tempate --- fastddsspy_tool/src/cpp/main.cpp | 5 ++-- .../YamlReaderConfiguration.hpp | 3 ++ .../src/cpp/YamlReaderConfiguration.cpp | 29 +++++++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/fastddsspy_tool/src/cpp/main.cpp b/fastddsspy_tool/src/cpp/main.cpp index c3499f11..cef4b409 100644 --- a/fastddsspy_tool/src/cpp/main.cpp +++ b/fastddsspy_tool/src/cpp/main.cpp @@ -131,16 +131,15 @@ int main( // Fast DDS Spy Initialization // Default configuration. Load it from file if file exists - eprosima::spy::yaml::Configuration configuration; - if (file_path != "") { logInfo( FASTDDSSPY_TOOL, "Loading configuration from file '" << file_path << "' ."); - configuration = eprosima::spy::yaml::Configuration(file_path); } + eprosima::spy::yaml::Configuration configuration = eprosima::spy::yaml::Configuration(file_path); + // Create the Spy eprosima::spy::Controller spy(configuration); diff --git a/fastddsspy_yaml/include/fastddsspy_yaml/YamlReaderConfiguration.hpp b/fastddsspy_yaml/include/fastddsspy_yaml/YamlReaderConfiguration.hpp index 86ca8762..12b593f3 100644 --- a/fastddsspy_yaml/include/fastddsspy_yaml/YamlReaderConfiguration.hpp +++ b/fastddsspy_yaml/include/fastddsspy_yaml/YamlReaderConfiguration.hpp @@ -87,6 +87,9 @@ class Configuration : ddspipe::core::IConfiguration void load_dds_configuration_( const Yaml& yml, const ddspipe::yaml::YamlReaderVersion& version); + + void load_configuration_from_file_( + const std::string& file_path); }; } /* namespace yaml */ diff --git a/fastddsspy_yaml/src/cpp/YamlReaderConfiguration.cpp b/fastddsspy_yaml/src/cpp/YamlReaderConfiguration.cpp index 71e583f1..94aac2d3 100644 --- a/fastddsspy_yaml/src/cpp/YamlReaderConfiguration.cpp +++ b/fastddsspy_yaml/src/cpp/YamlReaderConfiguration.cpp @@ -61,9 +61,9 @@ Configuration::Configuration( Configuration::Configuration( const std::string& file_path) - : Configuration(YamlManager::load_file(file_path)) + : Configuration() { - // Do nothing + load_configuration_from_file_(file_path); } void Configuration::load_configuration_( @@ -105,7 +105,7 @@ void Configuration::load_configuration_( ddspipe_configuration.blocklist.insert( utils::Heritable::make_heritable(rpc_response_topic)); - // Only trigger the DdsPipe's callbacks with the discovery (and removal) of writers. + // Only trigger the DdsPipe's callbacks when discovering or removing writers ddspipe_configuration.discovery_trigger = DiscoveryTrigger::WRITER; } catch (const std::exception& e) @@ -215,6 +215,29 @@ void Configuration::load_specs_configuration_( } } +void Configuration::load_configuration_from_file_( + const std::string& file_path) +{ + Yaml yml; + + // Load file + try + { + if (!file_path.empty()) + { + yml = YamlManager::load_file(file_path); + } + } + catch (const std::exception& e) + { + throw eprosima::utils::ConfigurationException( + utils::Formatter() << "Error loading Fast-DDS Spy configuration from file: <" << file_path << + "> :\n " << e.what()); + } + + load_configuration_(yml); +} + bool Configuration::is_valid( utils::Formatter& error_msg) const noexcept {