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.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/core/module/Module.h (limited to 'src/core/module/Module.h') diff --git a/src/core/module/Module.h b/src/core/module/Module.h new file mode 100644 index 00000000..bb7678ae --- /dev/null +++ b/src/core/module/Module.h @@ -0,0 +1,87 @@ +/** + * 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_MODULE_H +#define GPGFRONTEND_MODULE_H + +#include + +#include "core/module/Event.h" +#include "core/thread/Task.h" +#include "core/thread/TaskRunner.h" + +namespace GpgFrontend::Module { + +class Module; +class GlobalModuleContext; +class ModuleManager; + +using ModuleIdentifier = std::string; +using ModuleVersion = std::string; +using ModuleMetaData = std::map; +using ModulePtr = std::shared_ptr; +using GlobalModuleContextPtr = std::shared_ptr; + +using TaskRunnerPtr = std::shared_ptr; + +class GPGFRONTEND_CORE_EXPORT Module : public QObject { + Q_OBJECT + public: + Module(ModuleIdentifier, ModuleVersion, ModuleMetaData); + + ~Module(); + + virtual bool Register() = 0; + + virtual bool Active() = 0; + + virtual int Exec(EventRefrernce) = 0; + + virtual bool Deactive() = 0; + + ModuleIdentifier GetModuleIdentifier() const; + + void SetGPC(GlobalModuleContextPtr); + + protected: + int getChannel(); + + int getDefaultChannel(); + + TaskRunnerPtr getTaskRunner(); + + bool listenEvent(EventIdentifier); + + private: + class Impl; + std::unique_ptr p_; +}; + +} // namespace GpgFrontend::Module + +#endif // GPGFRONTEND_MODULE_H \ No newline at end of file -- 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.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/core/module/Module.h') diff --git a/src/core/module/Module.h b/src/core/module/Module.h index bb7678ae..d2f6aa3b 100644 --- a/src/core/module/Module.h +++ b/src/core/module/Module.h @@ -26,10 +26,7 @@ * */ -#ifndef GPGFRONTEND_MODULE_H -#define GPGFRONTEND_MODULE_H - -#include +#pragma once #include "core/module/Event.h" #include "core/thread/Task.h" @@ -45,7 +42,7 @@ using ModuleIdentifier = std::string; using ModuleVersion = std::string; using ModuleMetaData = std::map; using ModulePtr = std::shared_ptr; -using GlobalModuleContextPtr = std::shared_ptr; +using GMCPtr = std::shared_ptr; using TaskRunnerPtr = std::shared_ptr; @@ -66,7 +63,7 @@ class GPGFRONTEND_CORE_EXPORT Module : public QObject { ModuleIdentifier GetModuleIdentifier() const; - void SetGPC(GlobalModuleContextPtr); + void SetGPC(GMCPtr); protected: int getChannel(); @@ -82,6 +79,4 @@ class GPGFRONTEND_CORE_EXPORT Module : public QObject { std::unique_ptr p_; }; -} // namespace GpgFrontend::Module - -#endif // GPGFRONTEND_MODULE_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/Module.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/core/module/Module.h') diff --git a/src/core/module/Module.h b/src/core/module/Module.h index d2f6aa3b..da87f88e 100644 --- a/src/core/module/Module.h +++ b/src/core/module/Module.h @@ -29,7 +29,6 @@ #pragma once #include "core/module/Event.h" -#include "core/thread/Task.h" #include "core/thread/TaskRunner.h" namespace GpgFrontend::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/Module.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/core/module/Module.h') diff --git a/src/core/module/Module.h b/src/core/module/Module.h index da87f88e..6cc1cc3f 100644 --- a/src/core/module/Module.h +++ b/src/core/module/Module.h @@ -41,7 +41,6 @@ using ModuleIdentifier = std::string; using ModuleVersion = std::string; using ModuleMetaData = std::map; using ModulePtr = std::shared_ptr; -using GMCPtr = std::shared_ptr; using TaskRunnerPtr = std::shared_ptr; @@ -52,26 +51,26 @@ class GPGFRONTEND_CORE_EXPORT Module : public QObject { ~Module(); - virtual bool Register() = 0; + virtual auto Register() -> bool = 0; - virtual bool Active() = 0; + virtual auto Active() -> bool = 0; - virtual int Exec(EventRefrernce) = 0; + virtual auto Exec(EventRefrernce) -> int = 0; - virtual bool Deactive() = 0; + virtual auto Deactive() -> bool = 0; - ModuleIdentifier GetModuleIdentifier() const; + [[nodiscard]] auto GetModuleIdentifier() const -> ModuleIdentifier; - void SetGPC(GMCPtr); + void SetGPC(GlobalModuleContext*); protected: - int getChannel(); + auto getChannel() -> int; - int getDefaultChannel(); + auto getDefaultChannel() -> int; - TaskRunnerPtr getTaskRunner(); + auto getTaskRunner() -> TaskRunnerPtr; - bool listenEvent(EventIdentifier); + auto listenEvent(EventIdentifier) -> bool; private: class Impl; -- 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/module/Module.h') diff --git a/src/core/module/Module.h b/src/core/module/Module.h index 6cc1cc3f..fe672698 100644 --- a/src/core/module/Module.h +++ b/src/core/module/Module.h @@ -74,7 +74,7 @@ class GPGFRONTEND_CORE_EXPORT Module : public QObject { private: class Impl; - std::unique_ptr p_; + SecureUniquePtr p_; }; } // namespace GpgFrontend::Module \ No newline at end of file -- 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.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/module/Module.h') diff --git a/src/core/module/Module.h b/src/core/module/Module.h index fe672698..2742475e 100644 --- a/src/core/module/Module.h +++ b/src/core/module/Module.h @@ -37,9 +37,9 @@ class Module; class GlobalModuleContext; class ModuleManager; -using ModuleIdentifier = std::string; -using ModuleVersion = std::string; -using ModuleMetaData = std::map; +using ModuleIdentifier = QString; +using ModuleVersion = QString; +using ModuleMetaData = std::map; using ModulePtr = std::shared_ptr; using TaskRunnerPtr = std::shared_ptr; -- 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/module/Module.h') diff --git a/src/core/module/Module.h b/src/core/module/Module.h index 2742475e..2a5b54e7 100644 --- a/src/core/module/Module.h +++ b/src/core/module/Module.h @@ -47,7 +47,7 @@ using TaskRunnerPtr = std::shared_ptr; class GPGFRONTEND_CORE_EXPORT Module : public QObject { Q_OBJECT public: - Module(ModuleIdentifier, ModuleVersion, ModuleMetaData); + Module(ModuleIdentifier, ModuleVersion, const ModuleMetaData&); ~Module(); -- cgit v1.2.3