Alert layer should handle alerts by UUID if messages are received out of sequence

This commit is contained in:
Dan Paulat 2025-04-05 08:14:18 -05:00
parent 3f83c8e4a9
commit 16507adbe9
5 changed files with 46 additions and 7 deletions

View file

@ -245,7 +245,7 @@ void TextEventManager::Impl::HandleMessage(
if (updated)
{
Q_EMIT self_->AlertUpdated(key, messageIndex);
Q_EMIT self_->AlertUpdated(key, messageIndex, message->uuid());
}
}

View file

@ -6,6 +6,7 @@
#include <memory>
#include <string>
#include <boost/uuid/uuid.hpp>
#include <QObject>
namespace scwx
@ -32,7 +33,9 @@ public:
static std::shared_ptr<TextEventManager> Instance();
signals:
void AlertUpdated(const types::TextEventKey& key, size_t messageIndex);
void AlertUpdated(const types::TextEventKey& key,
std::size_t messageIndex,
boost::uuids::uuid uuid);
private:
class Impl;

View file

@ -73,8 +73,10 @@ public:
connect(textEventManager_.get(),
&manager::TextEventManager::AlertUpdated,
this,
[this](const types::TextEventKey& key, std::size_t messageIndex)
{ HandleAlert(key, messageIndex); });
[this](const types::TextEventKey& key,
std::size_t messageIndex,
boost::uuids::uuid uuid)
{ HandleAlert(key, messageIndex, uuid); });
}
~AlertLayerHandler()
{
@ -95,7 +97,9 @@ public:
types::TextEventHash<types::TextEventKey>>
segmentsByKey_ {};
void HandleAlert(const types::TextEventKey& key, size_t messageIndex);
void HandleAlert(const types::TextEventKey& key,
size_t messageIndex,
boost::uuids::uuid uuid);
static AlertLayerHandler& Instance();
@ -322,7 +326,8 @@ bool IsAlertActive(const std::shared_ptr<const awips::Segment>& segment)
}
void AlertLayerHandler::HandleAlert(const types::TextEventKey& key,
size_t messageIndex)
size_t messageIndex,
boost::uuids::uuid uuid)
{
logger_->trace("HandleAlert: {}", key.ToString());
@ -330,7 +335,27 @@ void AlertLayerHandler::HandleAlert(const types::TextEventKey& key,
AlertTypeHash<std::pair<awips::Phenomenon, bool>>>
alertsUpdated {};
auto message = textEventManager_->message_list(key).at(messageIndex);
const auto& messageList = textEventManager_->message_list(key);
auto message = messageList.at(messageIndex);
if (message->uuid() != uuid)
{
// Find message by UUID instead of index, as the message index could have
// changed between the signal being emitted and the handler being called
auto it = std::find_if(messageList.cbegin(),
messageList.cend(),
[&uuid](const auto& message)
{ return uuid == message->uuid(); });
if (it == messageList.cend())
{
logger_->warn(
"Could not find alert uuid: {} ({})", key.ToString(), messageIndex);
return;
}
message = *it;
}
// Determine start time for first segment
std::chrono::system_clock::time_point segmentBegin {};

View file

@ -13,6 +13,8 @@
#include <memory>
#include <string>
#include <boost/uuid/uuid.hpp>
namespace scwx
{
namespace awips
@ -94,6 +96,7 @@ public:
TextProductMessage(TextProductMessage&&) noexcept;
TextProductMessage& operator=(TextProductMessage&&) noexcept;
boost::uuids::uuid uuid() const;
std::string message_content() const;
std::shared_ptr<WmoHeader> wmo_header() const;
std::vector<std::string> mnd_header() const;

View file

@ -9,6 +9,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/uuid/random_generator.hpp>
#include <re2/re2.h>
namespace scwx::awips
@ -53,6 +54,8 @@ public:
TextProductMessageImpl(const TextProductMessageImpl&&) = delete;
TextProductMessageImpl& operator=(const TextProductMessageImpl&&) = delete;
boost::uuids::uuid uuid_ {boost::uuids::random_generator()()};
std::string messageContent_;
std::shared_ptr<WmoHeader> wmoHeader_;
std::vector<std::string> mndHeader_;
@ -70,6 +73,11 @@ TextProductMessage::TextProductMessage(TextProductMessage&&) noexcept = default;
TextProductMessage&
TextProductMessage::operator=(TextProductMessage&&) noexcept = default;
boost::uuids::uuid TextProductMessage::uuid() const
{
return p->uuid_;
}
std::string TextProductMessage::message_content() const
{
return p->messageContent_;