/* Subscribe for notifications about file changes. When a file changes, we'll call observer->OnFileChanged(). We take ownership of observer object. Returns a cancellation token that can be used in FileWatcherUnsubscribe(). That way we can support multiple callers subscribing to the same file. */ WatchedFile* FileWatcherSubscribe(const WCHAR* path, const std::function<void()>& onFileChangedCb) { lf(L"FileWatcherSubscribe() path: %s", path); if (!file::Exists(path)) { return nullptr; } StartThreadIfNecessary(); ScopedCritSec cs(&g_threadCritSec); return NewWatchedFile(path, onFileChangedCb); }
/* Subscribe for notifications about file changes. When a file changes, we'll call observer->OnFileChanged(). We take ownership of observer object. Returns a cancellation token that can be used in FileWatcherUnsubscribe(). That way we can support multiple callers subscribing for the same file. */ FileWatcherToken FileWatcherSubscribe(const WCHAR *path, FileChangeObserver *observer) { if (!file::Exists(path)) { delete observer; return INVALID_TOKEN; } // TODO: if the file is on a network drive we should periodically check // it ourselves, because ReadDirectoryChangesW() // doesn't work in that case WatchedFile *wf = NewWatchedFile(path, observer); return wf->token; }
/* Subscribe for notifications about file changes. When a file changes, we'll call observer->OnFileChanged(). We take ownership of observer object. Returns a cancellation token that can be used in FileWatcherUnsubscribe(). That way we can support multiple callers subscribing to the same file. */ WatchedFile *FileWatcherSubscribe(const WCHAR *path, FileChangeObserver *observer) { CrashIf(!observer); lf(L"FileWatcherSubscribe() path: %s", path); if (!file::Exists(path)) { delete observer; return nullptr; } StartThreadIfNecessary(); ScopedCritSec cs(&g_threadCritSec); return NewWatchedFile(path, observer); }