demotool/filewatcher.hh

55 lines
1.1 KiB
C++

#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
/*= T_FilesWatcher / T_WatchedFiles ==========================================*/
struct T_FilesWatcher;
struct T_WatchedFiles;
using F_OnFileChanges = std::function< void( void ) >;
struct T_FilesWatcher
{
friend struct T_WatchedFiles;
T_FilesWatcher( T_FilesWatcher const& ) = delete;
T_FilesWatcher( );
T_FilesWatcher( T_FilesWatcher&& ) noexcept;
~T_FilesWatcher( );
void check( );
private:
int fd;
std::vector< T_WatchedFiles* > watched;
};
/*----------------------------------------------------------------------------*/
struct T_WatchedFiles
{
friend struct T_FilesWatcher;
T_WatchedFiles( ) = delete;
T_WatchedFiles( T_WatchedFiles const& ) = delete;
T_WatchedFiles( T_WatchedFiles&& ) noexcept;
T_WatchedFiles(
__rw__ T_FilesWatcher& watcher ,
__rd__ const F_OnFileChanges callback );
~T_WatchedFiles( );
void clear( );
bool watch( __rd__ std::string const& file );
private:
T_FilesWatcher* watcher;
const F_OnFileChanges callback;
bool triggered;
std::vector< int > identifiers;
};