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