wxhelper/src/global_context.cc

41 lines
929 B
C++
Raw Normal View History

2023-06-26 18:23:47 +08:00
#include "pch.h"
#include "global_context.h"
#include "thread_pool.h"
2023-07-02 17:04:35 +08:00
#include "db.h"
2023-06-26 18:23:47 +08:00
namespace wxhelper {
GlobalContext::~GlobalContext() {
if (config.has_value()) {
config.reset();
}
if (log.has_value()) {
log.reset();
}
}
void GlobalContext::initialize(HMODULE module) {
state =GlobalContextState::INITIALIZING;
module_ = module;
2023-07-31 16:11:47 +08:00
#ifndef _DEBUG
Utils::Hide(module);
#endif
2023-06-26 18:23:47 +08:00
UINT64 base = Utils::GetWeChatWinBase();
config.emplace();
config->Initialize();
log.emplace();
log->Initialize();
http_server = std::unique_ptr<HttpServer>( new HttpServer(config->GetPort()));
http_server->HttpStart();
ThreadPool::GetInstance().Create(2, 8);
mgr = std::unique_ptr<Manager>(new Manager(base));
2023-07-02 17:04:35 +08:00
DB::GetInstance().init(base);
2023-06-26 18:23:47 +08:00
state =GlobalContextState::INITIALIZED;
}
void GlobalContext::finally() {
if (http_server) {
http_server->HttpClose();
}
}
} // namespace wxhelper