From c1f5b3336836e15d193582e9b8f3e044f7d8bc1b Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 29 Feb 2024 18:15:57 +0800 Subject: feat: add module controller and continue to work on module system 1. speed up building by reducing build info sheader including 2. add module controller 3. continue to work on module system --- src/core/module/Module.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index e943ab09..0534d261 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -29,6 +29,7 @@ #include "Module.h" #include "core/module/GlobalModuleContext.h" +#include "core/utils/IOUtils.h" namespace GpgFrontend::Module { @@ -47,7 +48,10 @@ class Module::Impl { good_(true) {} Impl(ModuleRawPtr m_ptr, QLibrary& module_library) - : m_ptr_(m_ptr), good_(false) { + : m_ptr_(m_ptr), + module_hash_(CalculateBinaryChacksum(module_library.fileName())), + module_library_path_(module_library.fileName()), + good_(false) { for (auto& required_symbol : module_required_symbols_) { *required_symbol.pointer = reinterpret_cast(module_library.resolve(required_symbol.name)); @@ -59,13 +63,26 @@ class Module::Impl { } } - SPDLOG_INFO("module loaded, name: {}, verison: {}", - QString::fromUtf8(get_id_api_()), - QString::fromUtf8(get_version_api_())); + GF_CORE_LOG_INFO("module loaded, id: {}, verison: {}, hash: {}, path: {}", + QString::fromUtf8(get_id_api_()), + QString::fromUtf8(get_version_api_()), module_hash_, + module_library_path_); identifier_ = QString::fromUtf8(get_id_api_()); version_ = QString::fromUtf8(get_version_api_()); + ::ModuleMetaData* p_meta_data = get_metadata_api_(); + ::ModuleMetaData* l_meta_data; + + GF_CORE_LOG_DEBUG("AAAAAA: {}", static_cast(p_meta_data)); + while (p_meta_data != nullptr) { + meta_data_[QString::fromUtf8(p_meta_data->key)] = + QString::fromUtf8(p_meta_data->value); + l_meta_data = p_meta_data; + p_meta_data = p_meta_data->next; + SecureFree(l_meta_data); + } + good_ = true; } @@ -116,6 +133,20 @@ class Module::Impl { return identifier_; } + [[nodiscard]] auto GetModuleVersion() const -> ModuleVersion { + return version_; + } + + [[nodiscard]] auto GetModuleMetaData() const -> ModuleMetaData { + return meta_data_; + } + + [[nodiscard]] auto GetModulePath() const -> QString { + return module_library_path_; + } + + [[nodiscard]] auto GetModuleHash() const -> QString { return module_hash_; } + void SetGPC(GlobalModuleContext* gpc) { gpc_ = gpc; } private: @@ -124,6 +155,8 @@ class Module::Impl { ModuleIdentifier identifier_; ModuleVersion version_; ModuleMetaData meta_data_; + QString module_hash_; + QString module_library_path_; bool good_; ModuleAPIGetModuleID get_id_api_; @@ -198,5 +231,21 @@ auto Module::GetModuleIdentifier() const -> ModuleIdentifier { return p_->GetModuleIdentifier(); } +[[nodiscard]] auto Module::GetModuleVersion() const -> ModuleVersion { + return p_->GetModuleVersion(); +} + +[[nodiscard]] auto Module::GetModuleMetaData() const -> ModuleMetaData { + return p_->GetModuleMetaData(); +} + +[[nodiscard]] auto Module::GetModulePath() const -> QString { + return p_->GetModulePath(); +} + +[[nodiscard]] auto Module::GetModuleHash() const -> QString { + return p_->GetModuleHash(); +} + void Module::SetGPC(GlobalModuleContext* gpc) { p_->SetGPC(gpc); } } // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3