diff options
author | Saturneric <[email protected]> | 2023-10-25 07:40:43 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2023-10-25 07:40:43 +0000 |
commit | a23b2fbc707406dec0dd924c089b4285bc7f0010 (patch) | |
tree | 7773e4a3e45a26a38735450f065c637e170f202d /src/core | |
parent | feat: use module instead of integrated code at version checking task (diff) | |
download | GpgFrontend-a23b2fbc707406dec0dd924c089b4285bc7f0010.tar.gz GpgFrontend-a23b2fbc707406dec0dd924c089b4285bc7f0010.zip |
feat: use rt listen publish event function in main windows' app version upgrade notification
Diffstat (limited to '')
-rw-r--r-- | src/core/GpgFunctionObject.h | 2 | ||||
-rw-r--r-- | src/core/function/CacheManager.cpp | 4 | ||||
-rw-r--r-- | src/core/module/GlobalRegisterTable.cpp | 59 | ||||
-rw-r--r-- | src/core/module/ModuleManager.cpp | 13 | ||||
-rw-r--r-- | src/core/module/ModuleManager.h | 11 |
5 files changed, 53 insertions, 36 deletions
diff --git a/src/core/GpgFunctionObject.h b/src/core/GpgFunctionObject.h index 37315b68..7a26828a 100644 --- a/src/core/GpgFunctionObject.h +++ b/src/core/GpgFunctionObject.h @@ -225,7 +225,7 @@ class SingletonFunctionObject : public ChannelObject { if (_p_pbj == nullptr) { return *( - T*)(p_storage->SetObjectInChannel(channel, std::move(factory()))); + T*)(p_storage->SetObjectInChannel(channel, factory())); } else return *_p_pbj; } diff --git a/src/core/function/CacheManager.cpp b/src/core/function/CacheManager.cpp index 1794735a..27133957 100644 --- a/src/core/function/CacheManager.cpp +++ b/src/core/function/CacheManager.cpp @@ -36,8 +36,8 @@ #include "spdlog/spdlog.h" GpgFrontend::CacheManager::CacheManager(int channel) - : m_timer_(new QTimer(this)), - SingletonFunctionObject<CacheManager>(channel) { + : SingletonFunctionObject<CacheManager>(channel), + m_timer_(new QTimer(this)) { connect(m_timer_, &QTimer::timeout, this, &CacheManager::flush_cache_storage); m_timer_->start(15000); diff --git a/src/core/module/GlobalRegisterTable.cpp b/src/core/module/GlobalRegisterTable.cpp index a4910f9f..42a8f1f7 100644 --- a/src/core/module/GlobalRegisterTable.cpp +++ b/src/core/module/GlobalRegisterTable.cpp @@ -52,42 +52,51 @@ class GlobalRegisterTable::Impl { : parent_(parent), global_register_table_() {} bool PublishKV(Namespace n, Key k, std::any v) { - std::unique_lock lock(lock_); SPDLOG_DEBUG("publishing kv to rt, n: {}, k: {}, v type: {}", n, k, v.type().name()); - auto& sub_table = - global_register_table_.emplace(n, SubTable{}).first->second; - - auto sub_it = sub_table.find(k); - if (sub_it == sub_table.end()) { - sub_it = sub_table.emplace(k, std::make_unique<Value>(Value{v})).first; - SPDLOG_DEBUG("new kv in rt, created n: {}, k: {}, v type: {}", n, k, - v.type().name()); - } else { - if (sub_it->second->type != v.type()) { - return false; + int version = 0; + + { + std::unique_lock lock(lock_); + auto& sub_table = + global_register_table_.emplace(n, SubTable{}).first->second; + + auto sub_it = sub_table.find(k); + if (sub_it == sub_table.end()) { + sub_it = sub_table.emplace(k, std::make_unique<Value>(Value{v})).first; + SPDLOG_DEBUG("new kv in rt, created n: {}, k: {}, v type: {}", n, k, + v.type().name()); + } else { + if (sub_it->second->type != v.type()) { + return false; + } + sub_it->second->value = v; } - sub_it->second->value = v; + version = ++sub_it->second->version; } - sub_it->second->version++; - emit parent_->SignalPublish(n, k, sub_it->second->version); + emit parent_->SignalPublish(n, k, version); + SPDLOG_DEBUG("published kv to rt, n: {}, k: {}", n, k); return true; } std::optional<std::any> LookupKV(Namespace n, Key k) { - std::shared_lock lock(lock_); SPDLOG_DEBUG("looking up kv in rt, n: {}, k: {}", n, k); - - auto it = global_register_table_.find(n); - if (it == global_register_table_.end()) return std::nullopt; - - auto& sub_table = it->second; - auto sub_it = sub_table.find(k); - return (sub_it != sub_table.end()) - ? std::optional<std::any>{sub_it->second->value} - : std::nullopt; + std::optional<std::any> rtn = std::nullopt; + { + std::shared_lock lock(lock_); + auto it = global_register_table_.find(n); + if (it == global_register_table_.end()) return std::nullopt; + + auto& sub_table = it->second; + auto sub_it = sub_table.find(k); + rtn = (sub_it != sub_table.end()) + ? std::optional<std::any>{sub_it->second->value} + : std::nullopt; + } + SPDLOG_DEBUG("looking up kv in rt done, n: {}, k: {}", n, k); + return rtn; } bool ListenPublish(QObject* o, Namespace n, Key k, LPCallback c) { 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<Impl>()) {} ModuleManager::~ModuleManager() = default; @@ -140,8 +145,8 @@ std::optional<std::any> 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); } 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<std::any> 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>(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 <typename T> std::optional<T> RetrieveRTValueTyped(const std::string& namespace_, |