载入中...
搜索中...
未找到
FileWatch.h
浏览该文件的文档.
1#pragma once
2
3#include "common/config.h"
4
5#ifndef EVENGINE_WEBGPU
6#include <Poco/DirectoryWatcher.h>
7#endif
8
9#include <memory>
10#include <mutex>
11#include <string>
12#include <unordered_map>
13#include <vector>
14
15namespace eve::filesystem {
16
23class FileWatch {
24public:
25 struct Event {
26 std::string kind; // "added" | "removed" | "modified" | "movedFrom" | "movedTo"
27 std::string path; // report path (usually the path passed to watch())
28 std::string realPath;
29 };
30
32 ~FileWatch();
33
34 FileWatch(const FileWatch &) = delete;
35 FileWatch &operator=(const FileWatch &) = delete;
36
43 bool add(const std::string &realDir, const std::string &filterName, const std::string &reportPath,
44 int scanInterval = 1);
45
47 bool remove(const std::string &reportPath);
48 void clear();
49
50 int count() const;
51
53 bool poll(Event &out);
54
55private:
56 struct DirWatch;
57
58#ifndef EVENGINE_WEBGPU
59 void onAdded(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
60 void onRemoved(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
61 void onModified(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
62 void onMovedFrom(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
63 void onMovedTo(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
64
66 void unsubscribeDelegates(DirWatch *dw);
67#endif
68
69 void handlePocoEvent(const std::string &kind, const std::string &itemPath);
70
71 mutable std::mutex mu_;
72 std::vector<Event> queue_;
73 std::unordered_map<std::string, std::unique_ptr<DirWatch>> byDir_;
74 std::unordered_map<std::string, std::string> reportToDir_;
75};
76
77} // namespace eve::filesystem
Tok kind
OS directory watch with a main-thread event queue. Desktop/mobile: backed by Poco::DirectoryWatcher (...
Definition FileWatch.h:23
bool add(const std::string &realDir, const std::string &filterName, const std::string &reportPath, int scanInterval=1)
Definition FileWatch.cpp:64
bool poll(Event &out)
Pop one event; false if empty.
FileWatch(const FileWatch &)=delete
FileWatch & operator=(const FileWatch &)=delete
bool remove(const std::string &reportPath)
Remove by reportPath previously passed to add().