]> git.tdb.fi Git - libs/core.git/blob - source/fs/filemonitor.h
Check errors from CreateSemaphore
[libs/core.git] / source / fs / filemonitor.h
1 #ifndef MSP_FS_FILEMONITOR_H_
2 #define MSP_FS_FILEMONITOR_H_
3
4 #include <msp/core/mspcore_api.h>
5 #include <msp/core/noncopyable.h>
6 #include <msp/fs/path.h>
7 #include <msp/io/eventdispatcher.h>
8
9 namespace Msp {
10 namespace FS {
11
12 class MSPCORE_API FileMonitor: NonCopyable
13 {
14 private:
15         struct Private;
16
17         struct MonitoredFile
18         {
19                 FS::Path path;
20                 bool modified = false;
21                 int tag = -1;
22         };
23
24 public:
25         sigc::signal<void, const FS::Path &> signal_file_modified;
26
27 private:
28         Private *priv = nullptr;
29         IO::EventDispatcher *event_disp = nullptr;
30         std::vector<MonitoredFile> files;
31
32 public:
33         FileMonitor();
34         ~FileMonitor();
35
36         void add_file(const FS::Path &);
37         void remove_file(const FS::Path &);
38 private:
39         void prepare_file(MonitoredFile &);
40         void cleanup_file(MonitoredFile &);
41
42 public:
43         void use_event_dispatcher(IO::EventDispatcher &);
44 private:
45         void platform_use_event_dispatcher();
46
47 public:
48         void tick();
49         void tick(const Msp::Time::TimeDelta &);
50 };
51
52 } // namespace FS
53 } // namespace Msp
54
55 #endif