diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index bec14b1f..af351f33 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -100,8 +100,10 @@ set(HDR_SETTINGS source/scwx/qt/settings/general_settings.hpp set(SRC_SETTINGS source/scwx/qt/settings/general_settings.cpp source/scwx/qt/settings/map_settings.cpp source/scwx/qt/settings/palette_settings.cpp) -set(HDR_TYPES source/scwx/qt/types/radar_product_record.hpp) -set(SRC_TYPES source/scwx/qt/types/radar_product_record.cpp) +set(HDR_TYPES source/scwx/qt/types/radar_product_record.hpp + source/scwx/qt/types/text_event_key.hpp) +set(SRC_TYPES source/scwx/qt/types/radar_product_record.cpp + source/scwx/qt/types/text_event_key.cpp) set(HDR_UI source/scwx/qt/ui/flow_layout.hpp source/scwx/qt/ui/level2_products_widget.hpp source/scwx/qt/ui/level2_settings_widget.hpp diff --git a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp index 8311c233..eb64867a 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -7,8 +6,6 @@ #include #include -#include - namespace scwx { namespace qt @@ -19,60 +16,46 @@ namespace manager static const std::string logPrefix_ = "scwx::qt::manager::text_event_manager"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); -struct TextEventKey -{ - TextEventKey(const awips::PVtec& pvtec) : - officeId_ {pvtec.office_id()}, - phenomenon_ {pvtec.phenomenon()}, - significance_ {pvtec.significance()}, - etn_ {pvtec.event_tracking_number()} - { - } - - bool operator==(const TextEventKey& o) const; - - std::string officeId_; - awips::Phenomenon phenomenon_; - awips::Significance significance_; - int16_t etn_; -}; - -template -struct TextEventHash; - -template<> -struct TextEventHash -{ - size_t operator()(const TextEventKey& x) const - { - size_t seed = 0; - boost::hash_combine(seed, x.officeId_); - boost::hash_combine(seed, x.phenomenon_); - boost::hash_combine(seed, x.significance_); - boost::hash_combine(seed, x.etn_); - return seed; - } -}; - class TextEventManager::Impl { public: - explicit Impl() : textEventMap_ {}, textEventMutex_ {} {} + explicit Impl(TextEventManager* self) : + self_ {self}, textEventMap_ {}, textEventMutex_ {} + { + } ~Impl() {} void HandleMessage(std::shared_ptr message); - std::unordered_map>, - TextEventHash> + types::TextEventHash> textEventMap_; std::shared_mutex textEventMutex_; }; -TextEventManager::TextEventManager() : p(std::make_unique()) {} +TextEventManager::TextEventManager() : p(std::make_unique(this)) {} TextEventManager::~TextEventManager() = default; +std::list> +TextEventManager::message_list(const types::TextEventKey& key) const +{ + std::list> messageList {}; + + std::shared_lock lock(p->textEventMutex_); + + auto it = p->textEventMap_.find(key); + if (it != p->textEventMap_.cend()) + { + messageList = it->second; + } + + return messageList; +} + void TextEventManager::LoadFile(const std::string& filename) { logger_->debug("LoadFile: {}", filename); @@ -114,14 +97,16 @@ void TextEventManager::Impl::HandleMessage( std::unique_lock lock(textEventMutex_); // Find a matching event in the event map - auto& vtecString = segments[0]->header_->vtecString_; - TextEventKey key {vtecString[0].pVtec_}; - auto it = textEventMap_.find(key); + auto& vtecString = segments[0]->header_->vtecString_; + types::TextEventKey key {vtecString[0].pVtec_}; + auto it = textEventMap_.find(key); + bool updated = false; if (it == textEventMap_.cend()) { // If there was no matching event, add the message to a new event textEventMap_.emplace(key, std::list {message}); + updated = true; } else if (std::find_if(it->second.cbegin(), it->second.cend(), @@ -134,7 +119,15 @@ void TextEventManager::Impl::HandleMessage( // (WMO header equivalence check), add the updated message to the existing // event it->second.push_back(message); + updated = true; }; + + lock.unlock(); + + if (updated) + { + emit self_->AlertUpdated(key); + } } TextEventManager& TextEventManager::Instance() @@ -143,12 +136,6 @@ TextEventManager& TextEventManager::Instance() return textEventManager_; } -bool TextEventKey::operator==(const TextEventKey& o) const -{ - return (officeId_ == o.officeId_ && phenomenon_ == o.phenomenon_ && - significance_ == o.significance_ && etn_ == o.etn_); -} - } // namespace manager } // namespace qt } // namespace scwx diff --git a/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp b/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp index 91e52f68..b29a8ebb 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp @@ -1,5 +1,8 @@ #pragma once +#include +#include + #include #include @@ -20,10 +23,16 @@ public: explicit TextEventManager(); ~TextEventManager(); + std::list> + message_list(const types::TextEventKey& key) const; + void LoadFile(const std::string& filename); static TextEventManager& Instance(); +signals: + void AlertUpdated(const types::TextEventKey& key); + private: class Impl; std::unique_ptr p; diff --git a/scwx-qt/source/scwx/qt/types/text_event_key.cpp b/scwx-qt/source/scwx/qt/types/text_event_key.cpp new file mode 100644 index 00000000..02775c13 --- /dev/null +++ b/scwx-qt/source/scwx/qt/types/text_event_key.cpp @@ -0,0 +1,32 @@ +#include + +#include + +namespace scwx +{ +namespace qt +{ +namespace types +{ + +static const std::string logPrefix_ = "scwx::qt::types::text_event_key"; + +bool TextEventKey::operator==(const TextEventKey& o) const +{ + return (officeId_ == o.officeId_ && phenomenon_ == o.phenomenon_ && + significance_ == o.significance_ && etn_ == o.etn_); +} + +size_t TextEventHash::operator()(const TextEventKey& x) const +{ + size_t seed = 0; + boost::hash_combine(seed, x.officeId_); + boost::hash_combine(seed, x.phenomenon_); + boost::hash_combine(seed, x.significance_); + boost::hash_combine(seed, x.etn_); + return seed; +} + +} // namespace types +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/types/text_event_key.hpp b/scwx-qt/source/scwx/qt/types/text_event_key.hpp new file mode 100644 index 00000000..02b960a4 --- /dev/null +++ b/scwx-qt/source/scwx/qt/types/text_event_key.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include + +namespace scwx +{ +namespace qt +{ +namespace types +{ + +struct TextEventKey +{ + TextEventKey(const awips::PVtec& pvtec) : + officeId_ {pvtec.office_id()}, + phenomenon_ {pvtec.phenomenon()}, + significance_ {pvtec.significance()}, + etn_ {pvtec.event_tracking_number()} + { + } + + bool operator==(const TextEventKey& o) const; + + std::string officeId_; + awips::Phenomenon phenomenon_; + awips::Significance significance_; + int16_t etn_; +}; + +template +struct TextEventHash; + +template<> +struct TextEventHash +{ + size_t operator()(const TextEventKey& x) const; +}; + +} // namespace types +} // namespace qt +} // namespace scwx