MCPcopy Create free account
hub / github.com/OpenSteam001/OpenSteamTool / WatcherThread

Function WatcherThread

src/Utils/Config/ConfigFileWatcher.cpp:81–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void WatcherThread() {
82 const std::filesystem::path configPath(g_configPath);
83 const std::filesystem::path dirPath = configPath.parent_path();
84 const std::string targetFileName = configPath.filename().string();
85
86 OSTPlatform::DirectoryWatch::Watch watch;
87 if (!watch.Open(dirPath.string(), 4096)) {
88 LOG_WARN("Failed to open config watch directory: {}", dirPath.string());
89 return;
90 }
91 if (!watch.IssueRead()) {
92 return;
93 }
94
95 LOG_INFO("Watching config file: {}", g_configPath);
96
97 OSTPlatform::DirectoryWatch::Watch* watchPtr = &watch;
98 std::vector<OSTPlatform::DirectoryWatch::Watch*> watches{watchPtr};
99
100 auto drainEvent = [&]() {
101 bool changed = ContainsConfigChange(watch.Drain(), targetFileName);
102 watch.IssueRead();
103 return changed;
104 };
105
106 while (g_running) {
107 auto waitResult = OSTPlatform::DirectoryWatch::WaitAny(watches, 1000);
108
109 if (!g_running) break;
110 if (waitResult.status == OSTPlatform::DirectoryWatch::WaitStatus::Timeout) continue;
111 if (waitResult.status != OSTPlatform::DirectoryWatch::WaitStatus::Signaled) continue;
112
113 bool changed = drainEvent();
114 while (g_running) {
115 auto debounceResult = OSTPlatform::DirectoryWatch::WaitAny(watches, kDebounceMs);
116 if (!g_running) break;
117 if (debounceResult.status == OSTPlatform::DirectoryWatch::WaitStatus::Timeout) break;
118 if (debounceResult.status != OSTPlatform::DirectoryWatch::WaitStatus::Signaled) break;
119 changed = drainEvent() || changed;
120 }
121
122 if (changed) {
123 ReloadConfig();
124 }
125 }
126
127 watch.Cancel();
128 LOG_INFO("Config watcher stopped");
129}
130
131} // namespace
132

Callers

nothing calls this directly

Calls 7

ContainsConfigChangeFunction · 0.85
WaitAnyFunction · 0.85
ReloadConfigFunction · 0.85
OpenMethod · 0.80
IssueReadMethod · 0.80
DrainMethod · 0.80
CancelMethod · 0.80

Tested by

no test coverage detected