Skip to content
Open
Changes from 1 commit
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
22 changes: 16 additions & 6 deletions rmw_zenoh_cpp/src/detail/zenoh_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "logging_macros.hpp"

#include <ament_index_cpp/get_package_share_path.hpp>
#include <ament_index_cpp/get_package_prefix.hpp> /* for PackageNotFoundError */
#include <rmw/impl/cpp/macros.hpp>

///=============================================================================
Expand Down Expand Up @@ -119,12 +120,21 @@ std::optional<zenoh::Config> get_z_config(const ConfigurableEntity & entity)
"rmw_zenoh_cpp", "get_z_config called with invalid ConfigurableEntity.");
return std::nullopt;
}
// Get the absolute path to the default configuration file.
std::filesystem::path path_to_config_folder =
ament_index_cpp::get_package_share_path("rmw_zenoh_cpp") / "config";

const std::filesystem::path default_config_path =
path_to_config_folder / envar_map_it->second.second;

std::filesystem::path default_config_path;

try {
// Get the absolute path to the default configuration file.
std::filesystem::path path_to_config_folder =
ament_index_cpp::get_package_share_path("rmw_zenoh_cpp") / "config";

default_config_path = path_to_config_folder / envar_map_it->second.second;
} catch (const ament_index_cpp::PackageNotFoundError& e) {
RMW_ZENOH_LOG_WARN_NAMED(
"rmw_zenoh_cpp",
"Failed to find rmw_zenoh_cpp package in ament_index (%s). "
"Relying on 'ZENOH_*_CONFIG_URI' ENV vars.", e.what());
}

return _get_z_config(envar_map_it->second.first, default_config_path);
}
Expand Down
Loading