Skip to content

Commit

Permalink
Add file_exists function to Utils.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaranda committed Apr 13, 2023
1 parent 837646a commit 2509a06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/config/XmlSupport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ bool XmlSupport::load_default_files()
cfg_file += default_configuration_file_name();

std::string normalized_path = utils::normalize_path(cfg_file).c_str();
if (RTIOsapiUtility_fileExists(normalized_path.c_str())) {
if (utils::file_exists(normalized_path)) {
parse_file(normalized_path);
} else {
// If files aren't in the default location, try to load the default
Expand All @@ -285,7 +285,7 @@ bool XmlSupport::load_default_files()
cfg_file += default_configuration_file_name();

normalized_path = utils::normalize_path(cfg_file).c_str();
if (RTIOsapiUtility_fileExists(normalized_path.c_str())) {
if (utils::file_exists(normalized_path)) {
parse_file(normalized_path);
} else {
GATEWAYLog_warn(
Expand All @@ -295,7 +295,7 @@ bool XmlSupport::load_default_files()
}

// Load the user file name (from working directory only)
if (RTIOsapiUtility_fileExists(user_configuration_file_name().c_str())) {
if (utils::file_exists(user_configuration_file_name())) {
parse_file(user_configuration_file_name());
} else {
GATEWAYLog_warn(
Expand Down
9 changes: 9 additions & 0 deletions src/service/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ static std::string executable_path()
return std::string(path);
}

static bool file_exists(const std::string& filename)
{
#if RTI_DDS_VERSION_MAJOR >= 7 && RTI_DDS_VERSION_MINOR >= 1
return static_cast<bool>(RTIOsapiFile_exists(filename.c_str()));
#else
return static_cast<bool>(RTIOsapiUtility_fileExists(filename.c_str()));
#endif
}

class Thread {
public:
Thread(const std::string& name = std::string("Thread"),
Expand Down

0 comments on commit 2509a06

Please sign in to comment.