blob: 6b0b41ddfd435dd3cecf43147cdbcb8e96af65b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "plugins/interfaces/interface.h"
#include "ISys.h"
#include "plugins/plugins.h"
#include "plugins/pluginmanager.h"
class CSys : public ISys
{
public:
void Log(HMODULE handle, LogLevel level, char* msg)
{
spdlog::level::level_enum spdLevel;
switch (level)
{
case LogLevel::WARN:
spdLevel = spdlog::level::level_enum::warn;
break;
case LogLevel::ERR:
spdLevel = spdlog::level::level_enum::err;
break;
default:
NS::log::PLUGINSYS->warn("Attempted to log with invalid level {}. Defaulting to info", (int)level);
case LogLevel::INFO:
spdLevel = spdlog::level::level_enum::info;
break;
}
std::optional<Plugin> plugin = g_pPluginManager->GetPlugin(handle);
if (plugin)
{
plugin->Log(spdLevel, msg);
}
else
{
NS::log::PLUGINSYS->warn("Attempted to log message '{}' with invalid plugin handle {}", msg, static_cast<void*>(handle));
}
}
void Unload(HMODULE handle)
{
std::optional<Plugin> plugin = g_pPluginManager->GetPlugin(handle);
if (plugin)
{
plugin->Unload();
}
else
{
NS::log::PLUGINSYS->warn("Attempted to unload plugin with invalid handle {}", static_cast<void*>(handle));
}
}
void Reload(HMODULE handle)
{
std::optional<Plugin> plugin = g_pPluginManager->GetPlugin(handle);
if (plugin)
{
plugin->Reload();
}
else
{
NS::log::PLUGINSYS->warn("Attempted to reload plugin with invalid handle {}", static_cast<void*>(handle));
}
}
};
EXPOSE_SINGLE_INTERFACE(CSys, ISys, SYS_VERSION);
|