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

View file

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

View file

@ -171,7 +171,8 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const
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());
@ -181,7 +182,7 @@ void AlertModel::HandleAlert(const types::TextEventKey& alertKey)
auto alertMessages =
manager::TextEventManager::Instance().message_list(alertKey);
std::shared_ptr<const awips::Segment> alertSegment =
alertMessages.back()->segments().back();
alertMessages[messageIndex]->segments().back();
if (alertSegment->codedLocation_.has_value())
{

View file

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