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/ModuleManager.cpp | 111 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/core/module/ModuleManager.cpp (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp new file mode 100644 index 00000000..dc31072b --- /dev/null +++ b/src/core/module/ModuleManager.cpp @@ -0,0 +1,111 @@ +/** + * 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 "ModuleManager.h" + +#include "core/module/GlobalModuleContext.h" +#include "core/module/Module.h" +#include "core/thread/TaskRunner.h" + +namespace GpgFrontend::Module { + +ModuleMangerPtr ModuleManager::g_ = nullptr; + +class ModuleManager::Impl { + public: + Impl() + : task_runner_(std::make_shared()), + gpc_(std::make_shared(task_runner_)) { + task_runner_->start(); + } + + void RegisterModule(ModulePtr module) { + task_runner_->PostTask(new Thread::Task( + std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { + module->SetGPC(gpc_); + gpc_->RegisterModule(module); + return 0; + }), + __func__, nullptr, true)); + } + + void TriggerEvent(EventRefrernce event) { + task_runner_->PostTask(new Thread::Task( + std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { + gpc_->TriggerEvent(event); + return 0; + }), + __func__, nullptr, true)); + } + + void ActiveModule(ModuleIdentifier identifier) { + task_runner_->PostTask(new Thread::Task( + std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { + gpc_->ActiveModule(identifier); + return 0; + }), + __func__, nullptr, true)); + } + + std::optional GetTaskRunner(ModuleIdentifier module_id) { + return gpc_->GetTaskRunner(module_id); + } + + private: + static ModuleMangerPtr global_module_manager_; + TaskRunnerPtr task_runner_; + GlobalModuleContextPtr gpc_; +}; + +ModuleManager::ModuleManager() : p_(std::make_unique()) {} + +ModuleManager::~ModuleManager() = default; + +ModuleMangerPtr ModuleManager::GetInstance() { + if (g_ == nullptr) g_ = std::shared_ptr(new ModuleManager()); + return g_; +} + +void ModuleManager::RegisterModule(ModulePtr module) { + return p_->RegisterModule(module); +} + +void ModuleManager::TriggerEvent(EventRefrernce event) { + return p_->TriggerEvent(event); +} + +void ModuleManager::ActiveModule(ModuleIdentifier identifier) { + return p_->ActiveModule(identifier); +} + +std::optional ModuleManager::GetTaskRunner( + ModuleIdentifier module_id) { + return p_->GetTaskRunner(module_id); +} + +} // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3 From 76fda183d4c1067ab1735965e9bde3c7b29d1345 Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 18 Oct 2023 20:54:02 +0800 Subject: feat: simplify the thread system and improve its stability --- src/core/module/ModuleManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index dc31072b..b9e73721 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -41,7 +41,7 @@ class ModuleManager::Impl { Impl() : task_runner_(std::make_shared()), gpc_(std::make_shared(task_runner_)) { - task_runner_->start(); + task_runner_->Start(); } void RegisterModule(ModulePtr module) { -- cgit v1.2.3 From 025c268f91ee1deab17891f00dc8c90c4770224f Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 19 Oct 2023 18:51:20 +0800 Subject: fix: improve the stability of thread system --- src/core/module/ModuleManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index b9e73721..f578e67c 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -51,7 +51,7 @@ class ModuleManager::Impl { gpc_->RegisterModule(module); return 0; }), - __func__, nullptr, true)); + __func__, nullptr)); } void TriggerEvent(EventRefrernce event) { @@ -60,7 +60,7 @@ class ModuleManager::Impl { gpc_->TriggerEvent(event); return 0; }), - __func__, nullptr, true)); + __func__, nullptr)); } void ActiveModule(ModuleIdentifier identifier) { @@ -69,7 +69,7 @@ class ModuleManager::Impl { gpc_->ActiveModule(identifier); return 0; }), - __func__, nullptr, true)); + __func__, nullptr)); } std::optional GetTaskRunner(ModuleIdentifier module_id) { -- 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/ModuleManager.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index f578e67c..0bf9e972 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -28,7 +28,10 @@ #include "ModuleManager.h" +#include + #include "core/module/GlobalModuleContext.h" +#include "core/module/GlobalRegisterTable.h" #include "core/module/Module.h" #include "core/thread/TaskRunner.h" @@ -40,15 +43,16 @@ class ModuleManager::Impl { public: Impl() : task_runner_(std::make_shared()), - gpc_(std::make_shared(task_runner_)) { + gmc_(std::make_shared(task_runner_)), + grt_(std::make_shared()) { task_runner_->Start(); } void RegisterModule(ModulePtr module) { task_runner_->PostTask(new Thread::Task( std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { - module->SetGPC(gpc_); - gpc_->RegisterModule(module); + module->SetGPC(gmc_); + gmc_->RegisterModule(module); return 0; }), __func__, nullptr)); @@ -57,7 +61,7 @@ class ModuleManager::Impl { void TriggerEvent(EventRefrernce event) { task_runner_->PostTask(new Thread::Task( std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { - gpc_->TriggerEvent(event); + gmc_->TriggerEvent(event); return 0; }), __func__, nullptr)); @@ -66,20 +70,29 @@ class ModuleManager::Impl { void ActiveModule(ModuleIdentifier identifier) { task_runner_->PostTask(new Thread::Task( std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { - gpc_->ActiveModule(identifier); + gmc_->ActiveModule(identifier); return 0; }), __func__, nullptr)); } std::optional GetTaskRunner(ModuleIdentifier module_id) { - return gpc_->GetTaskRunner(module_id); + return gmc_->GetTaskRunner(module_id); + } + + bool UpsertRTValue(Namespace n, Key k, std::any v) { + return grt_->PublishKV(n, k, v); + } + + std::optional RetrieveRTValue(Namespace n, Key k) { + return grt_->LookupKV(n, k); } private: static ModuleMangerPtr global_module_manager_; TaskRunnerPtr task_runner_; - GlobalModuleContextPtr gpc_; + GMCPtr gmc_; + GRTPtr grt_; }; ModuleManager::ModuleManager() : p_(std::make_unique()) {} @@ -108,4 +121,12 @@ std::optional ModuleManager::GetTaskRunner( return p_->GetTaskRunner(module_id); } +bool ModuleManager::UpsertRTValue(Namespace n, Key k, std::any v) { + return p_->UpsertRTValue(n, k, v); +} + +std::optional ModuleManager::RetrieveRTValue(Namespace n, Key k) { + return p_->RetrieveRTValue(n, k); +} + } // namespace GpgFrontend::Module \ No newline at end of file -- 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/ModuleManager.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 0bf9e972..20f9ab28 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -28,11 +28,12 @@ #include "ModuleManager.h" -#include +#include #include "core/module/GlobalModuleContext.h" #include "core/module/GlobalRegisterTable.h" #include "core/module/Module.h" +#include "core/thread/Task.h" #include "core/thread/TaskRunner.h" namespace GpgFrontend::Module { @@ -88,6 +89,10 @@ class ModuleManager::Impl { return grt_->LookupKV(n, k); } + bool ListenPublish(QObject* o, Namespace n, Key k, LPCallback c) { + return grt_->ListenPublish(o, n, k, c); + } + private: static ModuleMangerPtr global_module_manager_; TaskRunnerPtr task_runner_; @@ -95,6 +100,12 @@ class ModuleManager::Impl { GRTPtr grt_; }; +bool UpsertRTValueTyped(const std::string& namespace_, const std::string& key, + const std::any& value) { + return ModuleManager::GetInstance()->UpsertRTValue(namespace_, key, + std::any(value)); +} + ModuleManager::ModuleManager() : p_(std::make_unique()) {} ModuleManager::~ModuleManager() = default; @@ -129,4 +140,15 @@ std::optional ModuleManager::RetrieveRTValue(Namespace n, Key k) { return p_->RetrieveRTValue(n, k); } +bool ModuleManager::ListenPublish(QObject* o, Namespace n, Key k, + LPCallback c) { + return p_->ListenPublish(o, n, k, c); +} + +ModuleIdentifier GetRealModuleIdentifier(const ModuleIdentifier& id) { + // WARNING: when YOU need to CHANGE this line, YOU SHOULD change the same code + // in Module.cpp as well. + return (boost::format("__module_%1%") % id).str(); +} + } // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3 From a23b2fbc707406dec0dd924c089b4285bc7f0010 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 25 Oct 2023 15:40:43 +0800 Subject: feat: use rt listen publish event function in main windows' app version upgrade notification --- src/core/module/ModuleManager.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 20f9ab28..c151ebb1 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -100,12 +100,17 @@ class ModuleManager::Impl { GRTPtr grt_; }; -bool UpsertRTValueTyped(const std::string& namespace_, const std::string& key, - const std::any& value) { +bool UpsertRTValue(const std::string& namespace_, const std::string& key, + const std::any& value) { return ModuleManager::GetInstance()->UpsertRTValue(namespace_, key, std::any(value)); } +bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject* o, Namespace n, + Key k, LPCallback c) { + return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c); +} + ModuleManager::ModuleManager() : p_(std::make_unique()) {} ModuleManager::~ModuleManager() = default; @@ -140,8 +145,8 @@ std::optional ModuleManager::RetrieveRTValue(Namespace n, Key k) { return p_->RetrieveRTValue(n, k); } -bool ModuleManager::ListenPublish(QObject* o, Namespace n, Key k, - LPCallback c) { +bool ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k, + LPCallback c) { return p_->ListenPublish(o, n, k, c); } -- cgit v1.2.3 From 124929609eabff19359caad276a10f1026793c0f Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 25 Oct 2023 18:26:26 +0800 Subject: fix: solve some code tidy issues --- src/core/module/ModuleManager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index c151ebb1..4a78a85b 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -51,29 +51,29 @@ class ModuleManager::Impl { void RegisterModule(ModulePtr module) { task_runner_->PostTask(new Thread::Task( - std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { + [=](GpgFrontend::Thread::DataObjectPtr) -> int { module->SetGPC(gmc_); gmc_->RegisterModule(module); return 0; - }), + }, __func__, nullptr)); } void TriggerEvent(EventRefrernce event) { task_runner_->PostTask(new Thread::Task( - std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { + [=](GpgFrontend::Thread::DataObjectPtr) -> int { gmc_->TriggerEvent(event); return 0; - }), + }, __func__, nullptr)); } void ActiveModule(ModuleIdentifier identifier) { task_runner_->PostTask(new Thread::Task( - std::move([=](GpgFrontend::Thread::DataObjectPtr) -> int { + [=](GpgFrontend::Thread::DataObjectPtr) -> int { gmc_->ActiveModule(identifier); return 0; - }), + }, __func__, nullptr)); } -- cgit v1.2.3 From b7ceed0b87752077fe19fefe9b0df8ec27ce0531 Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 25 Oct 2023 22:28:25 +0800 Subject: feat: moving gnupg info gathering logic to a new module --- src/core/module/ModuleManager.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 4a78a85b..ba24ec7a 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -89,8 +89,8 @@ class ModuleManager::Impl { return grt_->LookupKV(n, k); } - bool ListenPublish(QObject* o, Namespace n, Key k, LPCallback c) { - return grt_->ListenPublish(o, n, k, c); + bool ListenPublish(QObject* o, Namespace n, Key k, LPCallback c, bool c_o) { + return grt_->ListenPublish(o, n, k, c, c_o); } private: @@ -107,8 +107,9 @@ bool UpsertRTValue(const std::string& namespace_, const std::string& key, } bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject* o, Namespace n, - Key k, LPCallback c) { - return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c); + Key k, LPCallback c, + bool c_o) { + return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c, c_o); } ModuleManager::ModuleManager() : p_(std::make_unique()) {} @@ -146,8 +147,8 @@ std::optional ModuleManager::RetrieveRTValue(Namespace n, Key k) { } bool ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k, - LPCallback c) { - return p_->ListenPublish(o, n, k, c); + LPCallback c, bool c_o) { + return p_->ListenPublish(o, n, k, c, c_o); } ModuleIdentifier GetRealModuleIdentifier(const ModuleIdentifier& id) { -- 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/ModuleManager.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index ba24ec7a..4dcc9595 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -51,7 +51,7 @@ class ModuleManager::Impl { void RegisterModule(ModulePtr module) { task_runner_->PostTask(new Thread::Task( - [=](GpgFrontend::Thread::DataObjectPtr) -> int { + [=](GpgFrontend::DataObjectPtr) -> int { module->SetGPC(gmc_); gmc_->RegisterModule(module); return 0; @@ -61,7 +61,7 @@ class ModuleManager::Impl { void TriggerEvent(EventRefrernce event) { task_runner_->PostTask(new Thread::Task( - [=](GpgFrontend::Thread::DataObjectPtr) -> int { + [=](GpgFrontend::DataObjectPtr) -> int { gmc_->TriggerEvent(event); return 0; }, @@ -70,7 +70,7 @@ class ModuleManager::Impl { void ActiveModule(ModuleIdentifier identifier) { task_runner_->PostTask(new Thread::Task( - [=](GpgFrontend::Thread::DataObjectPtr) -> int { + [=](GpgFrontend::DataObjectPtr) -> int { gmc_->ActiveModule(identifier); return 0; }, @@ -89,8 +89,8 @@ class ModuleManager::Impl { return grt_->LookupKV(n, k); } - bool ListenPublish(QObject* o, Namespace n, Key k, LPCallback c, bool c_o) { - return grt_->ListenPublish(o, n, k, c, c_o); + bool ListenPublish(QObject* o, Namespace n, Key k, LPCallback c) { + return grt_->ListenPublish(o, n, k, c); } private: @@ -107,9 +107,8 @@ bool UpsertRTValue(const std::string& namespace_, const std::string& key, } bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject* o, Namespace n, - Key k, LPCallback c, - bool c_o) { - return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c, c_o); + Key k, LPCallback c) { + return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c); } ModuleManager::ModuleManager() : p_(std::make_unique()) {} @@ -147,8 +146,8 @@ std::optional ModuleManager::RetrieveRTValue(Namespace n, Key k) { } bool ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k, - LPCallback c, bool c_o) { - return p_->ListenPublish(o, n, k, c, c_o); + LPCallback c) { + return p_->ListenPublish(o, n, k, c); } ModuleIdentifier GetRealModuleIdentifier(const ModuleIdentifier& id) { -- cgit v1.2.3 From b219d1c9d0f6e9542b0b4f3f62c4dd368413ddec Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 2 Nov 2023 09:59:40 +0800 Subject: feat: add callback function to event --- src/core/module/ModuleManager.cpp | 53 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 4dcc9595..1c778197 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -29,6 +29,7 @@ #include "ModuleManager.h" #include +#include #include "core/module/GlobalModuleContext.h" #include "core/module/GlobalRegisterTable.h" @@ -49,7 +50,7 @@ class ModuleManager::Impl { task_runner_->Start(); } - void RegisterModule(ModulePtr module) { + void RegisterModule(const ModulePtr& module) { task_runner_->PostTask(new Thread::Task( [=](GpgFrontend::DataObjectPtr) -> int { module->SetGPC(gmc_); @@ -59,55 +60,56 @@ class ModuleManager::Impl { __func__, nullptr)); } - void TriggerEvent(EventRefrernce event) { + void TriggerEvent(const EventRefrernce& event) { task_runner_->PostTask(new Thread::Task( - [=](GpgFrontend::DataObjectPtr) -> int { + [=](const GpgFrontend::DataObjectPtr&) -> int { gmc_->TriggerEvent(event); return 0; }, __func__, nullptr)); } - void ActiveModule(ModuleIdentifier identifier) { + void ActiveModule(const ModuleIdentifier& identifier) { task_runner_->PostTask(new Thread::Task( - [=](GpgFrontend::DataObjectPtr) -> int { + [=](const GpgFrontend::DataObjectPtr&) -> int { gmc_->ActiveModule(identifier); return 0; }, __func__, nullptr)); } - std::optional GetTaskRunner(ModuleIdentifier module_id) { - return gmc_->GetTaskRunner(module_id); + auto GetTaskRunner(ModuleIdentifier module_id) + -> std::optional { + return gmc_->GetTaskRunner(std::move(module_id)); } - bool UpsertRTValue(Namespace n, Key k, std::any v) { + auto UpsertRTValue(Namespace n, Key k, std::any v) -> bool { return grt_->PublishKV(n, k, v); } - std::optional RetrieveRTValue(Namespace n, Key k) { + auto RetrieveRTValue(Namespace n, Key k) -> std::optional { return grt_->LookupKV(n, k); } - bool ListenPublish(QObject* o, Namespace n, Key k, LPCallback c) { + auto ListenPublish(QObject* o, Namespace n, Key k, LPCallback c) -> bool { return grt_->ListenPublish(o, n, k, c); } private: - static ModuleMangerPtr global_module_manager_; + static ModuleMangerPtr global_module_manager; TaskRunnerPtr task_runner_; GMCPtr gmc_; GRTPtr grt_; }; -bool UpsertRTValue(const std::string& namespace_, const std::string& key, - const std::any& value) { +auto UpsertRTValue(const std::string& namespace_, const std::string& key, + const std::any& value) -> bool { return ModuleManager::GetInstance()->UpsertRTValue(namespace_, key, std::any(value)); } -bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject* o, Namespace n, - Key k, LPCallback c) { +auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject* o, Namespace n, + Key k, LPCallback c) -> bool { return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c); } @@ -115,7 +117,7 @@ ModuleManager::ModuleManager() : p_(std::make_unique()) {} ModuleManager::~ModuleManager() = default; -ModuleMangerPtr ModuleManager::GetInstance() { +auto ModuleManager::GetInstance() -> ModuleMangerPtr { if (g_ == nullptr) g_ = std::shared_ptr(new ModuleManager()); return g_; } @@ -132,28 +134,29 @@ void ModuleManager::ActiveModule(ModuleIdentifier identifier) { return p_->ActiveModule(identifier); } -std::optional ModuleManager::GetTaskRunner( - ModuleIdentifier module_id) { - return p_->GetTaskRunner(module_id); +auto ModuleManager::GetTaskRunner(ModuleIdentifier module_id) + -> std::optional { + return p_->GetTaskRunner(std::move(module_id)); } -bool ModuleManager::UpsertRTValue(Namespace n, Key k, std::any v) { +auto ModuleManager::UpsertRTValue(Namespace n, Key k, std::any v) -> bool { return p_->UpsertRTValue(n, k, v); } -std::optional ModuleManager::RetrieveRTValue(Namespace n, Key k) { +auto ModuleManager::RetrieveRTValue(Namespace n, Key k) + -> std::optional { return p_->RetrieveRTValue(n, k); } -bool ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k, - LPCallback c) { +auto ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k, + LPCallback c) -> bool { return p_->ListenPublish(o, n, k, c); } -ModuleIdentifier GetRealModuleIdentifier(const ModuleIdentifier& id) { +auto GetRealModuleIdentifier(const ModuleIdentifier& m_id) -> ModuleIdentifier { // WARNING: when YOU need to CHANGE this line, YOU SHOULD change the same code // in Module.cpp as well. - return (boost::format("__module_%1%") % id).str(); + return (boost::format("__module_%1%") % m_id).str(); } } // namespace GpgFrontend::Module \ No newline at end of file -- 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/ModuleManager.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 1c778197..4400a92d 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -95,6 +95,11 @@ class ModuleManager::Impl { return grt_->ListenPublish(o, n, k, c); } + auto ListRTChildKeys(const std::string& n, const std::string& k) + -> std::vector { + return grt_->ListChildKeys(n, k); + } + private: static ModuleMangerPtr global_module_manager; TaskRunnerPtr task_runner_; @@ -108,11 +113,16 @@ auto UpsertRTValue(const std::string& namespace_, const std::string& key, std::any(value)); } -auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject* o, Namespace n, - Key k, LPCallback c) -> bool { +auto ListenRTPublishEvent(QObject* o, Namespace n, Key k, LPCallback c) + -> bool { return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c); } +auto ListRTChildKeys(const std::string& namespace_, const std::string& key) + -> std::vector { + return ModuleManager::GetInstance()->ListRTChildKeys(namespace_, key); +} + ModuleManager::ModuleManager() : p_(std::make_unique()) {} ModuleManager::~ModuleManager() = default; @@ -130,13 +140,13 @@ void ModuleManager::TriggerEvent(EventRefrernce event) { return p_->TriggerEvent(event); } -void ModuleManager::ActiveModule(ModuleIdentifier identifier) { - return p_->ActiveModule(identifier); +void ModuleManager::ActiveModule(ModuleIdentifier id) { + return p_->ActiveModule(id); } -auto ModuleManager::GetTaskRunner(ModuleIdentifier module_id) +auto ModuleManager::GetTaskRunner(ModuleIdentifier id) -> std::optional { - return p_->GetTaskRunner(std::move(module_id)); + return p_->GetTaskRunner(std::move(id)); } auto ModuleManager::UpsertRTValue(Namespace n, Key k, std::any v) -> bool { @@ -153,10 +163,9 @@ auto ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k, return p_->ListenPublish(o, n, k, c); } -auto GetRealModuleIdentifier(const ModuleIdentifier& m_id) -> ModuleIdentifier { - // WARNING: when YOU need to CHANGE this line, YOU SHOULD change the same code - // in Module.cpp as well. - return (boost::format("__module_%1%") % m_id).str(); +auto ModuleManager::ListRTChildKeys(const std::string& n, const std::string& k) + -> std::vector { + return p_->ListRTChildKeys(n, k); } } // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3 From 883db05d54510e76b6548e107593187e1306117d Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 3 Dec 2023 04:28:46 -0800 Subject: feat: general improvements of aync execution and memory security --- src/core/module/ModuleManager.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 4400a92d..5e2aa994 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -44,9 +44,11 @@ ModuleMangerPtr ModuleManager::g_ = nullptr; class ModuleManager::Impl { public: Impl() - : task_runner_(std::make_shared()), - gmc_(std::make_shared(task_runner_)), - grt_(std::make_shared()) { + : task_runner_( + GpgFrontend::SecureCreateSharedObject()), + gmc_(GpgFrontend::SecureCreateSharedObject( + task_runner_)), + grt_(GpgFrontend::SecureCreateSharedObject()) { task_runner_->Start(); } -- cgit v1.2.3 From 054e6e28cca2517dda2319ef683314b3318c39a6 Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 3 Dec 2023 12:25:21 -0800 Subject: feat: standarized and speed up app env loading process --- src/core/module/ModuleManager.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 5e2aa994..03ac21a8 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -102,6 +102,10 @@ class ModuleManager::Impl { return grt_->ListChildKeys(n, k); } + auto IsModuleActivated(ModuleIdentifier id) -> bool { + return gmc_->IsModuleActivated(id); + } + private: static ModuleMangerPtr global_module_manager; TaskRunnerPtr task_runner_; @@ -109,6 +113,10 @@ class ModuleManager::Impl { GRTPtr grt_; }; +auto IsModuleAcivate(ModuleIdentifier id) -> bool { + return ModuleManager::GetInstance()->IsModuleActivated(id); +} + auto UpsertRTValue(const std::string& namespace_, const std::string& key, const std::any& value) -> bool { return ModuleManager::GetInstance()->UpsertRTValue(namespace_, key, @@ -170,4 +178,8 @@ auto ModuleManager::ListRTChildKeys(const std::string& n, const std::string& k) return p_->ListRTChildKeys(n, k); } +auto ModuleManager::IsModuleActivated(ModuleIdentifier id) -> bool { + return p_->IsModuleActivated(id); +} + } // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3 From 79783510863445b5068eef092a1f2650733a5b02 Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 14 Dec 2023 16:58:53 +0800 Subject: fix: slove some memory issues --- src/core/module/ModuleManager.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 03ac21a8..26974f1c 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -36,11 +36,10 @@ #include "core/module/Module.h" #include "core/thread/Task.h" #include "core/thread/TaskRunner.h" +#include "utils/MemoryUtils.h" namespace GpgFrontend::Module { -ModuleMangerPtr ModuleManager::g_ = nullptr; - class ModuleManager::Impl { public: Impl() @@ -138,8 +137,8 @@ ModuleManager::ModuleManager() : p_(std::make_unique()) {} ModuleManager::~ModuleManager() = default; auto ModuleManager::GetInstance() -> ModuleMangerPtr { - if (g_ == nullptr) g_ = std::shared_ptr(new ModuleManager()); - return g_; + static ModuleMangerPtr g = SecureCreateSharedObject(); + return g; } void ModuleManager::RegisterModule(ModulePtr module) { -- 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/ModuleManager.cpp | 84 ++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 40 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 26974f1c..26edc43e 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -29,13 +29,18 @@ #include "ModuleManager.h" #include +#include #include +#include "GpgConstants.h" #include "core/module/GlobalModuleContext.h" #include "core/module/GlobalRegisterTable.h" #include "core/module/Module.h" #include "core/thread/Task.h" #include "core/thread/TaskRunner.h" +#include "function/SecureMemoryAllocator.h" +#include "function/basic/GpgFunctionObject.h" +#include "thread/TaskRunnerGetter.h" #include "utils/MemoryUtils.h" namespace GpgFrontend::Module { @@ -43,40 +48,43 @@ namespace GpgFrontend::Module { class ModuleManager::Impl { public: Impl() - : task_runner_( - GpgFrontend::SecureCreateSharedObject()), - gmc_(GpgFrontend::SecureCreateSharedObject( - task_runner_)), - grt_(GpgFrontend::SecureCreateSharedObject()) { - task_runner_->Start(); - } + : gmc_(GpgFrontend::SecureCreateUniqueObject()), + grt_(GpgFrontend::SecureCreateUniqueObject()) {} + + ~Impl() = default; void RegisterModule(const ModulePtr& module) { - task_runner_->PostTask(new Thread::Task( - [=](GpgFrontend::DataObjectPtr) -> int { - module->SetGPC(gmc_); - gmc_->RegisterModule(module); - return 0; - }, - __func__, nullptr)); + Thread::TaskRunnerGetter::GetInstance() + .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Default) + ->PostTask(new Thread::Task( + [=](GpgFrontend::DataObjectPtr) -> int { + module->SetGPC(gmc_.get()); + gmc_->RegisterModule(module); + return 0; + }, + __func__, nullptr)); } void TriggerEvent(const EventRefrernce& event) { - task_runner_->PostTask(new Thread::Task( - [=](const GpgFrontend::DataObjectPtr&) -> int { - gmc_->TriggerEvent(event); - return 0; - }, - __func__, nullptr)); + Thread::TaskRunnerGetter::GetInstance() + .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Default) + ->PostTask(new Thread::Task( + [=](const GpgFrontend::DataObjectPtr&) -> int { + gmc_->TriggerEvent(event); + return 0; + }, + __func__, nullptr)); } void ActiveModule(const ModuleIdentifier& identifier) { - task_runner_->PostTask(new Thread::Task( - [=](const GpgFrontend::DataObjectPtr&) -> int { - gmc_->ActiveModule(identifier); - return 0; - }, - __func__, nullptr)); + Thread::TaskRunnerGetter::GetInstance() + .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Default) + ->PostTask(new Thread::Task( + [=](const GpgFrontend::DataObjectPtr&) -> int { + gmc_->ActiveModule(identifier); + return 0; + }, + __func__, nullptr)); } auto GetTaskRunner(ModuleIdentifier module_id) @@ -107,40 +115,36 @@ class ModuleManager::Impl { private: static ModuleMangerPtr global_module_manager; - TaskRunnerPtr task_runner_; - GMCPtr gmc_; - GRTPtr grt_; + SecureUniquePtr gmc_; + SecureUniquePtr grt_; }; auto IsModuleAcivate(ModuleIdentifier id) -> bool { - return ModuleManager::GetInstance()->IsModuleActivated(id); + return ModuleManager::GetInstance().IsModuleActivated(id); } auto UpsertRTValue(const std::string& namespace_, const std::string& key, const std::any& value) -> bool { - return ModuleManager::GetInstance()->UpsertRTValue(namespace_, key, - std::any(value)); + return ModuleManager::GetInstance().UpsertRTValue(namespace_, key, + std::any(value)); } auto ListenRTPublishEvent(QObject* o, Namespace n, Key k, LPCallback c) -> bool { - return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c); + return ModuleManager::GetInstance().ListenRTPublish(o, n, k, c); } auto ListRTChildKeys(const std::string& namespace_, const std::string& key) -> std::vector { - return ModuleManager::GetInstance()->ListRTChildKeys(namespace_, key); + return ModuleManager::GetInstance().ListRTChildKeys(namespace_, key); } -ModuleManager::ModuleManager() : p_(std::make_unique()) {} +ModuleManager::ModuleManager(int channel) + : SingletonFunctionObject(channel), + p_(std::make_unique()) {} ModuleManager::~ModuleManager() = default; -auto ModuleManager::GetInstance() -> ModuleMangerPtr { - static ModuleMangerPtr g = SecureCreateSharedObject(); - return g; -} - void ModuleManager::RegisterModule(ModulePtr module) { return p_->RegisterModule(module); } -- cgit v1.2.3 From c41074792f8c3b966b6d637c9e9b0ee10c5255e7 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 15 Dec 2023 21:12:25 -0800 Subject: fix: clean up envirnoment when app exits --- src/core/module/ModuleManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 26edc43e..420bc611 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -141,7 +141,7 @@ auto ListRTChildKeys(const std::string& namespace_, const std::string& key) ModuleManager::ModuleManager(int channel) : SingletonFunctionObject(channel), - p_(std::make_unique()) {} + p_(SecureCreateUniqueObject()) {} ModuleManager::~ModuleManager() = 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/ModuleManager.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 420bc611..4c1cf098 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -28,7 +28,6 @@ #include "ModuleManager.h" -#include #include #include @@ -104,8 +103,7 @@ class ModuleManager::Impl { return grt_->ListenPublish(o, n, k, c); } - auto ListRTChildKeys(const std::string& n, const std::string& k) - -> std::vector { + auto ListRTChildKeys(const QString& n, const QString& k) -> std::vector { return grt_->ListChildKeys(n, k); } @@ -123,7 +121,7 @@ auto IsModuleAcivate(ModuleIdentifier id) -> bool { return ModuleManager::GetInstance().IsModuleActivated(id); } -auto UpsertRTValue(const std::string& namespace_, const std::string& key, +auto UpsertRTValue(const QString& namespace_, const QString& key, const std::any& value) -> bool { return ModuleManager::GetInstance().UpsertRTValue(namespace_, key, std::any(value)); @@ -134,7 +132,7 @@ auto ListenRTPublishEvent(QObject* o, Namespace n, Key k, LPCallback c) return ModuleManager::GetInstance().ListenRTPublish(o, n, k, c); } -auto ListRTChildKeys(const std::string& namespace_, const std::string& key) +auto ListRTChildKeys(const QString& namespace_, const QString& key) -> std::vector { return ModuleManager::GetInstance().ListRTChildKeys(namespace_, key); } @@ -176,7 +174,7 @@ auto ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k, return p_->ListenPublish(o, n, k, c); } -auto ModuleManager::ListRTChildKeys(const std::string& n, const std::string& k) +auto ModuleManager::ListRTChildKeys(const QString& n, const QString& k) -> std::vector { return p_->ListRTChildKeys(n, k); } -- 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/ModuleManager.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 4c1cf098..fd65a0ab 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -29,7 +29,6 @@ #include "ModuleManager.h" #include -#include #include "GpgConstants.h" #include "core/module/GlobalModuleContext.h" -- cgit v1.2.3 From e352e8e6b8d03a24ef5d52eef3e4d370807b5bbd Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 17 Jan 2024 19:39:47 +0800 Subject: fix: find and slove some bugs --- src/core/module/ModuleManager.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/core/module/ModuleManager.cpp') diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index fd65a0ab..83e7c1ff 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -35,7 +35,6 @@ #include "core/module/GlobalRegisterTable.h" #include "core/module/Module.h" #include "core/thread/Task.h" -#include "core/thread/TaskRunner.h" #include "function/SecureMemoryAllocator.h" #include "function/basic/GpgFunctionObject.h" #include "thread/TaskRunnerGetter.h" -- cgit v1.2.3