8#include <sys/inotify.h>
19inline std::vector<std::string>
findFromFile(
const std::filesystem::path &filePath,
const std::string &pattern,
20 std::string &lastWord)
22 const std::regex regExp(pattern);
23 std::ifstream inFile(filePath);
24 std::vector<std::string> matchedLines;
27 while (getline(inFile, readLine))
29 if (std::regex_search(readLine, regExp))
31 matchedLines.push_back(readLine);
35 if (!matchedLines.empty())
37 auto pos = matchedLines.front().find_last_of(
' ');
38 if (pos != std::string::npos && pos != matchedLines.front().size())
40 lastWord = matchedLines.front().substr(pos + 1);
53inline std::vector<std::string>
findFromFile(
const std::filesystem::path &filePath,
const std::string &pattern)
83 void threadFunc(
const std::stop_token &stopToken)
const noexcept;
91 explicit FileMonitor(std::filesystem::path filePath, uint32_t notifyEvents = IN_MODIFY);
std::function< void(const void *)> FNotifyCallback
Callback function for file notifications.
std::vector< std::string > findFromFile(const std::filesystem::path &filePath, const std::string &pattern, std::string &lastWord)
const void * _userPtr
User pointer.
FileMonitor(const FileMonitor &)=delete
Copy constructor.
void threadFunc(const std::stop_token &stopToken) const noexcept
FNotifyCallback _notifyCallback
Callback function.
int _fDescriptor
File descriptor.
void notifyCallback(FNotifyCallback func)
void userPtr(const void *ptr)
FileMonitor(std::filesystem::path filePath, uint32_t notifyEvents=IN_MODIFY)
FileMonitor(FileMonitor &&)=delete
Move constructor.
FNotifyCallback notifyCallback() const
int _wDescriptor
Watch descriptor.
uint32_t _notifyEvents
Notify types.
FileMonitor & operator=(FileMonitor)=delete
Copy assignment operator.
std::filesystem::path _filePath
File path.
FileMonitor & operator=(FileMonitor &&)=delete
Move assignment operator.
std::unique_ptr< std::jthread > _thread
Thread.