载入中...
搜索中...
未找到
FileWatch.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/config.h"
6
7#ifndef EVENGINE_WEBGPU
8#include <Poco/DirectoryWatcher.h>
9#endif
10
11#include <chrono>
12#include <deque>
13#include <memory>
14#include <mutex>
15#include <string>
16#include <unordered_map>
17
18namespace eve::filesystem {
19
27public:
29 struct Event {
30 std::string kind; // "added" | "removed" | "modified" | "movedFrom" | "movedTo"
31 std::string path; // report path (usually the path passed to watch())
32 std::string realPath;
33 };
34
36 ~FileWatch();
37
38 FileWatch(const FileWatch &) = delete;
39 FileWatch &operator=(const FileWatch &) = delete;
40
47 bool add(const std::string &realDir, const std::string &filterName, const std::string &reportPath,
48 int scanInterval = 1);
49
51 bool remove(const std::string &reportPath);
52 void clear();
53
54 int count() const;
55
57 bool poll(Event &out);
58
59private:
60 struct DirWatch;
61 struct PendingEvent {
62 Event event;
63 std::chrono::steady_clock::time_point readyAt;
64 };
65
66#ifndef EVENGINE_WEBGPU
67 void onAdded(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
68 void onRemoved(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
69 void onModified(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
70 void onMovedFrom(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
71 void onMovedTo(const void *sender, const Poco::DirectoryWatcher::DirectoryEvent &event);
72
74 void unsubscribeDelegates(DirWatch *dw);
75#endif
76
77 void handlePocoEvent(const std::string &kind, const std::string &itemPath);
78 void enqueue(Event event);
79
80 mutable std::mutex mu_;
81 std::deque<PendingEvent> queue_;
82 std::unordered_map<std::string, std::unique_ptr<DirWatch>> byDir_;
83 std::unordered_map<std::string, std::string> reportToDir_;
84};
85
86} // namespace eve::filesystem
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
TokenKind kind
std::uint32_t count
OS directory watch with a main-thread event queue. Desktop/mobile: backed by Poco::DirectoryWatcher (...
Definition FileWatch.h:26
FileWatch(const FileWatch &)=delete
FileWatch & operator=(const FileWatch &)=delete