diff options
author | Saturneric <[email protected]> | 2023-10-24 13:22:13 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2023-10-24 13:42:16 +0000 |
commit | fa2e87a48acbc32650ca9db073b991729dfba622 (patch) | |
tree | 1076f6b2eac737d0559cd78e70b44975c789980e /src/core/module/ModuleManager.h | |
parent | fix: solve build issues on macOS (diff) | |
download | GpgFrontend-fa2e87a48acbc32650ca9db073b991729dfba622.tar.gz GpgFrontend-fa2e87a48acbc32650ca9db073b991729dfba622.zip |
feat: use module instead of integrated code at version checking task
Diffstat (limited to 'src/core/module/ModuleManager.h')
-rw-r--r-- | src/core/module/ModuleManager.h | 32 |
1 files changed, 32 insertions, 0 deletions
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<ModuleManager>; using GMCPtr = std::shared_ptr<GlobalModuleContext>; using Namespace = std::string; using Key = std::string; +using LPCallback = std::function<void(Namespace, Key, int)>; + +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<std::any> RetrieveRTValue(Namespace, Key); + bool ListenPublish(QObject*, Namespace, Key, LPCallback); + private: class Impl; std::unique_ptr<Impl> p_; @@ -100,4 +106,30 @@ void TriggerEvent(const EventIdentifier& event_id, Args&&... args) { std::move(MakeEvent(event_id, std::forward<Args>(args)...))); } +bool GPGFRONTEND_CORE_EXPORT UpsertRTValueTyped(const std::string& namespace_, + const std::string& key, + const std::any& value); + +template <typename T> +std::optional<T> 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<T>(*any_value); + } + return std::nullopt; +} + +template <typename T> +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<T>(*any_value); + } + return defaultValue; +} + } // namespace GpgFrontend::Module
\ No newline at end of file |