diff --git a/cpp_utils/src/cpp/event/FileWatcher.hpp b/cpp_utils/src/cpp/event/FileWatcher.hpp index f7955c7..66d76fa 100644 --- a/cpp_utils/src/cpp/event/FileWatcher.hpp +++ b/cpp_utils/src/cpp/event/FileWatcher.hpp @@ -20,50 +20,39 @@ #include -#if !defined(__APPLE__) +// The bundled FileWatch backend is only usable on Windows and Unix. It is disabled +// on QNX (where it compiles but throws at runtime) and on any other platform. +#if (defined(_WIN32) || defined(__unix__)) && !defined(__QNX__) +#define FILEWATCH_ENABLED 1 +#else +#define FILEWATCH_ENABLED 0 +#endif // FileWatch backend availability + +#if FILEWATCH_ENABLED #include -#endif // if !defined(__APPLE__) +#endif // FILEWATCH_ENABLED namespace eprosima { namespace utils { namespace event { -#if defined(__APPLE__) +#if FILEWATCH_ENABLED -enum class FileWatchEvent +class FileWatcher : public filewatch::FileWatch { - added, - removed, - modified, - renamed_old, - renamed_new + using filewatch::FileWatch::FileWatch; }; -class FileWatcher -{ -public: - - template - FileWatcher( - std::string, - Callback&&) - { - } - -}; +using FileWatchEvent = filewatch::Event; #else -class FileWatcher : public filewatch::FileWatch +class FileWatcher { - using filewatch::FileWatch::FileWatch; }; -using FileWatchEvent = filewatch::Event; - -#endif // defined(__APPLE__) +#endif // FILEWATCH_ENABLED } /* namespace event */ } /* namespace utils */ } /* namespace eprosima */ - diff --git a/cpp_utils/src/cpp/event/FileWatcherHandler.cpp b/cpp_utils/src/cpp/event/FileWatcherHandler.cpp index c0fdfb1..85cfd0d 100644 --- a/cpp_utils/src/cpp/event/FileWatcherHandler.cpp +++ b/cpp_utils/src/cpp/event/FileWatcherHandler.cpp @@ -56,12 +56,7 @@ void FileWatcherHandler::start_filewatcher_nts_() { logInfo(UTILS_FILEWATCHER, "Starting FileWatcher in file: " << file_path_); -#if defined(__APPLE__) - logWarning( - UTILS_FILEWATCHER, - "File watching is disabled on macOS because the bundled backend only supports Windows and Linux."); - filewatcher_started_.store(true); -#else +#if FILEWATCH_ENABLED try { file_watch_handler_ = std::make_unique( @@ -86,8 +81,12 @@ void FileWatcherHandler::start_filewatcher_nts_() << "Error creating file watcher: " << e.what()); } +#else + logWarning( + UTILS_FILEWATCHER, + "File watching is not available on this platform."); +#endif // FILEWATCH_ENABLED filewatcher_started_.store(true); -#endif // defined(__APPLE__) logInfo(UTILS_FILEWATCHER, "Start Watching file: " << file_path_); } @@ -119,4 +118,3 @@ void FileWatcherHandler::callback_unset_nts_() noexcept } /* namespace event */ } /* namespace utils */ } /* namespace eprosima */ -