QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
logring.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2026 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef LOGRING_H
19#define LOGRING_H
20
21#include <QByteArray>
22#include <QVector>
23#include <atomic>
24#include <vector>
25
51{
52 public:
53 static constexpr int kCapacityEntries = 4096;
54 static constexpr int kEntryBytes = 512; // 4096 * 512 = 2 MiB total
55
56 LogRing();
57
62 void append(const QByteArray &line) noexcept;
63
66 QVector<QByteArray> snapshot() const;
67
71 void dumpToFd(int fd) const noexcept;
72
73 void clear();
74
75 private:
76 struct Entry {
78 std::atomic<int> length{0}; // 0 = not yet written this lap
79 };
80
81 std::vector<Entry> m_entries; // preallocated once, capacity fixed
82 std::atomic<quint64> m_write_cursor{0}; // monotonically increasing
83};
84
85#endif // LOGRING_H
std::vector< Entry > m_entries
Definition logring.h:81
QVector< QByteArray > snapshot() const
Definition logring.cpp:109
void dumpToFd(int fd) const noexcept
Definition logring.cpp:130
LogRing()
Definition logring.cpp:73
std::atomic< quint64 > m_write_cursor
Definition logring.h:82
static constexpr int kCapacityEntries
Definition logring.h:53
void append(const QByteArray &line) noexcept
Definition logring.cpp:82
void clear()
Definition logring.cpp:146
static constexpr int kEntryBytes
Definition logring.h:54
Definition logring.h:76
char data[kEntryBytes]
Definition logring.h:77
std::atomic< int > length
Definition logring.h:78