Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 16 additions & 27 deletions cpp_utils/src/cpp/event/FileWatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,39 @@

#include <string>

#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 <FileWatch.hpp>
#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<std::string>
{
added,
removed,
modified,
renamed_old,
renamed_new
using filewatch::FileWatch<std::string>::FileWatch;
};

class FileWatcher
{
public:

template<typename Callback>
FileWatcher(
std::string,
Callback&&)
{
}

};
using FileWatchEvent = filewatch::Event;

#else

class FileWatcher : public filewatch::FileWatch<std::string>
class FileWatcher
{
using filewatch::FileWatch<std::string>::FileWatch;
};

using FileWatchEvent = filewatch::Event;

#endif // defined(__APPLE__)
#endif // FILEWATCH_ENABLED

} /* namespace event */
} /* namespace utils */
} /* namespace eprosima */

14 changes: 6 additions & 8 deletions cpp_utils/src/cpp/event/FileWatcherHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileWatcher>(
Expand All @@ -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_);
}
Expand Down Expand Up @@ -119,4 +118,3 @@ void FileWatcherHandler::callback_unset_nts_() noexcept
} /* namespace event */
} /* namespace utils */
} /* namespace eprosima */

Loading