Move PluginMonitor out of TLuaEngine

This commit is contained in:
Lion Kortlepel
2022-05-26 20:59:53 +02:00
parent f06f31c2a0
commit 36547d1e9e
7 changed files with 110 additions and 84 deletions

View File

@@ -16,6 +16,8 @@ extern TSentry Sentry;
#include <zlib.h>
#include <doctest/doctest.h>
#include <filesystem>
namespace fs = std::filesystem;
#include "Compat.h"

View File

@@ -60,20 +60,7 @@ struct TLuaChunk {
std::string PluginPath;
};
class TPluginMonitor : IThreaded {
public:
TPluginMonitor(const fs::path& Path, TLuaEngine& Engine, std::atomic_bool& Shutdown);
void operator()();
private:
TLuaEngine& mEngine;
fs::path mPath;
std::atomic_bool& mShutdown;
std::unordered_map<std::string, fs::file_time_type> mFileTimes;
};
class TLuaEngine : IThreaded, public std::enable_shared_from_this<TLuaEngine> {
class TLuaEngine : public std::enable_shared_from_this<TLuaEngine>, IThreaded {
public:
enum CallStrategy : int {
BestEffort,
@@ -245,7 +232,6 @@ private:
TNetwork* mNetwork;
TServer* mServer;
TPluginMonitor mPluginMonitor;
std::atomic_bool mShutdown { false };
fs::path mResourceServerPath;
std::vector<std::shared_ptr<TLuaPlugin>> mLuaPlugins;

23
include/TPluginMonitor.h Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include "Common.h"
#include "IThreaded.h"
#include <atomic>
#include <memory>
#include <unordered_map>
class TLuaEngine;
class TPluginMonitor : IThreaded, public std::enable_shared_from_this<TPluginMonitor> {
public:
TPluginMonitor(const fs::path& Path, std::shared_ptr<TLuaEngine> Engine);
void operator()();
private:
std::shared_ptr<TLuaEngine> mEngine;
fs::path mPath;
std::atomic_bool mShutdown;
std::unordered_map<std::string, fs::file_time_type> mFileTimes;
};