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.h | 104 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/core/module/ModuleManager.h (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h new file mode 100644 index 00000000..bb201ebe --- /dev/null +++ b/src/core/module/ModuleManager.h @@ -0,0 +1,104 @@ +/** + * 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 + * + */ + +#ifndef GPGFRONTEND_MODULEMANAGER_H +#define GPGFRONTEND_MODULEMANAGER_H + +#include +#include + +#include "core/GpgFrontendCore.h" +#include "core/thread/Task.h" + +namespace GpgFrontend::Thread { +class TaskRunner; +} + +namespace GpgFrontend::Module { + +using TaskRunnerPtr = std::shared_ptr; + +class Event; +class Module; +class GlobalModuleContext; +class ModuleManager; + +using EventRefrernce = std::shared_ptr; +using ModuleIdentifier = std::string; +using ModulePtr = std::shared_ptr; +using ModuleMangerPtr = std::shared_ptr; +using GlobalModuleContextPtr = std::shared_ptr; + +class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { + Q_OBJECT + public: + ~ModuleManager(); + + static ModuleMangerPtr GetInstance(); + + void RegisterModule(ModulePtr); + + void TriggerEvent(EventRefrernce); + + void ActiveModule(ModuleIdentifier); + + void DeactiveModule(ModuleIdentifier); + + std::optional GetTaskRunner(ModuleIdentifier); + + private: + class Impl; + std::unique_ptr p_; + static ModuleMangerPtr g_; + + ModuleManager(); +}; + +template +void RegisterModule(Args&&... args) { + ModuleManager::GetInstance()->RegisterModule( + std::make_shared(std::forward(args)...)); +} + +template +void RegisterAndActivateModule(Args&&... args) { + auto manager = ModuleManager::GetInstance(); + auto module = std::make_shared(std::forward(args)...); + manager->RegisterModule(module); + manager->ActiveModule(module->GetModuleIdentifier()); +} + +template +void TriggerEvent(const std::string& eventIdentifier, Args&&... args) { + ModuleManager::GetInstance()->TriggerEvent(std::make_shared( + std::move(MakeEvent(eventIdentifier, std::forward(args)...)))); +} + +} // namespace GpgFrontend::Module + +#endif // GPGFRONTEND_MODULEMANAGER_H \ 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/ModuleManager.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index bb201ebe..c2889f87 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -32,8 +32,7 @@ #include #include -#include "core/GpgFrontendCore.h" -#include "core/thread/Task.h" +#include "core/module/Event.h" namespace GpgFrontend::Thread { class TaskRunner; @@ -94,9 +93,9 @@ void RegisterAndActivateModule(Args&&... args) { } template -void TriggerEvent(const std::string& eventIdentifier, Args&&... args) { - ModuleManager::GetInstance()->TriggerEvent(std::make_shared( - std::move(MakeEvent(eventIdentifier, std::forward(args)...)))); +void TriggerEvent(const EventIdentifier& event_id, Args&&... args) { + ModuleManager::GetInstance()->TriggerEvent( + std::move(MakeEvent(event_id, std::forward(args)...))); } } // namespace GpgFrontend::Module -- 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.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index c2889f87..66fa9db6 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -26,11 +26,7 @@ * */ -#ifndef GPGFRONTEND_MODULEMANAGER_H -#define GPGFRONTEND_MODULEMANAGER_H - -#include -#include +#pragma once #include "core/module/Event.h" @@ -51,7 +47,9 @@ using EventRefrernce = std::shared_ptr; using ModuleIdentifier = std::string; using ModulePtr = std::shared_ptr; using ModuleMangerPtr = std::shared_ptr; -using GlobalModuleContextPtr = std::shared_ptr; +using GMCPtr = std::shared_ptr; +using Namespace = std::string; +using Key = std::string; class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { Q_OBJECT @@ -70,6 +68,10 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { std::optional GetTaskRunner(ModuleIdentifier); + bool UpsertRTValue(Namespace, Key, std::any); + + std::optional RetrieveRTValue(Namespace, Key); + private: class Impl; std::unique_ptr p_; @@ -98,6 +100,4 @@ void TriggerEvent(const EventIdentifier& event_id, Args&&... args) { std::move(MakeEvent(event_id, std::forward(args)...))); } -} // namespace GpgFrontend::Module - -#endif // GPGFRONTEND_MODULEMANAGER_H \ No newline at end of file +} // 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.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 66fa9db6..586627b6 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -50,6 +50,10 @@ using ModuleMangerPtr = std::shared_ptr; using GMCPtr = std::shared_ptr; using Namespace = std::string; using Key = std::string; +using LPCallback = std::function; + +ModuleIdentifier GPGFRONTEND_CORE_EXPORT +GetRealModuleIdentifier(const ModuleIdentifier& id); class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { Q_OBJECT @@ -72,6 +76,8 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { std::optional RetrieveRTValue(Namespace, Key); + bool ListenPublish(QObject*, Namespace, Key, LPCallback); + private: class Impl; std::unique_ptr p_; @@ -100,4 +106,30 @@ void TriggerEvent(const EventIdentifier& event_id, Args&&... args) { std::move(MakeEvent(event_id, std::forward(args)...))); } +bool GPGFRONTEND_CORE_EXPORT UpsertRTValueTyped(const std::string& namespace_, + const std::string& key, + const std::any& value); + +template +std::optional RetrieveRTValueTyped(const std::string& namespace_, + const std::string& key) { + auto any_value = + ModuleManager::GetInstance()->RetrieveRTValue(namespace_, key); + if (any_value && any_value->type() == typeid(T)) { + return std::any_cast(*any_value); + } + return std::nullopt; +} + +template +T RetrieveRTValueTypedOrDefault(const std::string& namespace_, + const std::string& key, const T& defaultValue) { + auto any_value = + ModuleManager::GetInstance()->RetrieveRTValue(namespace_, key); + if (any_value && any_value->type() == typeid(T)) { + return std::any_cast(*any_value); + } + return defaultValue; +} + } // 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.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 586627b6..865f196b 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -76,7 +76,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { std::optional RetrieveRTValue(Namespace, Key); - bool ListenPublish(QObject*, Namespace, Key, LPCallback); + bool ListenRTPublish(QObject*, Namespace, Key, LPCallback); private: class Impl; @@ -106,9 +106,12 @@ void TriggerEvent(const EventIdentifier& event_id, Args&&... args) { std::move(MakeEvent(event_id, std::forward(args)...))); } -bool GPGFRONTEND_CORE_EXPORT UpsertRTValueTyped(const std::string& namespace_, - const std::string& key, - const std::any& value); +bool GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, + const std::string& key, + const std::any& value); + +bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, + LPCallback); template std::optional RetrieveRTValueTyped(const std::string& namespace_, -- 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.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 865f196b..1ce2d8b5 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -50,7 +50,7 @@ using ModuleMangerPtr = std::shared_ptr; using GMCPtr = std::shared_ptr; using Namespace = std::string; using Key = std::string; -using LPCallback = std::function; +using LPCallback = std::function; ModuleIdentifier GPGFRONTEND_CORE_EXPORT GetRealModuleIdentifier(const ModuleIdentifier& id); @@ -76,7 +76,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { std::optional RetrieveRTValue(Namespace, Key); - bool ListenRTPublish(QObject*, Namespace, Key, LPCallback); + bool ListenRTPublish(QObject*, Namespace, Key, LPCallback, bool); private: class Impl; @@ -111,7 +111,8 @@ bool GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, const std::any& value); bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, - LPCallback); + LPCallback, + bool callback_once = true); template std::optional RetrieveRTValueTyped(const std::string& namespace_, -- 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.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 1ce2d8b5..4488838c 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -76,7 +76,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { std::optional RetrieveRTValue(Namespace, Key); - bool ListenRTPublish(QObject*, Namespace, Key, LPCallback, bool); + bool ListenRTPublish(QObject*, Namespace, Key, LPCallback); private: class Impl; @@ -111,8 +111,7 @@ bool GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, const std::any& value); bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, - LPCallback, - bool callback_once = true); + LPCallback); template std::optional RetrieveRTValueTyped(const std::string& namespace_, -- 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.h | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 4488838c..55325ab6 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -52,15 +52,15 @@ using Namespace = std::string; using Key = std::string; using LPCallback = std::function; -ModuleIdentifier GPGFRONTEND_CORE_EXPORT -GetRealModuleIdentifier(const ModuleIdentifier& id); +auto GPGFRONTEND_CORE_EXPORT GetRealModuleIdentifier(const ModuleIdentifier& id) + -> ModuleIdentifier; class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { Q_OBJECT public: - ~ModuleManager(); + ~ModuleManager() override; - static ModuleMangerPtr GetInstance(); + static auto GetInstance() -> ModuleMangerPtr; void RegisterModule(ModulePtr); @@ -70,13 +70,13 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { void DeactiveModule(ModuleIdentifier); - std::optional GetTaskRunner(ModuleIdentifier); + auto GetTaskRunner(ModuleIdentifier) -> std::optional; - bool UpsertRTValue(Namespace, Key, std::any); + auto UpsertRTValue(Namespace, Key, std::any) -> bool; - std::optional RetrieveRTValue(Namespace, Key); + auto RetrieveRTValue(Namespace, Key) -> std::optional; - bool ListenRTPublish(QObject*, Namespace, Key, LPCallback); + auto ListenRTPublish(QObject*, Namespace, Key, LPCallback) -> bool; private: class Impl; @@ -101,21 +101,22 @@ void RegisterAndActivateModule(Args&&... args) { } template -void TriggerEvent(const EventIdentifier& event_id, Args&&... args) { +void TriggerEvent(const EventIdentifier& event_id, Args&&... args, + Event::EventCallback e_cb = nullptr) { ModuleManager::GetInstance()->TriggerEvent( - std::move(MakeEvent(event_id, std::forward(args)...))); + std::move(MakeEvent(event_id, std::forward(args)..., e_cb))); } -bool GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, +auto GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, const std::string& key, - const std::any& value); + const std::any& value) -> bool; -bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, - LPCallback); +auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, + LPCallback) -> bool; template -std::optional RetrieveRTValueTyped(const std::string& namespace_, - const std::string& key) { +auto RetrieveRTValueTyped(const std::string& namespace_, const std::string& key) + -> std::optional { auto any_value = ModuleManager::GetInstance()->RetrieveRTValue(namespace_, key); if (any_value && any_value->type() == typeid(T)) { @@ -125,8 +126,9 @@ std::optional RetrieveRTValueTyped(const std::string& namespace_, } template -T RetrieveRTValueTypedOrDefault(const std::string& namespace_, - const std::string& key, const T& defaultValue) { +auto RetrieveRTValueTypedOrDefault(const std::string& namespace_, + const std::string& key, + const T& defaultValue) -> T { auto any_value = ModuleManager::GetInstance()->RetrieveRTValue(namespace_, key); if (any_value && any_value->type() == typeid(T)) { -- 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.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 55325ab6..cf845f96 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -28,6 +28,8 @@ #pragma once +#include + #include "core/module/Event.h" namespace GpgFrontend::Thread { @@ -52,9 +54,6 @@ using Namespace = std::string; using Key = std::string; using LPCallback = std::function; -auto GPGFRONTEND_CORE_EXPORT GetRealModuleIdentifier(const ModuleIdentifier& id) - -> ModuleIdentifier; - class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { Q_OBJECT public: @@ -78,6 +77,9 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { auto ListenRTPublish(QObject*, Namespace, Key, LPCallback) -> bool; + auto ListRTChildKeys(const std::string&, const std::string&) + -> std::vector; + private: class Impl; std::unique_ptr p_; @@ -114,6 +116,10 @@ auto GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, LPCallback) -> bool; +auto GPGFRONTEND_CORE_EXPORT ListRTChildKeys(const std::string& namespace_, + const std::string& key) + -> std::vector; + template auto RetrieveRTValueTyped(const std::string& namespace_, const std::string& key) -> std::optional { -- 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.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index cf845f96..76d6c042 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -91,13 +91,14 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { template void RegisterModule(Args&&... args) { ModuleManager::GetInstance()->RegisterModule( - std::make_shared(std::forward(args)...)); + GpgFrontend::SecureCreateSharedObject(std::forward(args)...)); } template void RegisterAndActivateModule(Args&&... args) { auto manager = ModuleManager::GetInstance(); - auto module = std::make_shared(std::forward(args)...); + auto module = + GpgFrontend::SecureCreateSharedObject(std::forward(args)...); manager->RegisterModule(module); manager->ActiveModule(module->GetModuleIdentifier()); } -- 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.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 76d6c042..bc05860b 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -63,6 +63,8 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { void RegisterModule(ModulePtr); + auto IsModuleActivated(ModuleIdentifier) -> bool; + void TriggerEvent(EventRefrernce); void ActiveModule(ModuleIdentifier); @@ -110,13 +112,43 @@ void TriggerEvent(const EventIdentifier& event_id, Args&&... args, std::move(MakeEvent(event_id, std::forward(args)..., e_cb))); } +/** + * @brief + * + * @return true + * @return false + */ +auto GPGFRONTEND_CORE_EXPORT IsModuleAcivate(ModuleIdentifier) -> bool; + +/** + * @brief + * + * @param namespace_ + * @param key + * @param value + * @return true + * @return false + */ auto GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, const std::string& key, const std::any& value) -> bool; +/** + * @brief + * + * @return true + * @return false + */ auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, LPCallback) -> bool; +/** + * @brief + * + * @param namespace_ + * @param key + * @return std::vector + */ auto GPGFRONTEND_CORE_EXPORT ListRTChildKeys(const std::string& namespace_, const std::string& key) -> std::vector; -- 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.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index bc05860b..1b1133da 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -57,7 +57,9 @@ using LPCallback = std::function; class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { Q_OBJECT public: - ~ModuleManager() override; + ModuleManager(); + + virtual ~ModuleManager() override; static auto GetInstance() -> ModuleMangerPtr; @@ -85,9 +87,6 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { private: class Impl; std::unique_ptr p_; - static ModuleMangerPtr g_; - - ModuleManager(); }; template -- 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.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 1b1133da..ace71c13 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -28,8 +28,10 @@ #pragma once +#include #include +#include "core/function/basic/GpgFunctionObject.h" #include "core/module/Event.h" namespace GpgFrontend::Thread { @@ -54,15 +56,13 @@ using Namespace = std::string; using Key = std::string; using LPCallback = std::function; -class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { - Q_OBJECT +class GPGFRONTEND_CORE_EXPORT ModuleManager + : public SingletonFunctionObject { public: - ModuleManager(); + explicit ModuleManager(int channel); virtual ~ModuleManager() override; - static auto GetInstance() -> ModuleMangerPtr; - void RegisterModule(ModulePtr); auto IsModuleActivated(ModuleIdentifier) -> bool; @@ -91,23 +91,23 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { template void RegisterModule(Args&&... args) { - ModuleManager::GetInstance()->RegisterModule( + ModuleManager::GetInstance().RegisterModule( GpgFrontend::SecureCreateSharedObject(std::forward(args)...)); } template void RegisterAndActivateModule(Args&&... args) { - auto manager = ModuleManager::GetInstance(); + auto& manager = ModuleManager::GetInstance(); auto module = GpgFrontend::SecureCreateSharedObject(std::forward(args)...); - manager->RegisterModule(module); - manager->ActiveModule(module->GetModuleIdentifier()); + manager.RegisterModule(module); + manager.ActiveModule(module->GetModuleIdentifier()); } template void TriggerEvent(const EventIdentifier& event_id, Args&&... args, Event::EventCallback e_cb = nullptr) { - ModuleManager::GetInstance()->TriggerEvent( + ModuleManager::GetInstance().TriggerEvent( std::move(MakeEvent(event_id, std::forward(args)..., e_cb))); } @@ -156,7 +156,7 @@ template auto RetrieveRTValueTyped(const std::string& namespace_, const std::string& key) -> std::optional { auto any_value = - ModuleManager::GetInstance()->RetrieveRTValue(namespace_, key); + ModuleManager::GetInstance().RetrieveRTValue(namespace_, key); if (any_value && any_value->type() == typeid(T)) { return std::any_cast(*any_value); } @@ -168,7 +168,7 @@ auto RetrieveRTValueTypedOrDefault(const std::string& namespace_, const std::string& key, const T& defaultValue) -> T { auto any_value = - ModuleManager::GetInstance()->RetrieveRTValue(namespace_, key); + ModuleManager::GetInstance().RetrieveRTValue(namespace_, key); if (any_value && any_value->type() == typeid(T)) { return std::any_cast(*any_value); } -- 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.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index ace71c13..bf00c87c 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -31,8 +31,10 @@ #include #include +#include "core/function/SecureMemoryAllocator.h" #include "core/function/basic/GpgFunctionObject.h" #include "core/module/Event.h" +#include "core/utils/MemoryUtils.h" namespace GpgFrontend::Thread { class TaskRunner; @@ -86,7 +88,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager private: class Impl; - std::unique_ptr p_; + SecureUniquePtr p_; }; template -- 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.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/core/module/ModuleManager.h') diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index bf00c87c..93b89e95 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -50,12 +50,12 @@ class GlobalModuleContext; class ModuleManager; using EventRefrernce = std::shared_ptr; -using ModuleIdentifier = std::string; +using ModuleIdentifier = QString; using ModulePtr = std::shared_ptr; using ModuleMangerPtr = std::shared_ptr; using GMCPtr = std::shared_ptr; -using Namespace = std::string; -using Key = std::string; +using Namespace = QString; +using Key = QString; using LPCallback = std::function; class GPGFRONTEND_CORE_EXPORT ModuleManager @@ -83,8 +83,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager auto ListenRTPublish(QObject*, Namespace, Key, LPCallback) -> bool; - auto ListRTChildKeys(const std::string&, const std::string&) - -> std::vector; + auto ListRTChildKeys(const QString&, const QString&) -> std::vector; private: class Impl; @@ -130,8 +129,8 @@ auto GPGFRONTEND_CORE_EXPORT IsModuleAcivate(ModuleIdentifier) -> bool; * @return true * @return false */ -auto GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, - const std::string& key, +auto GPGFRONTEND_CORE_EXPORT UpsertRTValue(const QString& namespace_, + const QString& key, const std::any& value) -> bool; /** @@ -150,12 +149,12 @@ auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, * @param key * @return std::vector */ -auto GPGFRONTEND_CORE_EXPORT ListRTChildKeys(const std::string& namespace_, - const std::string& key) +auto GPGFRONTEND_CORE_EXPORT ListRTChildKeys(const QString& namespace_, + const QString& key) -> std::vector; template -auto RetrieveRTValueTyped(const std::string& namespace_, const std::string& key) +auto RetrieveRTValueTyped(const QString& namespace_, const QString& key) -> std::optional { auto any_value = ModuleManager::GetInstance().RetrieveRTValue(namespace_, key); @@ -166,9 +165,9 @@ auto RetrieveRTValueTyped(const std::string& namespace_, const std::string& key) } template -auto RetrieveRTValueTypedOrDefault(const std::string& namespace_, - const std::string& key, - const T& defaultValue) -> T { +auto RetrieveRTValueTypedOrDefault(const QString& namespace_, + const QString& key, const T& defaultValue) + -> T { auto any_value = ModuleManager::GetInstance().RetrieveRTValue(namespace_, key); if (any_value && any_value->type() == typeid(T)) { -- cgit v1.2.3