载入中...
搜索中...
未找到
HotReload.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
4
5
6#include "common/Module.h"
7
8#include <atomic>
9#include <condition_variable>
10#include <cstdint>
11#include <deque>
12#include <map>
13#include <mutex>
14#include <string>
15#include <thread>
16#include <unordered_map>
17#include <vector>
18
19namespace eve::filesystem {
20
38public:
40
42 HotReload() = default;
44 ~HotReload() override;
45
51 void bind(std::string path, std::string kind = "auto");
53 void unbind(std::string path);
54
56 bool tryReload(std::string path);
57
68 int watchTree(std::string root = ".");
69
74 bool watchNewDirectory(std::string path);
75
85 bool startRemoteSync(std::string url, int pollMs = 1000);
86
89 void stopRemoteSync();
90
97 void setRemoteHotDir(std::string dir);
98
101 bool isRemoteSyncing() const;
102
105 std::string remoteSyncStatus() const;
106
112 std::string pollRemoteChange();
113
115 static std::string normalizePath(std::string path);
116
117private:
118 struct RemoteFile {
119 std::string path;
120 int64_t size = -1;
121 int64_t mtime = -1;
122 };
123
124 // --- Remote sync internals ---
125
127 std::string ensureHotDir();
128
130 bool mountHotDir();
131
133 bool fetchManifest(std::vector<RemoteFile> &out);
134
136 bool downloadFile(const std::string &relPath);
137
139 void applyManifest(const std::vector<RemoteFile> &manifest);
140
142 std::map<std::string, std::pair<int64_t, int64_t>> loadRecord() const;
143 void saveRecord(const std::map<std::string, std::pair<int64_t, int64_t>> &record) const;
144
145 void syncLoop(int pollMs);
146
147 void queueChange(std::string path);
148
149 std::unordered_map<std::string, std::string> bindings_; // norm path → kind
150
151 // Remote sync state (guarded by syncMu_).
152 mutable std::mutex syncMu_;
153 std::thread syncThread_;
154 std::condition_variable syncCv_;
155 std::atomic<bool> syncRunning_{false};
156 bool syncStarted_ = false;
157 bool hotDirMounted_ = false;
158 std::string syncUrl_;
159 mutable std::string syncStatus_ = "idle";
160 mutable std::deque<std::string> changedQueue_;
161 std::string hotDir_;
162};
163
164} // namespace eve::filesystem
int root
Definition AnimSmr.cpp:119
ScriptComponentRecord record
Definition ECS.cpp:228
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::string path
Definition PlayHost.cpp:111
ScriptStructure out
std::string kind
Share string attribute map operations through the Windows Foundation DLL.
float size
Definition TreeMesh.cpp:158
V3 dir
Definition TreeMesh.cpp:151
EVENGINE_API_FOUNDATION public API.
Definition Module.h:48
Path→reload dispatcher for soft hot reload. Driven from load.nut via pollWatch → tryReload; also used...
Definition HotReload.h:37
HotReload()=default
Hot reload.