mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19:10: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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include <scwx/qt/manager/text_event_manager.hpp>
|
||||
#include <scwx/awips/pvtec.hpp>
|
||||
#include <scwx/awips/text_product_file.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
#include <scwx/util/threads.hpp>
|
||||
|
|
@ -7,8 +6,6 @@
|
|||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
|
||||
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<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
|
||||
{
|
||||
public:
|
||||
explicit Impl() : textEventMap_ {}, textEventMutex_ {} {}
|
||||
explicit Impl(TextEventManager* self) :
|
||||
self_ {self}, textEventMap_ {}, textEventMutex_ {}
|
||||
{
|
||||
}
|
||||
|
||||
~Impl() {}
|
||||
|
||||
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>>,
|
||||
TextEventHash<TextEventKey>>
|
||||
types::TextEventHash<types::TextEventKey>>
|
||||
textEventMap_;
|
||||
std::shared_mutex textEventMutex_;
|
||||
};
|
||||
|
||||
TextEventManager::TextEventManager() : p(std::make_unique<Impl>()) {}
|
||||
TextEventManager::TextEventManager() : p(std::make_unique<Impl>(this)) {}
|
||||
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)
|
||||
{
|
||||
logger_->debug("LoadFile: {}", filename);
|
||||
|
|
@ -115,13 +98,15 @@ void TextEventManager::Impl::HandleMessage(
|
|||
|
||||
// Find a matching event in the event map
|
||||
auto& vtecString = segments[0]->header_->vtecString_;
|
||||
TextEventKey key {vtecString[0].pVtec_};
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/awips/text_product_message.hpp>
|
||||
#include <scwx/qt/types/text_event_key.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -20,10 +23,16 @@ public:
|
|||
explicit TextEventManager();
|
||||
~TextEventManager();
|
||||
|
||||
std::list<std::shared_ptr<awips::TextProductMessage>>
|
||||
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<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