mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:20:06 +00:00 
			
		
		
		
	Extracting text event key type, and adding interface to text event manager
This commit is contained in:
		
							parent
							
								
									54f38b6c1a
								
							
						
					
					
						commit
						5cf9746e97
					
				
					 5 changed files with 124 additions and 53 deletions
				
			
		|  | @ -100,8 +100,10 @@ set(HDR_SETTINGS source/scwx/qt/settings/general_settings.hpp | ||||||
| set(SRC_SETTINGS source/scwx/qt/settings/general_settings.cpp | set(SRC_SETTINGS source/scwx/qt/settings/general_settings.cpp | ||||||
|                  source/scwx/qt/settings/map_settings.cpp |                  source/scwx/qt/settings/map_settings.cpp | ||||||
|                  source/scwx/qt/settings/palette_settings.cpp) |                  source/scwx/qt/settings/palette_settings.cpp) | ||||||
| set(HDR_TYPES source/scwx/qt/types/radar_product_record.hpp) | set(HDR_TYPES source/scwx/qt/types/radar_product_record.hpp | ||||||
| set(SRC_TYPES source/scwx/qt/types/radar_product_record.cpp) |               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 | set(HDR_UI source/scwx/qt/ui/flow_layout.hpp | ||||||
|            source/scwx/qt/ui/level2_products_widget.hpp |            source/scwx/qt/ui/level2_products_widget.hpp | ||||||
|            source/scwx/qt/ui/level2_settings_widget.hpp |            source/scwx/qt/ui/level2_settings_widget.hpp | ||||||
|  |  | ||||||
|  | @ -1,5 +1,4 @@ | ||||||
| #include <scwx/qt/manager/text_event_manager.hpp> | #include <scwx/qt/manager/text_event_manager.hpp> | ||||||
| #include <scwx/awips/pvtec.hpp> |  | ||||||
| #include <scwx/awips/text_product_file.hpp> | #include <scwx/awips/text_product_file.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| #include <scwx/util/threads.hpp> | #include <scwx/util/threads.hpp> | ||||||
|  | @ -7,8 +6,6 @@ | ||||||
| #include <shared_mutex> | #include <shared_mutex> | ||||||
| #include <unordered_map> | #include <unordered_map> | ||||||
| 
 | 
 | ||||||
| #include <boost/container_hash/hash.hpp> |  | ||||||
| 
 |  | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
| namespace qt | namespace qt | ||||||
|  | @ -19,60 +16,46 @@ namespace manager | ||||||
| static const std::string logPrefix_ = "scwx::qt::manager::text_event_manager"; | static const std::string logPrefix_ = "scwx::qt::manager::text_event_manager"; | ||||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | 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<class Key> |  | ||||||
| struct TextEventHash; |  | ||||||
| 
 |  | ||||||
| template<> |  | ||||||
| struct TextEventHash<TextEventKey> |  | ||||||
| { |  | ||||||
|    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 | class TextEventManager::Impl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit Impl() : textEventMap_ {}, textEventMutex_ {} {} |    explicit Impl(TextEventManager* self) : | ||||||
|  |        self_ {self}, textEventMap_ {}, textEventMutex_ {} | ||||||
|  |    { | ||||||
|  |    } | ||||||
| 
 | 
 | ||||||
|    ~Impl() {} |    ~Impl() {} | ||||||
| 
 | 
 | ||||||
|    void HandleMessage(std::shared_ptr<awips::TextProductMessage> message); |    void HandleMessage(std::shared_ptr<awips::TextProductMessage> message); | ||||||
| 
 | 
 | ||||||
|    std::unordered_map<TextEventKey, |    TextEventManager* self_; | ||||||
|  | 
 | ||||||
|  |    std::unordered_map<types::TextEventKey, | ||||||
|                       std::list<std::shared_ptr<awips::TextProductMessage>>, |                       std::list<std::shared_ptr<awips::TextProductMessage>>, | ||||||
|                       TextEventHash<TextEventKey>> |                       types::TextEventHash<types::TextEventKey>> | ||||||
|                      textEventMap_; |                      textEventMap_; | ||||||
|    std::shared_mutex textEventMutex_; |    std::shared_mutex textEventMutex_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| TextEventManager::TextEventManager() : p(std::make_unique<Impl>()) {} | TextEventManager::TextEventManager() : p(std::make_unique<Impl>(this)) {} | ||||||
| TextEventManager::~TextEventManager() = default; | TextEventManager::~TextEventManager() = default; | ||||||
| 
 | 
 | ||||||
|  | std::list<std::shared_ptr<awips::TextProductMessage>> | ||||||
|  | TextEventManager::message_list(const types::TextEventKey& key) const | ||||||
|  | { | ||||||
|  |    std::list<std::shared_ptr<awips::TextProductMessage>> 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) | void TextEventManager::LoadFile(const std::string& filename) | ||||||
| { | { | ||||||
|    logger_->debug("LoadFile: {}", filename); |    logger_->debug("LoadFile: {}", filename); | ||||||
|  | @ -115,13 +98,15 @@ void TextEventManager::Impl::HandleMessage( | ||||||
| 
 | 
 | ||||||
|    // Find a matching event in the event map
 |    // Find a matching event in the event map
 | ||||||
|    auto&               vtecString = segments[0]->header_->vtecString_; |    auto&               vtecString = segments[0]->header_->vtecString_; | ||||||
|    TextEventKey key {vtecString[0].pVtec_}; |    types::TextEventKey key {vtecString[0].pVtec_}; | ||||||
|    auto                it      = textEventMap_.find(key); |    auto                it      = textEventMap_.find(key); | ||||||
|  |    bool                updated = false; | ||||||
| 
 | 
 | ||||||
|    if (it == textEventMap_.cend()) |    if (it == textEventMap_.cend()) | ||||||
|    { |    { | ||||||
|       // If there was no matching event, add the message to a new event
 |       // If there was no matching event, add the message to a new event
 | ||||||
|       textEventMap_.emplace(key, std::list {message}); |       textEventMap_.emplace(key, std::list {message}); | ||||||
|  |       updated = true; | ||||||
|    } |    } | ||||||
|    else if (std::find_if(it->second.cbegin(), |    else if (std::find_if(it->second.cbegin(), | ||||||
|                          it->second.cend(), |                          it->second.cend(), | ||||||
|  | @ -134,7 +119,15 @@ void TextEventManager::Impl::HandleMessage( | ||||||
|       // (WMO header equivalence check), add the updated message to the existing
 |       // (WMO header equivalence check), add the updated message to the existing
 | ||||||
|       // event
 |       // event
 | ||||||
|       it->second.push_back(message); |       it->second.push_back(message); | ||||||
|  |       updated = true; | ||||||
|    }; |    }; | ||||||
|  | 
 | ||||||
|  |    lock.unlock(); | ||||||
|  | 
 | ||||||
|  |    if (updated) | ||||||
|  |    { | ||||||
|  |       emit self_->AlertUpdated(key); | ||||||
|  |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| TextEventManager& TextEventManager::Instance() | TextEventManager& TextEventManager::Instance() | ||||||
|  | @ -143,12 +136,6 @@ TextEventManager& TextEventManager::Instance() | ||||||
|    return textEventManager_; |    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 manager
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,8 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
|  | #include <scwx/awips/text_product_message.hpp> | ||||||
|  | #include <scwx/qt/types/text_event_key.hpp> | ||||||
|  | 
 | ||||||
| #include <memory> | #include <memory> | ||||||
| #include <string> | #include <string> | ||||||
| 
 | 
 | ||||||
|  | @ -20,10 +23,16 @@ public: | ||||||
|    explicit TextEventManager(); |    explicit TextEventManager(); | ||||||
|    ~TextEventManager(); |    ~TextEventManager(); | ||||||
| 
 | 
 | ||||||
|  |    std::list<std::shared_ptr<awips::TextProductMessage>> | ||||||
|  |    message_list(const types::TextEventKey& key) const; | ||||||
|  | 
 | ||||||
|    void LoadFile(const std::string& filename); |    void LoadFile(const std::string& filename); | ||||||
| 
 | 
 | ||||||
|    static TextEventManager& Instance(); |    static TextEventManager& Instance(); | ||||||
| 
 | 
 | ||||||
|  | signals: | ||||||
|  |    void AlertUpdated(const types::TextEventKey& key); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
|    std::unique_ptr<Impl> p; |    std::unique_ptr<Impl> p; | ||||||
|  |  | ||||||
							
								
								
									
										32
									
								
								scwx-qt/source/scwx/qt/types/text_event_key.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								scwx-qt/source/scwx/qt/types/text_event_key.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,32 @@ | ||||||
|  | #include <scwx/qt/types/text_event_key.hpp> | ||||||
|  | 
 | ||||||
|  | #include <boost/container_hash/hash.hpp> | ||||||
|  | 
 | ||||||
|  | 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<TextEventKey>::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
 | ||||||
							
								
								
									
										41
									
								
								scwx-qt/source/scwx/qt/types/text_event_key.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								scwx-qt/source/scwx/qt/types/text_event_key.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <scwx/awips/pvtec.hpp> | ||||||
|  | 
 | ||||||
|  | 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<class Key> | ||||||
|  | struct TextEventHash; | ||||||
|  | 
 | ||||||
|  | template<> | ||||||
|  | struct TextEventHash<TextEventKey> | ||||||
|  | { | ||||||
|  |    size_t operator()(const TextEventKey& x) const; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | } // namespace types
 | ||||||
|  | } // namespace qt
 | ||||||
|  | } // namespace scwx
 | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat