mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-24 05:47:58 -05:00
Add RandomStringGenerator class. Implement Circular and Logger buffers. Add UTs for LoggerBuffer.
38 lines
954 B
C++
38 lines
954 B
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "LoggerBuffer.hpp"
|
|
|
|
std::pair<bool, std::string> LoggerBuffer::get()
|
|
{
|
|
auto [result, logMsg] = StringCircularBuffer::get();
|
|
if (!result) {
|
|
return {result, logMsg};
|
|
}
|
|
if (numOfLostBytes > 0) {
|
|
logMsg += "\r\n" + std::to_string(numOfLostBytes) + " " + lostBytesMessage;
|
|
numOfLostBytes = 0;
|
|
}
|
|
return {true, logMsg};
|
|
}
|
|
|
|
void LoggerBuffer::put(const std::string &logMsg)
|
|
{
|
|
updateNumOfLostBytes();
|
|
StringCircularBuffer::put(logMsg);
|
|
}
|
|
|
|
void LoggerBuffer::put(std::string &&logMsg)
|
|
{
|
|
updateNumOfLostBytes();
|
|
StringCircularBuffer::put(std::move(logMsg));
|
|
}
|
|
|
|
void LoggerBuffer::updateNumOfLostBytes()
|
|
{
|
|
if (StringCircularBuffer::isFull()) {
|
|
auto [_, lostMsg] = StringCircularBuffer::get();
|
|
numOfLostBytes += lostMsg.length();
|
|
}
|
|
}
|