Update alert signal to include message index, so messages aren't missed

This commit is contained in:
Dan Paulat 2022-10-15 17:41:46 -05:00
parent 5784abc117
commit 1c5e0d51b7
4 changed files with 16 additions and 12 deletions

View file

@ -40,17 +40,17 @@ public:
TextEventManager::TextEventManager() : p(std::make_unique<Impl>(this)) {} TextEventManager::TextEventManager() : p(std::make_unique<Impl>(this)) {}
TextEventManager::~TextEventManager() = default; TextEventManager::~TextEventManager() = default;
std::list<std::shared_ptr<awips::TextProductMessage>> std::vector<std::shared_ptr<awips::TextProductMessage>>
TextEventManager::message_list(const types::TextEventKey& key) const TextEventManager::message_list(const types::TextEventKey& key) const
{ {
std::list<std::shared_ptr<awips::TextProductMessage>> messageList {}; std::vector<std::shared_ptr<awips::TextProductMessage>> messageList {};
std::shared_lock lock(p->textEventMutex_); std::shared_lock lock(p->textEventMutex_);
auto it = p->textEventMap_.find(key); auto it = p->textEventMap_.find(key);
if (it != p->textEventMap_.cend()) if (it != p->textEventMap_.cend())
{ {
messageList = it->second; messageList.assign(it->second.begin(), it->second.end());
} }
return messageList; return messageList;
@ -109,6 +109,7 @@ 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_;
types::TextEventKey key {vtecString[0].pVtec_}; types::TextEventKey key {vtecString[0].pVtec_};
size_t messageIndex = 0;
auto it = textEventMap_.find(key); auto it = textEventMap_.find(key);
bool updated = false; bool updated = false;
@ -116,6 +117,7 @@ void TextEventManager::Impl::HandleMessage(
{ {
// 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});
messageIndex = 0;
updated = true; updated = true;
} }
else if (std::find_if(it->second.cbegin(), else if (std::find_if(it->second.cbegin(),
@ -128,6 +130,7 @@ void TextEventManager::Impl::HandleMessage(
// If there was a matching event, and this message has not been stored // If there was a matching event, and this message has not been stored
// (WMO header equivalence check), add the updated message to the existing // (WMO header equivalence check), add the updated message to the existing
// event // event
messageIndex = it->second.size();
it->second.push_back(message); it->second.push_back(message);
updated = true; updated = true;
}; };
@ -136,7 +139,7 @@ void TextEventManager::Impl::HandleMessage(
if (updated) if (updated)
{ {
emit self_->AlertUpdated(key); emit self_->AlertUpdated(key, messageIndex);
} }
} }

View file

@ -23,7 +23,7 @@ public:
explicit TextEventManager(); explicit TextEventManager();
~TextEventManager(); ~TextEventManager();
std::list<std::shared_ptr<awips::TextProductMessage>> std::vector<std::shared_ptr<awips::TextProductMessage>>
message_list(const types::TextEventKey& key) const; message_list(const types::TextEventKey& key) const;
void LoadFile(const std::string& filename); void LoadFile(const std::string& filename);
@ -31,7 +31,7 @@ public:
static TextEventManager& Instance(); static TextEventManager& Instance();
signals: signals:
void AlertUpdated(const types::TextEventKey& key); void AlertUpdated(const types::TextEventKey& key, size_t messageIndex);
private: private:
class Impl; class Impl;

View file

@ -171,7 +171,8 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const
return QVariant(); return QVariant();
} }
void AlertModel::HandleAlert(const types::TextEventKey& alertKey) void AlertModel::HandleAlert(const types::TextEventKey& alertKey,
size_t messageIndex)
{ {
logger_->trace("Handle alert: {}", alertKey.ToString()); logger_->trace("Handle alert: {}", alertKey.ToString());
@ -181,7 +182,7 @@ void AlertModel::HandleAlert(const types::TextEventKey& alertKey)
auto alertMessages = auto alertMessages =
manager::TextEventManager::Instance().message_list(alertKey); manager::TextEventManager::Instance().message_list(alertKey);
std::shared_ptr<const awips::Segment> alertSegment = std::shared_ptr<const awips::Segment> alertSegment =
alertMessages.back()->segments().back(); alertMessages[messageIndex]->segments().back();
if (alertSegment->codedLocation_.has_value()) if (alertSegment->codedLocation_.has_value())
{ {

View file

@ -31,7 +31,7 @@ public:
int role = Qt::DisplayRole) const override; int role = Qt::DisplayRole) const override;
public slots: public slots:
void HandleAlert(const types::TextEventKey& alertKey); void HandleAlert(const types::TextEventKey& alertKey, size_t messageIndex);
void HandleMapUpdate(double latitude, double longitude); void HandleMapUpdate(double latitude, double longitude);
private: private: