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) 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 <memory>
#include <string> #include <string>
#include <boost/uuid/uuid.hpp>
#include <QObject> #include <QObject>
namespace scwx namespace scwx
@ -32,7 +33,9 @@ public:
static std::shared_ptr<TextEventManager> Instance(); static std::shared_ptr<TextEventManager> Instance();
signals: 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: private:
class Impl; class Impl;

View file

@ -73,8 +73,10 @@ public:
connect(textEventManager_.get(), connect(textEventManager_.get(),
&manager::TextEventManager::AlertUpdated, &manager::TextEventManager::AlertUpdated,
this, this,
[this](const types::TextEventKey& key, std::size_t messageIndex) [this](const types::TextEventKey& key,
{ HandleAlert(key, messageIndex); }); std::size_t messageIndex,
boost::uuids::uuid uuid)
{ HandleAlert(key, messageIndex, uuid); });
} }
~AlertLayerHandler() ~AlertLayerHandler()
{ {
@ -95,7 +97,9 @@ public:
types::TextEventHash<types::TextEventKey>> types::TextEventHash<types::TextEventKey>>
segmentsByKey_ {}; 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(); static AlertLayerHandler& Instance();
@ -322,7 +326,8 @@ bool IsAlertActive(const std::shared_ptr<const awips::Segment>& segment)
} }
void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, void AlertLayerHandler::HandleAlert(const types::TextEventKey& key,
size_t messageIndex) size_t messageIndex,
boost::uuids::uuid uuid)
{ {
logger_->trace("HandleAlert: {}", key.ToString()); logger_->trace("HandleAlert: {}", key.ToString());
@ -330,7 +335,27 @@ void AlertLayerHandler::HandleAlert(const types::TextEventKey& key,
AlertTypeHash<std::pair<awips::Phenomenon, bool>>> AlertTypeHash<std::pair<awips::Phenomenon, bool>>>
alertsUpdated {}; 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 // Determine start time for first segment
std::chrono::system_clock::time_point segmentBegin {}; std::chrono::system_clock::time_point segmentBegin {};

View file

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