Skip to content

Commit

Permalink
Process an empty YAML when no YAML file is given
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate committed Dec 27, 2023
1 parent 208dadc commit db43dd2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
5 changes: 2 additions & 3 deletions fastddsspy_tool/src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
29 changes: 26 additions & 3 deletions fastddsspy_yaml/src/cpp/YamlReaderConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_(
Expand Down Expand Up @@ -105,7 +105,7 @@ void Configuration::load_configuration_(
ddspipe_configuration.blocklist.insert(
utils::Heritable<WildcardDdsFilterTopic>::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)
Expand Down Expand Up @@ -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(

Check warning on line 233 in fastddsspy_yaml/src/cpp/YamlReaderConfiguration.cpp

View check run for this annotation

Codecov / codecov/patch

fastddsspy_yaml/src/cpp/YamlReaderConfiguration.cpp#L233

Added line #L233 was not covered by tests
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
{
Expand Down

0 comments on commit db43dd2

Please sign in to comment.