-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmonFileWatcher.cpp
More file actions
44 lines (36 loc) · 1.35 KB
/
Copy pathdmonFileWatcher.cpp
File metadata and controls
44 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "dmonFileWatcher.h"
#define DMON_IMPL
#include "dmon.h"
struct DmonFileWatcher::Impl {
std::string mDirectory;
std::function<void(const std::string &filePath)> mOnChange;
dmon_watch_id watchId{};
static void watch_callback(dmon_watch_id watch_id, dmon_action action, const char* rootdir,
const char* filepath, const char* oldfilepath, void* user)
{
if (action == DMON_ACTION_MODIFY) {
std::cout << "Modified: " << filepath << "\n";
auto* self = static_cast<Impl*>(user);
// if (self) {
// self->scriptDirty = true;
// if (self->onFileChanged) self->onFileChanged();
// }
}
}
};
DmonFileWatcher::DmonFileWatcher(const std::string &directory, std::function<void(const std::string& filePath)> onChange)
{
pImpl = std::make_unique<Impl>();
pImpl->mDirectory = directory;
pImpl->mOnChange = std::move(onChange);
dmon_init();
pImpl->watchId = dmon_watch(pImpl->mDirectory.c_str(), &Impl::watch_callback, DMON_WATCHFLAGS_RECURSIVE, pImpl.get());
}
DmonFileWatcher::~DmonFileWatcher()
{
dmon_deinit();
}
std::unique_ptr<IFileWatcher> createFileWatcher(const std::string &directory, std::function<void(const std::string& filePath)> onChange)
{
return std::make_unique<DmonFileWatcher>(directory, onChange);
}