载入中...
搜索中...
未找到
HotReload.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Module.h"
6
7#include <atomic>
8#include <condition_variable>
9#include <cstdint>
10#include <deque>
11#include <map>
12#include <mutex>
13#include <string>
14#include <thread>
15#include <unordered_map>
16#include <vector>
17
18namespace eve::filesystem {
19
37public:
39
41 HotReload() = default;
43 ~HotReload() override;
44
50 void bind(std::string path, std::string kind = "auto");
52 void unbind(std::string path);
53
55 bool tryReload(std::string path);
56
67 int watchTree(std::string root = ".");
68
73 bool watchNewDirectory(std::string path);
74
84 bool startRemoteSync(std::string url, int pollMs = 1000);
85
88 void stopRemoteSync();
89
96 void setRemoteHotDir(std::string dir);
97
100 bool isRemoteSyncing() const;
101
104 std::string remoteSyncStatus() const;
105
111 std::string pollRemoteChange();
112
114 static std::string normalizePath(std::string path);
115
116private:
117 struct RemoteFile {
118 std::string path;
119 int64_t size = -1;
120 int64_t mtime = -1;
121 };
122
123 // --- Remote sync internals ---
124
126 std::string ensureHotDir();
127
129 bool mountHotDir();
130
132 bool fetchManifest(std::vector<RemoteFile> &out);
133
135 bool downloadFile(const std::string &relPath);
136
138 void applyManifest(const std::vector<RemoteFile> &manifest);
139
141 std::map<std::string, std::pair<int64_t, int64_t>> loadRecord() const;
142 void saveRecord(const std::map<std::string, std::pair<int64_t, int64_t>> &record) const;
143
144 void syncLoop(int pollMs);
145
146 void queueChange(std::string path);
147
148 std::unordered_map<std::string, std::string> bindings_; // norm path → kind
149
150 // Remote sync state (guarded by syncMu_).
151 mutable std::mutex syncMu_;
152 std::thread syncThread_;
153 std::condition_variable syncCv_;
154 std::atomic<bool> syncRunning_{false};
155 bool syncStarted_ = false;
156 bool hotDirMounted_ = false;
157 std::string syncUrl_;
158 mutable std::string syncStatus_ = "idle";
159 mutable std::deque<std::string> changedQueue_;
160 std::string hotDir_;
161};
162
163} // namespace eve::filesystem
int root
Definition AnimSmr.cpp:119
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
TokenKind kind
std::string path
Definition PlayHost.cpp:110
float size
Definition TreeMesh.cpp:156
V3 dir
Definition TreeMesh.cpp:150
EVENGINE_API_FOUNDATION public API.
Definition Module.h:46
Path→reload dispatcher for soft hot reload. Driven from load.nut via pollWatch → tryReload; also used...
Definition HotReload.h:36
HotReload()=default
Hot reload.