Skip to content

Commit 81d86d0

Browse files
Disable FileWatch in QNX (#160)
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
1 parent 9d529a2 commit 81d86d0

2 files changed

Lines changed: 22 additions & 35 deletions

File tree

cpp_utils/src/cpp/event/FileWatcher.hpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,39 @@
2020

2121
#include <string>
2222

23-
#if !defined(__APPLE__)
23+
// The bundled FileWatch backend is only usable on Windows and Unix. It is disabled
24+
// on QNX (where it compiles but throws at runtime) and on any other platform.
25+
#if (defined(_WIN32) || defined(__unix__)) && !defined(__QNX__)
26+
#define FILEWATCH_ENABLED 1
27+
#else
28+
#define FILEWATCH_ENABLED 0
29+
#endif // FileWatch backend availability
30+
31+
#if FILEWATCH_ENABLED
2432
#include <FileWatch.hpp>
25-
#endif // if !defined(__APPLE__)
33+
#endif // FILEWATCH_ENABLED
2634

2735
namespace eprosima {
2836
namespace utils {
2937
namespace event {
3038

31-
#if defined(__APPLE__)
39+
#if FILEWATCH_ENABLED
3240

33-
enum class FileWatchEvent
41+
class FileWatcher : public filewatch::FileWatch<std::string>
3442
{
35-
added,
36-
removed,
37-
modified,
38-
renamed_old,
39-
renamed_new
43+
using filewatch::FileWatch<std::string>::FileWatch;
4044
};
4145

42-
class FileWatcher
43-
{
44-
public:
45-
46-
template<typename Callback>
47-
FileWatcher(
48-
std::string,
49-
Callback&&)
50-
{
51-
}
52-
53-
};
46+
using FileWatchEvent = filewatch::Event;
5447

5548
#else
5649

57-
class FileWatcher : public filewatch::FileWatch<std::string>
50+
class FileWatcher
5851
{
59-
using filewatch::FileWatch<std::string>::FileWatch;
6052
};
6153

62-
using FileWatchEvent = filewatch::Event;
63-
64-
#endif // defined(__APPLE__)
54+
#endif // FILEWATCH_ENABLED
6555

6656
} /* namespace event */
6757
} /* namespace utils */
6858
} /* namespace eprosima */
69-

cpp_utils/src/cpp/event/FileWatcherHandler.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ void FileWatcherHandler::start_filewatcher_nts_()
5656
{
5757
logInfo(UTILS_FILEWATCHER, "Starting FileWatcher in file: " << file_path_);
5858

59-
#if defined(__APPLE__)
60-
logWarning(
61-
UTILS_FILEWATCHER,
62-
"File watching is disabled on macOS because the bundled backend only supports Windows and Linux.");
63-
filewatcher_started_.store(true);
64-
#else
59+
#if FILEWATCH_ENABLED
6560
try
6661
{
6762
file_watch_handler_ = std::make_unique<FileWatcher>(
@@ -86,8 +81,12 @@ void FileWatcherHandler::start_filewatcher_nts_()
8681
<< "Error creating file watcher: " << e.what());
8782
}
8883

84+
#else
85+
logWarning(
86+
UTILS_FILEWATCHER,
87+
"File watching is not available on this platform.");
88+
#endif // FILEWATCH_ENABLED
8989
filewatcher_started_.store(true);
90-
#endif // defined(__APPLE__)
9190

9291
logInfo(UTILS_FILEWATCHER, "Start Watching file: " << file_path_);
9392
}
@@ -119,4 +118,3 @@ void FileWatcherHandler::callback_unset_nts_() noexcept
119118
} /* namespace event */
120119
} /* namespace utils */
121120
} /* namespace eprosima */
122-

0 commit comments

Comments
 (0)