From 459cd3d0e512a1166b3a09233c22b7357b514760 Mon Sep 17 00:00:00 2001 From: saturneric Date: Tue, 17 Oct 2023 23:45:10 +0800 Subject: refactor: move module system to core and make it work --- src/core/module/Module.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/core/module/Module.cpp (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp new file mode 100644 index 00000000..d84b74af --- /dev/null +++ b/src/core/module/Module.cpp @@ -0,0 +1,107 @@ +/** + * Copyright (C) 2021 Saturneric + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see . + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "Module.h" + +#include + +#include "core/module/GlobalModuleContext.h" + +namespace GpgFrontend::Module { + +class Module::Impl { + public: + friend class GlobalModuleContext; + + Impl(ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) + : identifier_((boost::format("__module_%1%") % id).str()), + version_(version), + meta_data_(meta_data) {} + + int GetChannel() { + return get_global_module_context()->GetChannel(self_shared_ptr_); + } + + int GetDefaultChannel() { + return get_global_module_context()->GetDefaultChannel(self_shared_ptr_); + } + + std::optional GetTaskRunner() { + return get_global_module_context()->GetTaskRunner(self_shared_ptr_); + } + + bool ListenEvent(EventIdentifier event) { + return get_global_module_context()->ListenEvent(gpc_get_identifier(), + event); + } + + ModuleIdentifier GetModuleIdentifier() const { return identifier_; } + + void SetGPC(GlobalModuleContextPtr gpc) { gpc_ = gpc; } + + private: + GlobalModuleContextPtr gpc_; + const std::shared_ptr self_shared_ptr_; + const ModuleIdentifier identifier_; + const ModuleVersion version_; + const ModuleMetaData meta_data_; + + ModuleIdentifier gpc_get_identifier() { return identifier_; } + + const GlobalModuleContextPtr get_global_module_context() { + if (gpc_ == nullptr) { + throw std::runtime_error("module is not registered by module manager"); + } + return gpc_; + } +}; + +Module::Module(ModuleIdentifier id, ModuleVersion version, + ModuleMetaData meta_data) + : p_(std::make_unique(id, version, meta_data)) {} + +Module::~Module() = default; + +int Module::getChannel() { return p_->GetChannel(); } + +int Module::getDefaultChannel() { return p_->GetDefaultChannel(); } + +TaskRunnerPtr Module::getTaskRunner() { + return p_->GetTaskRunner().value_or(nullptr); +} + +bool Module::listenEvent(EventIdentifier event) { + return p_->ListenEvent(event); +} + +ModuleIdentifier Module::GetModuleIdentifier() const { + return p_->GetModuleIdentifier(); +} + +void Module::SetGPC(GlobalModuleContextPtr gpc) { p_->SetGPC(gpc); } +} // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3 From 4fa7cc872224014f6e5bc731164c74bfa96db06e Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 18 Oct 2023 02:04:05 +0800 Subject: feat: imporve module system --- src/core/module/Module.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index d84b74af..33525072 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -38,26 +38,25 @@ class Module::Impl { public: friend class GlobalModuleContext; - Impl(ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) - : identifier_((boost::format("__module_%1%") % id).str()), + using ExecCallback = std::function; + + Impl(ModuleRawPtr m_ptr, ModuleIdentifier id, ModuleVersion version, + ModuleMetaData meta_data) + : m_ptr_(m_ptr), + identifier_((boost::format("__module_%1%") % id).str()), version_(version), meta_data_(meta_data) {} - int GetChannel() { - return get_global_module_context()->GetChannel(self_shared_ptr_); - } + int GetChannel() { return get_gpc()->GetChannel(m_ptr_); } - int GetDefaultChannel() { - return get_global_module_context()->GetDefaultChannel(self_shared_ptr_); - } + int GetDefaultChannel() { return get_gpc()->GetDefaultChannel(m_ptr_); } std::optional GetTaskRunner() { - return get_global_module_context()->GetTaskRunner(self_shared_ptr_); + return get_gpc()->GetTaskRunner(m_ptr_); } bool ListenEvent(EventIdentifier event) { - return get_global_module_context()->ListenEvent(gpc_get_identifier(), - event); + return get_gpc()->ListenEvent(GetModuleIdentifier(), event); } ModuleIdentifier GetModuleIdentifier() const { return identifier_; } @@ -66,14 +65,12 @@ class Module::Impl { private: GlobalModuleContextPtr gpc_; - const std::shared_ptr self_shared_ptr_; + Module* m_ptr_; const ModuleIdentifier identifier_; const ModuleVersion version_; const ModuleMetaData meta_data_; - ModuleIdentifier gpc_get_identifier() { return identifier_; } - - const GlobalModuleContextPtr get_global_module_context() { + const GlobalModuleContextPtr get_gpc() { if (gpc_ == nullptr) { throw std::runtime_error("module is not registered by module manager"); } @@ -83,7 +80,7 @@ class Module::Impl { Module::Module(ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) - : p_(std::make_unique(id, version, meta_data)) {} + : p_(std::make_unique(this, id, version, meta_data)) {} Module::~Module() = default; -- cgit v1.2.3 From 216905e2532a79101e987e936fdf8b353b2a4dab Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 18 Oct 2023 17:49:06 +0800 Subject: fix: improve thread and module relation --- src/core/module/Module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index 33525072..e4c40caa 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -38,7 +38,7 @@ class Module::Impl { public: friend class GlobalModuleContext; - using ExecCallback = std::function; + using ExecCallback = std::function; Impl(ModuleRawPtr m_ptr, ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) -- cgit v1.2.3 From 31fc827672a131da020c4b4a0c3c8a145d477835 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 23 Oct 2023 14:29:25 +0800 Subject: feat: improve project structure and add GRT for modules --- src/core/module/Module.cpp | 8 ++++---- 1 file changed, 4 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 e4c40caa..71a91cb8 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -61,16 +61,16 @@ class Module::Impl { ModuleIdentifier GetModuleIdentifier() const { return identifier_; } - void SetGPC(GlobalModuleContextPtr gpc) { gpc_ = gpc; } + void SetGPC(GMCPtr gpc) { gpc_ = gpc; } private: - GlobalModuleContextPtr gpc_; + GMCPtr gpc_; Module* m_ptr_; const ModuleIdentifier identifier_; const ModuleVersion version_; const ModuleMetaData meta_data_; - const GlobalModuleContextPtr get_gpc() { + const GMCPtr get_gpc() { if (gpc_ == nullptr) { throw std::runtime_error("module is not registered by module manager"); } @@ -100,5 +100,5 @@ ModuleIdentifier Module::GetModuleIdentifier() const { return p_->GetModuleIdentifier(); } -void Module::SetGPC(GlobalModuleContextPtr gpc) { p_->SetGPC(gpc); } +void Module::SetGPC(GMCPtr gpc) { p_->SetGPC(gpc); } } // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3 From 8fdeb3af49999f29e017b7f7a70bd36f020ba721 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 23 Oct 2023 18:27:25 +0800 Subject: perf: reduce header includes and improve build speed --- src/core/module/Module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index 71a91cb8..d66773ff 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -28,7 +28,7 @@ #include "Module.h" -#include +#include #include "core/module/GlobalModuleContext.h" -- cgit v1.2.3 From fa2e87a48acbc32650ca9db073b991729dfba622 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Tue, 24 Oct 2023 21:22:13 +0800 Subject: feat: use module instead of integrated code at version checking task --- src/core/module/Module.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index d66773ff..12de004a 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -29,6 +29,7 @@ #include "Module.h" #include +#include #include "core/module/GlobalModuleContext.h" -- cgit v1.2.3 From fd46d4667611c0db9cea3f06205727399b6fb5fd Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 29 Oct 2023 02:46:15 +0800 Subject: refactor: start to tidy up code using clang-tidy --- src/core/module/Module.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index 12de004a..d66773ff 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -29,7 +29,6 @@ #include "Module.h" #include -#include #include "core/module/GlobalModuleContext.h" -- cgit v1.2.3 From 9d16c9d5dfcd1171d713c3ba87a69d0f0fac4f33 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 29 Nov 2023 17:49:54 +0800 Subject: fix: repair gnupg info listing funtion --- src/core/module/Module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index d66773ff..642aadf8 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -43,7 +43,7 @@ class Module::Impl { Impl(ModuleRawPtr m_ptr, ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) : m_ptr_(m_ptr), - identifier_((boost::format("__module_%1%") % id).str()), + identifier_(id), version_(version), meta_data_(meta_data) {} -- cgit v1.2.3 From f9a49043c35e73fc2d4ffb3ed9b39c33849c43b3 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 15 Dec 2023 21:14:17 +0800 Subject: fix: slove threading and memory issues --- src/core/module/Module.cpp | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index 642aadf8..b19e36e4 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -29,6 +29,7 @@ #include "Module.h" #include +#include #include "core/module/GlobalModuleContext.h" @@ -43,34 +44,38 @@ class Module::Impl { Impl(ModuleRawPtr m_ptr, ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) : m_ptr_(m_ptr), - identifier_(id), - version_(version), - meta_data_(meta_data) {} + identifier_(std::move(id)), + version_(std::move(version)), + meta_data_(std::move(meta_data)) {} - int GetChannel() { return get_gpc()->GetChannel(m_ptr_); } + auto GetChannel() -> int { return get_gpc()->GetChannel(m_ptr_); } - int GetDefaultChannel() { return get_gpc()->GetDefaultChannel(m_ptr_); } + auto GetDefaultChannel() -> int { + return get_gpc()->GetDefaultChannel(m_ptr_); + } - std::optional GetTaskRunner() { + auto GetTaskRunner() -> std::optional { return get_gpc()->GetTaskRunner(m_ptr_); } - bool ListenEvent(EventIdentifier event) { - return get_gpc()->ListenEvent(GetModuleIdentifier(), event); + auto ListenEvent(EventIdentifier event) -> bool { + return get_gpc()->ListenEvent(GetModuleIdentifier(), std::move(event)); } - ModuleIdentifier GetModuleIdentifier() const { return identifier_; } + [[nodiscard]] auto GetModuleIdentifier() const -> ModuleIdentifier { + return identifier_; + } - void SetGPC(GMCPtr gpc) { gpc_ = gpc; } + void SetGPC(GlobalModuleContext* gpc) { gpc_ = gpc; } private: - GMCPtr gpc_; + GlobalModuleContext* gpc_; Module* m_ptr_; const ModuleIdentifier identifier_; const ModuleVersion version_; const ModuleMetaData meta_data_; - const GMCPtr get_gpc() { + auto get_gpc() -> GlobalModuleContext* { if (gpc_ == nullptr) { throw std::runtime_error("module is not registered by module manager"); } @@ -84,21 +89,21 @@ Module::Module(ModuleIdentifier id, ModuleVersion version, Module::~Module() = default; -int Module::getChannel() { return p_->GetChannel(); } +auto Module::getChannel() -> int { return p_->GetChannel(); } -int Module::getDefaultChannel() { return p_->GetDefaultChannel(); } +auto Module::getDefaultChannel() -> int { return p_->GetDefaultChannel(); } -TaskRunnerPtr Module::getTaskRunner() { +auto Module::getTaskRunner() -> TaskRunnerPtr { return p_->GetTaskRunner().value_or(nullptr); } -bool Module::listenEvent(EventIdentifier event) { - return p_->ListenEvent(event); +auto Module::listenEvent(EventIdentifier event) -> bool { + return p_->ListenEvent(std::move(event)); } -ModuleIdentifier Module::GetModuleIdentifier() const { +auto Module::GetModuleIdentifier() const -> ModuleIdentifier { return p_->GetModuleIdentifier(); } -void Module::SetGPC(GMCPtr gpc) { p_->SetGPC(gpc); } +void Module::SetGPC(GlobalModuleContext* gpc) { p_->SetGPC(gpc); } } // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3 From 37215a895a649345165027971690dfdcd9106a32 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 15 Dec 2023 21:53:03 -0800 Subject: fix: use secure memory management at impl class --- src/core/module/Module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index b19e36e4..e62d0ee7 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -85,7 +85,7 @@ class Module::Impl { Module::Module(ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) - : p_(std::make_unique(this, id, version, meta_data)) {} + : p_(SecureCreateUniqueObject(this, id, version, meta_data)) {} Module::~Module() = default; -- cgit v1.2.3 From bf538056b24a68b8fd235b1c50991ee8eb46a776 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 12 Jan 2024 14:02:37 +0800 Subject: refactor: use QString instead of std::string and improve threading system --- src/core/module/Module.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index e62d0ee7..241b448e 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -28,7 +28,6 @@ #include "Module.h" -#include #include #include "core/module/GlobalModuleContext.h" -- cgit v1.2.3 From 4994f4eaa1211d402b791660ad6221154a4c2405 Mon Sep 17 00:00:00 2001 From: saturneric Date: Tue, 16 Jan 2024 11:49:50 +0800 Subject: fix: make task and threading system safer --- src/core/module/Module.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index 241b448e..cab72a9a 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -28,8 +28,6 @@ #include "Module.h" -#include - #include "core/module/GlobalModuleContext.h" namespace GpgFrontend::Module { -- cgit v1.2.3 From 37848811b6c8ca6c2a707431ec077c8098918afe Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 18 Jan 2024 00:14:13 +0800 Subject: fix: improve code quality, docs and ci files --- src/core/module/Module.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index cab72a9a..c37b2262 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -40,7 +40,8 @@ class Module::Impl { Impl(ModuleRawPtr m_ptr, ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) - : m_ptr_(m_ptr), + : gpc_(nullptr), + m_ptr_(m_ptr), identifier_(std::move(id)), version_(std::move(version)), meta_data_(std::move(meta_data)) {} -- cgit v1.2.3 From 38e4a656dbdd14cf7a6a91cda6c814b5290acd93 Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 18 Jan 2024 13:32:25 +0800 Subject: fix: slove codacy issues --- src/core/module/Module.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/core/module/Module.cpp') diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index c37b2262..9076dc2c 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -40,8 +40,7 @@ class Module::Impl { Impl(ModuleRawPtr m_ptr, ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) - : gpc_(nullptr), - m_ptr_(m_ptr), + : m_ptr_(m_ptr), identifier_(std::move(id)), version_(std::move(version)), meta_data_(std::move(meta_data)) {} @@ -49,7 +48,7 @@ class Module::Impl { auto GetChannel() -> int { return get_gpc()->GetChannel(m_ptr_); } auto GetDefaultChannel() -> int { - return get_gpc()->GetDefaultChannel(m_ptr_); + return GlobalModuleContext::GetDefaultChannel(m_ptr_); } auto GetTaskRunner() -> std::optional { @@ -67,7 +66,7 @@ class Module::Impl { void SetGPC(GlobalModuleContext* gpc) { gpc_ = gpc; } private: - GlobalModuleContext* gpc_; + GlobalModuleContext* gpc_{}; Module* m_ptr_; const ModuleIdentifier identifier_; const ModuleVersion version_; @@ -82,7 +81,7 @@ class Module::Impl { }; Module::Module(ModuleIdentifier id, ModuleVersion version, - ModuleMetaData meta_data) + const ModuleMetaData& meta_data) : p_(SecureCreateUniqueObject(this, id, version, meta_data)) {} Module::~Module() = default; -- cgit v1.2.3