te::core::FileWatcher Class Reference

#include <FileWatcher.h>

Public Member Functions

 FileWatcher (const std::string &path, const std::function< void()> &callback)
 It initializes a new FileWatcher from a given path and callback function. More...
 
void unwatch ()
 Stops the thread watching the file. More...
 
void watch ()
 Starts a thread that will monitor the given file and call the previously given callback function. More...
 
 ~FileWatcher ()
 Destructor. More...
 

Private Attributes

std::function< void()> m_callback
 
std::string m_file
 
std::mutex m_mutex
 
bool m_running
 
std::thread m_watcher
 

Detailed Description

Definition at line 46 of file FileWatcher.h.

Constructor & Destructor Documentation

FileWatcher::FileWatcher ( const std::string &  path,
const std::function< void()> &  callback 
)

It initializes a new FileWatcher from a given path and callback function.

Parameters
pathA UTF-8 String with a path to a file.
callbackA function with zero parameters and void return that will be called when the file is changed.

Definition at line 38 of file FileWatcher.cpp.

FileWatcher::~FileWatcher ( )

Destructor.

Definition at line 44 of file FileWatcher.cpp.

References m_watcher.

Member Function Documentation

void FileWatcher::unwatch ( )

Stops the thread watching the file.

Definition at line 91 of file FileWatcher.cpp.

References m_running.

void FileWatcher::watch ( )

Starts a thread that will monitor the given file and call the previously given callback function.

Definition at line 49 of file FileWatcher.cpp.

References te::core::FileSystem::exists(), te::core::FileSystem::fileSize(), m_callback, m_file, m_mutex, m_running, and m_watcher.

Member Data Documentation

std::function<void()> te::core::FileWatcher::m_callback
private

Definition at line 84 of file FileWatcher.h.

Referenced by watch().

std::string te::core::FileWatcher::m_file
private

Definition at line 83 of file FileWatcher.h.

Referenced by watch().

std::mutex te::core::FileWatcher::m_mutex
private

Definition at line 82 of file FileWatcher.h.

Referenced by watch().

bool te::core::FileWatcher::m_running
private

Definition at line 86 of file FileWatcher.h.

Referenced by unwatch(), and watch().

std::thread te::core::FileWatcher::m_watcher
private

Definition at line 85 of file FileWatcher.h.

Referenced by watch(), and ~FileWatcher().


The documentation for this class was generated from the following files: