mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 15:10:06 +00:00
Alert layer should handle alerts by UUID if messages are received out of sequence
This commit is contained in:
parent
3f83c8e4a9
commit
16507adbe9
5 changed files with 46 additions and 7 deletions
|
|
@ -245,7 +245,7 @@ void TextEventManager::Impl::HandleMessage(
|
|||
|
||||
if (updated)
|
||||
{
|
||||
Q_EMIT self_->AlertUpdated(key, messageIndex);
|
||||
Q_EMIT self_->AlertUpdated(key, messageIndex, message->uuid());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue