LogStore.h
Go to the documentation of this file.
1
/*
2
* This file is part of ArmarX.
3
*
4
* ArmarX is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation.
7
*
8
* ArmarX is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*
16
* @package ArmarX::
17
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
18
* GNU General Public License
19
*/
20
21
#pragma once
22
23
#include <cstddef>
24
#include <deque>
25
26
#include <QString>
27
#include <QtGlobal>
28
29
#include <ArmarXCore/interface/core/Log.h>
30
31
namespace
armarx
32
{
33
//! Identifies a stored log entry for as long as it is retained. Monotonically
34
//! increasing and never reused, so it stays a valid reference even though the store
35
//! drops old entries from the front (which shifts every index, but no sequence
36
//! number).
37
using
LogSeq
= quint64;
38
39
//! A retained log line: the message plus the display data derived from it. The
40
//! derived fields are built once, here, instead of once per filter that accepts the
41
//! message and again on every repaint.
42
struct
StoredLogEntry
43
{
44
LogMessage
message
;
45
QString
timeString
;
//!< formatted time column (0)
46
QString
displayMessage
;
//!< truncated message column (4)
47
int
lineCount
= 1;
//!< number of display lines in displayMessage
48
};
49
50
/*!
51
* \brief The single bounded buffer holding every log line the viewer retains.
52
*
53
* Filters do not own their messages: each LogTableModel keeps a vector of LogSeq into
54
* this store. A message accepted by "All Messages", by its logging group filter and by
55
* its component filter is therefore stored -- and has its display data derived --
56
* once instead of three times.
57
*
58
* GUI thread only, like the rest of the viewer's model state. LogViewer::writeLog runs
59
* on an Ice dispatch thread but only appends to its own staging queue; everything
60
* reaching the store goes through insertPendingEntries on the GUI thread.
61
*/
62
class
LogStore
63
{
64
public
:
65
explicit
LogStore
(std::size_t maxEntries);
66
67
//! Append \p message, deriving its display data, and return its sequence number.
68
LogSeq
append
(
const
LogMessage& message);
69
70
//! Drop the oldest entries until the bound is met. Returns true if anything was
71
//! dropped, in which case firstSeq() has advanced and every model has to discard
72
//! the rows below it (see LogTableModel::dropRowsBefore).
73
bool
trim
();
74
75
//! Sequence number of the oldest retained entry.
76
LogSeq
firstSeq
()
const
;
77
//! One past the sequence number of the newest retained entry.
78
LogSeq
endSeq
()
const
;
79
bool
contains
(
LogSeq
seq)
const
;
80
//! Only valid if contains(seq).
81
const
StoredLogEntry
&
at
(
LogSeq
seq)
const
;
82
83
std::size_t
size
()
const
;
84
85
//! Drop everything. Sequence numbers keep counting up, so references to the
86
//! discarded entries stay invalid rather than aliasing new ones.
87
void
clear
();
88
89
private
:
90
std::deque<StoredLogEntry> entries;
91
LogSeq
first = 0;
92
std::size_t maxEntries;
93
};
94
}
// namespace armarx
armarx::LogStore::append
LogSeq append(const LogMessage &message)
Append message, deriving its display data, and return its sequence number.
Definition
LogStore.cpp:84
armarx::LogStore::firstSeq
LogSeq firstSeq() const
Sequence number of the oldest retained entry.
Definition
LogStore.cpp:111
armarx::LogStore::trim
bool trim()
Drop the oldest entries until the bound is met.
Definition
LogStore.cpp:97
armarx::LogStore::endSeq
LogSeq endSeq() const
One past the sequence number of the newest retained entry.
Definition
LogStore.cpp:117
armarx::LogStore::at
const StoredLogEntry & at(LogSeq seq) const
Only valid if contains(seq).
Definition
LogStore.cpp:129
armarx::LogStore::contains
bool contains(LogSeq seq) const
Definition
LogStore.cpp:123
armarx::LogStore::clear
void clear()
Drop everything.
Definition
LogStore.cpp:141
armarx::LogStore::LogStore
LogStore(std::size_t maxEntries)
Definition
LogStore.cpp:79
armarx::LogStore::size
std::size_t size() const
Definition
LogStore.cpp:135
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition
ArmarXTimeserver.cpp:28
armarx::LogSeq
quint64 LogSeq
Identifies a stored log entry for as long as it is retained.
Definition
LogStore.h:37
armarx::StoredLogEntry
A retained log line: the message plus the display data derived from it.
Definition
LogStore.h:43
armarx::StoredLogEntry::message
LogMessage message
Definition
LogStore.h:44
armarx::StoredLogEntry::displayMessage
QString displayMessage
truncated message column (4)
Definition
LogStore.h:46
armarx::StoredLogEntry::lineCount
int lineCount
number of display lines in displayMessage
Definition
LogStore.h:47
armarx::StoredLogEntry::timeString
QString timeString
formatted time column (0)
Definition
LogStore.h:45
ArmarXGui
gui-plugins
LoggingPlugin
ArmarXLogViewer
LogStore.h
Generated by
1.13.2