Handle empty message lists for text event keys

Partial fix for #44, application should no longer crash, but erroneous behavior may remain
This commit is contained in:
Dan Paulat 2023-05-11 22:26:48 -05:00
parent 7f624e1263
commit fceb5c33f7

View file

@ -368,6 +368,9 @@ AlertModelImpl::AlertModelImpl() :
std::string AlertModelImpl::GetCounties(const types::TextEventKey& key)
{
auto messageList = manager::TextEventManager::Instance()->message_list(key);
if (messageList.size() > 0)
{
auto& lastMessage = messageList.back();
size_t segmentCount = lastMessage->segment_count();
auto lastSegment = lastMessage->segment(segmentCount - 1);
@ -383,24 +386,51 @@ std::string AlertModelImpl::GetCounties(const types::TextEventKey& key)
return scwx::util::ToString(counties);
}
else
{
logger_->warn("GetCounties(): No message associated with key: {}",
key.ToString());
return {};
}
}
std::string AlertModelImpl::GetState(const types::TextEventKey& key)
{
auto messageList = manager::TextEventManager::Instance()->message_list(key);
if (messageList.size() > 0)
{
auto& lastMessage = messageList.back();
size_t segmentCount = lastMessage->segment_count();
auto lastSegment = lastMessage->segment(segmentCount - 1);
return scwx::util::ToString(lastSegment->header_->ugc_.states());
}
else
{
logger_->warn("GetState(): No message associated with key: {}",
key.ToString());
return {};
}
}
std::chrono::system_clock::time_point
AlertModelImpl::GetStartTime(const types::TextEventKey& key)
{
auto messageList = manager::TextEventManager::Instance()->message_list(key);
if (messageList.size() > 0)
{
auto& firstMessage = messageList.front();
auto firstSegment = firstMessage->segment(0);
return firstSegment->header_->vtecString_[0].pVtec_.event_begin();
}
else
{
logger_->warn("GetStartTime(): No message associated with key: {}",
key.ToString());
return {};
}
}
std::string AlertModelImpl::GetStartTimeString(const types::TextEventKey& key)
{
@ -411,11 +441,21 @@ std::chrono::system_clock::time_point
AlertModelImpl::GetEndTime(const types::TextEventKey& key)
{
auto messageList = manager::TextEventManager::Instance()->message_list(key);
if (messageList.size() > 0)
{
auto& lastMessage = messageList.back();
size_t segmentCount = lastMessage->segment_count();
auto lastSegment = lastMessage->segment(segmentCount - 1);
return lastSegment->header_->vtecString_[0].pVtec_.event_end();
}
else
{
logger_->warn("GetEndTime(): No message associated with key: {}",
key.ToString());
return {};
}
}
std::string AlertModelImpl::GetEndTimeString(const types::TextEventKey& key)
{