Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::FileSystemWatcherAsyncT< T_AsyncEventLoop > Struct Template Reference

FileSystemWatcherAsyncT is an implementation of SC::FileSystemWatcher that uses SC::Async. More...

#include <FileSystemWatcher.h>

Inheritance diagram for SC::FileSystemWatcherAsyncT< T_AsyncEventLoop >:
SC::FileSystemWatcher::EventLoopRunner

Public Types

using Self = FileSystemWatcherAsyncT
 
using T_AsyncLoopWakeUp = typename T_AsyncEventLoop::LoopWakeUp
 
using T_AsyncFilePoll = typename T_AsyncEventLoop::FilePoll
 
using T_EventObject = typename T_AsyncEventLoop::EventObjectType
 
using T_AsyncResult = typename T_AsyncEventLoop::ResultType
 

Public Member Functions

void init (T_AsyncEventLoop &loop)
 
- Public Member Functions inherited from SC::FileSystemWatcher::EventLoopRunner

Protected Types

using FolderWatcher = FileSystemWatcher::FolderWatcher
 

Protected Member Functions

virtual Result windowsStartFolderFilePoll (FolderWatcher &watcher, void *handle) override
 
virtual Result windowsStopFolderFilePoll (FolderWatcher &watcher) override
 
virtual void * windowsGetOverlapped (FolderWatcher &watcher) override
 
void onEventLoopNotification (typename T_AsyncFilePoll::Result &result)
 
- Protected Member Functions inherited from SC::FileSystemWatcher::EventLoopRunner
void internalInit (FileSystemWatcher &fsWatcher, int handle)
 

Protected Attributes

T_AsyncEventLoop * eventLoop = nullptr
 
Function< void(T_AsyncResult &)> onAsyncPollClose
 
- Protected Attributes inherited from SC::FileSystemWatcher::EventLoopRunner
FileSystemWatcherfileSystemWatcher = nullptr
 

Detailed Description

template<typename T_AsyncEventLoop>
struct SC::FileSystemWatcherAsyncT< T_AsyncEventLoop >

FileSystemWatcherAsyncT is an implementation of SC::FileSystemWatcher that uses SC::Async.

This class exists as a template is to break the dependency of SC::FileSystemWatcher from SC::AsyncEventLoop.

Example:

// Initialize the FileSystemWatcher
FileSystemWatcher fileSystemWatcher;
eventLoopRunner.init(eventLoop);
SC_TRY(fileSystemWatcher.init(eventLoopRunner));
// Setup notification callback
auto onFileModified = [&](const FileSystemWatcher::Notification& notification)
{
// This callback will be called from the thread calling AsyncEventLoop::run
StringPath fullPath;
if (notification.getFullPath(fullPath))
{
switch (notification.operation)
{
case FileSystemWatcher::Operation::Modified: // File has been modified
console.print("Modified {} {}\n", notification.relativePath, fullPath.view());
break;
case FileSystemWatcher::Operation::AddRemoveRename: // File was added / removed
console.print("AddRemoveRename {} {}\n", notification.relativePath, fullPath.view());
break;
}
}
};
// Start watching a specific folder
folderWatcher.notifyCallback = onFileModified;
SC_TRY(fileSystemWatcher.watch(folderWatcher, "/path/to/dir"));
// ...
// At a later point when there is no more need of watching the folder
SC_TRY(folderWatcher.stopWatching());
// ...
// When all watchers have been unwatched and to dispose all system resources
SC_TRY(fileSystemWatcher.close());

Member Function Documentation

◆ windowsGetOverlapped()

template<typename T_AsyncEventLoop >
virtual void * SC::FileSystemWatcherAsyncT< T_AsyncEventLoop >::windowsGetOverlapped ( FolderWatcher & watcher)
inlineoverrideprotectedvirtual

◆ windowsStartFolderFilePoll()

template<typename T_AsyncEventLoop >
virtual Result SC::FileSystemWatcherAsyncT< T_AsyncEventLoop >::windowsStartFolderFilePoll ( FolderWatcher & watcher,
void * handle )
inlineoverrideprotectedvirtual

◆ windowsStopFolderFilePoll()

template<typename T_AsyncEventLoop >
virtual Result SC::FileSystemWatcherAsyncT< T_AsyncEventLoop >::windowsStopFolderFilePoll ( FolderWatcher & watcher)
inlineoverrideprotectedvirtual

The documentation for this struct was generated from the following file: