GCC Code Coverage Report


Directory: ./
File: src/MessageModelImpl.cpp
Date: 2026-11-03 09:25:15
Exec Total Coverage
Lines: 229 249 92.0%
Branches: 331 632 52.4%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2009 - 2022 Florian Pose <fp@igh.de>
4 *
5 * This file is part of the QtPdCom library.
6 *
7 * The QtPdCom library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * The QtPdCom library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21
22 #include "MessageModelImpl.h"
23
24 #include "MessageImpl.h"
25 #include "MessageItem.h"
26
27 #include <QDateTime>
28 #include <QFutureWatcher>
29 #include <QtPdCom1/Process.h>
30
31 using QtPdCom::MessageModel;
32
33 /****************************************************************************/
34
35 /** Constructor.
36 */
37 17 MessageModel::Impl::Impl(MessageModel *model):
38 parent {model},
39 announcedMessageItem {nullptr},
40 messageManager {nullptr},
41 rowLimit {1000},
42 canFetchMore {false},
43 historicSeqNo {0},
44 17 lessThan {MessageItem::levelNoLessThan}
45 17 {}
46
47 /****************************************************************************/
48
49 /** Destructor.
50 */
51 34 MessageModel::Impl::~Impl()
52 34 {}
53
54 /****************************************************************************/
55
56 /** Insert a message item.
57 */
58 29 void MessageModel::Impl::insertItem(MessageItem *msgItem)
59 {
60 29 int row = messageItemList.indexOf(msgItem);
61
62
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 27 times.
29 if (row >= 0) {
63
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 parent->beginRemoveRows(QModelIndex(), row, row);
64 2 messageItemList.removeAt(row);
65 2 parent->endRemoveRows();
66 }
67
68 83 row = (messageItemList.empty()
69
4/6
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 7 times.
11 or MessageItem::lessThan(msgItem, messageItemList.first()))
70
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 18 times.
70 ? 0
71
3/6
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 25 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
41 : (std::lower_bound(
72
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 25 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
33 messageItemList.begin(),
73
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 25 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
33 messageItemList.end(),
74 msgItem,
75 lessThan)
76
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
✓ Branch 4 taken 4 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
37 - messageItemList.begin());
77
78
1/2
✓ Branch 3 taken 29 times.
✗ Branch 4 not taken.
29 parent->beginInsertRows(QModelIndex(), row, row);
79 29 messageItemList.insert(row, msgItem);
80 29 parent->endInsertRows();
81
82 // Is this a candidate for the current/announced message?
83 //
84 // Announce this message as current message, if
85 // - there is either no message announced yet,
86 // - the message type is more important than the type of the announced one
87 // - the sequence number is earlier
88
2/2
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 10 times.
58 if (msgItem->isActive()
89
4/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 17 times.
48 and (!announcedMessageItem
90
2/2
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
6 or msgItem->getType() > announcedMessageItem->getType()
91
2/2
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
4 or (msgItem->getType() == announcedMessageItem->getType()
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 and seqNoLessThan(
93 msgItem->seqNo,
94 3 announcedMessageItem->seqNo)))) {
95 19 announcedMessageItem = msgItem;
96 #if PD_DEBUG_MESSAGE_MODEL
97
4/8
✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 19 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 19 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 19 times.
✗ Branch 13 not taken.
38 qDebug() << __func__ << "currentMessage" << msgItem
98
1/2
✓ Branch 5 taken 19 times.
✗ Branch 6 not taken.
38 << msgItem->message;
99 #endif
100 19 emit parent->currentMessage(announcedMessageItem->message);
101 }
102
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
10 else if (msgItem->resetTime and msgItem == announcedMessageItem) {
103 // search for a new message to announce
104 ✗ announce();
105 }
106 29 }
107
108 /****************************************************************************/
109
110 /** Called from the PdCom interface, if a new message appears via
111 * processMessage() or in context of activeMessagesReply().
112 */
113 26 void MessageModel::Impl::addProcessMessage(const PdCom::Message &pdComMsg)
114 {
115
1/2
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
52 QString path {QString::fromStdString(pdComMsg.path)};
116 #if PD_DEBUG_MESSAGE_MODEL
117
4/8
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
26 qDebug() << __func__ << "seqno" << pdComMsg.seqNo;
118 #endif
119
120
2/4
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
26 Message *&msg = messageMap[path][pdComMsg.index];
121
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 11 times.
26 if (!msg) {
122 #if PD_DEBUG_MESSAGE_MODEL
123
3/6
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 15 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 15 times.
✗ Branch 11 not taken.
15 qDebug() << __func__ << "not in map. creating new message.";
124 #endif
125
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
15 msg = new Message();
126
1/2
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
15 msg->impl->fromPdComMessage(pdComMsg);
127 }
128 else {
129 // the server text may have changed, e. g. after a server restart
130
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 6 times.
11 if (not pdComMsg.text.empty()) {
131
1/2
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
5 msg->impl->serverText = pdComMsg.text.c_str();
132 }
133 }
134
135 26 auto msgItem {msg->impl->currentItem};
136 #if PD_DEBUG_MESSAGE_MODEL
137
4/8
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
26 qDebug() << __func__ << "msgItem" << msgItem;
138
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 17 times.
26 if (msgItem) {
139
4/8
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 9 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 9 times.
✗ Branch 14 not taken.
9 qDebug() << __func__ << "currentItem seqNo" << msgItem->seqNo;
140 }
141 #endif
142
143
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
26 if (pdComMsg.level != PdCom::LogLevel::Reset) { // set
144
145
2/2
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 2 times.
18 if (not msg->impl->announced) {
146
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 emit parent->anyMessage(msg);
147 16 msg->impl->announced = true;
148 }
149
150
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if (msgItem) {
151 // already has current item
152
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!msgItem->seqNo) {
153 // Current item has zero seqNo -> from mixed mode.
154 // Just attach the seqNo.
155 2 msgItem->seqNo = pdComMsg.seqNo;
156 }
157 ✗ else if (msgItem->seqNo != pdComMsg.seqNo) {
158 // Current item has different seqNo.
159 // Not ours, thus create a new one.
160 ✗ msgItem = new MessageItem(msg, this, pdComMsg.time.count());
161 ✗ msgItem->seqNo = pdComMsg.seqNo;
162 }
163 }
164 else { // no current item
165
2/4
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 16 times.
✗ Branch 6 not taken.
16 msgItem = new MessageItem(msg, this, pdComMsg.time.count());
166 16 msgItem->seqNo = pdComMsg.seqNo;
167 16 msg->impl->currentItem = msgItem;
168 }
169
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 insertItem(msgItem);
170 }
171 else { // reset
172 #if PD_DEBUG_MESSAGE_MODEL
173
4/8
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 8 times.
✗ Branch 14 not taken.
8 qDebug() << __func__ << "reset msgItem" << msgItem;
174 #endif
175 8 msg->impl->announced = false;
176
177
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (msgItem) {
178 7 msgItem->resetTime = pdComMsg.time.count();
179
180 // notify views
181
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 int row = messageItemList.indexOf(msgItem);
182 #if PD_DEBUG_MESSAGE_MODEL
183
4/8
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 7 times.
✗ Branch 14 not taken.
7 qDebug() << __func__ << "reset row" << row;
184 #endif
185
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (row >= 0) {
186
1/2
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
7 QModelIndex idx0 = parent->index(row, 0);
187
1/2
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
7 QModelIndex idx1 = parent->index(row, 2);
188
1/2
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
7 emit parent->dataChanged(idx0, idx1);
189 }
190 7 msg->impl->currentItem = nullptr;
191
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (msgItem == announcedMessageItem) {
192
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 announce();
193 }
194 }
195 }
196 26 }
197
198 /****************************************************************************/
199
200 /** Called from the PdCom interface, if a historic message appears via
201 * getMessageReply().
202 */
203 6 void MessageModel::Impl::addHistoricMessage(
204 const PdCom::Message &pdComMsg,
205 const PdCom::Message &resetMsg)
206 {
207
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 QString path {QString::fromStdString(pdComMsg.path)};
208 #if PD_DEBUG_MESSAGE_MODEL
209
4/8
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 6 times.
✗ Branch 14 not taken.
6 qDebug() << __func__ << pdComMsg.seqNo << resetMsg.seqNo;
210 #endif
211
212
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 Message *&msg = messageMap[path][pdComMsg.index];
213
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if (!msg) {
214
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 msg = new Message();
215
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 msg->impl->fromPdComMessage(pdComMsg);
216 }
217 else {
218
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (not pdComMsg.text.empty()) {
219
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 msg->impl->serverText = pdComMsg.text.c_str();
220 }
221 }
222
223
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 auto msgItem = new MessageItem(msg, this, pdComMsg.time.count());
224 6 msgItem->seqNo = pdComMsg.seqNo;
225 6 msgItem->resetTime = resetMsg.time.count();
226
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 insertItem(msgItem);
227 6 }
228
229 /****************************************************************************/
230
231 /** Returns a wrapped version of a string.
232 */
233 36 QString MessageModel::Impl::wrapText(const QString &text, unsigned int width)
234 {
235 36 QString ret;
236 int lineOffset, i;
237
238 36 lineOffset = 0;
239
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
36 while (lineOffset + (int) width < text.length()) {
240 // search last space before line end
241 ✗ for (i = width; i >= 0; i--) {
242 ✗ if (text[lineOffset + i].isSpace()) {
243 ✗ break; // break at whitespace
244 }
245 }
246 ✗ if (i < 0) { // no whitespace found
247 ✗ i = width; // "hard" break at line end
248 }
249
250 ✗ ret += text.mid(lineOffset, i) + QChar(QChar::LineSeparator);
251 ✗ lineOffset += i + 1; // skip line and whitespace
252 }
253
254
2/4
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 36 times.
✗ Branch 6 not taken.
36 ret += text.mid(lineOffset); // append remaining string
255 36 return ret;
256 }
257
258 /****************************************************************************/
259
260 13 void MessageModel::Impl::getHistoryMessage()
261 {
262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (!messageManager) {
263 ✗ qWarning() << __func__ << "no message manager";
264 ✗ return;
265 }
266
267 #if PD_DEBUG_MESSAGE_MODEL
268
3/6
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 13 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 13 times.
✗ Branch 11 not taken.
13 qDebug() << __func__ << "setting canFetchMore to false";
269 #endif
270 13 canFetchMore = false; // avoid fetchMore called twice for same seqNo
271
272 13 uint32_t prevSeqNo = historicSeqNo - 1;
273 #if PD_DEBUG_MESSAGE_MODEL
274
4/8
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 13 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 13 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 13 times.
✗ Branch 14 not taken.
13 qDebug() << __func__ << "fetching" << prevSeqNo;
275 #endif
276
277 try {
278
1/4
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
13 messageManager->getMessage(prevSeqNo, this, &Impl::getMessageReply);
279 }
280 ✗ catch (PdCom::Exception &e) {
281 ✗ qDebug() << __func__ << e.what();
282 }
283 }
284
285 /****************************************************************************/
286
287 9 void MessageModel::Impl::announce()
288 {
289
3/4
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 7 times.
11 MessageItemList sortedList(messageItemList);
290
1/2
✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
27 std::sort(
291
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
18 sortedList.begin(),
292
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
18 sortedList.end(),
293 MessageItem::levelNoLessThan);
294
295 // if there is no active message, announce a nullptr
296
4/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 2 times.
9 if (not sortedList.front()->isActive()) {
297
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (announcedMessageItem) {
298 7 announcedMessageItem = nullptr;
299 #if PD_DEBUG_MESSAGE_MODEL
300
3/6
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
7 qDebug() << __func__ << "currentMessage null";
301 #endif
302
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 emit parent->currentMessage(nullptr);
303 }
304 7 return;
305 }
306
307 // the first active message in the sorted list determines the type
308
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 auto type = sortedList.front()->getType();
309
310 // find the earliest message with this type
311 2 MessageItem *candidate {nullptr};
312
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
4 for (MessageItemList::const_iterator it = sortedList.begin();
313
7/16
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 4 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
20 (it != sortedList.end() and (*it)->isActive()
314
6/10
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 2 times.
18 and (*it)->getType() == type);
315 ++it) {
316
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 candidate = *it;
317 }
318
319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (announcedMessageItem == candidate) {
320 // still the same message, no new announcement needed
321 ✗ return;
322 }
323 2 announcedMessageItem = candidate;
324
325 2 const QtPdCom::Message *msg {nullptr};
326
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (announcedMessageItem) {
327 2 msg = announcedMessageItem->message;
328 }
329 #if PD_DEBUG_MESSAGE_MODEL
330
5/10
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
2 qDebug() << __func__ << "currentMessage" << announcedMessageItem << msg;
331 #endif
332
3/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 7 times.
2 emit parent->currentMessage(msg);
333 }
334
335 /*****************************************************************************
336 * private slots
337 ****************************************************************************/
338
339 /** Reacts on process values changes of all messages to watch.
340 */
341 8 void MessageModel::Impl::stateChanged()
342 {
343
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 Message *msg = (Message *) sender();
344 8 DoubleVariable &var = msg->impl->variable;
345
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 double time {var.hasData() ? var.getValue() : 0.0};
346
347 #if PD_DEBUG_MESSAGE_MODEL
348
7/14
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 8 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 8 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 8 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 8 times.
✗ Branch 23 not taken.
8 qDebug() << __func__ << msg->getPath() << msg->getIndex() << time;
349 #endif
350
351
5/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 3 times.
8 if (time and not msg->impl->announced) {
352
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 emit parent->anyMessage(msg);
353 5 msg->impl->announced = true;
354 }
355
356 8 MessageItem *msgItem {nullptr};
357
358
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
8 if (time) { // set
359 5 MessageItem *msgItem {msg->impl->currentItem};
360
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (!msgItem) {
361
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 msgItem = new MessageItem(msg, this, time * 1e9);
362 #if PD_DEBUG_MESSAGE_MODEL
363
4/8
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
5 qDebug() << __func__ << "new msgItem" << msgItem;
364 #endif
365 5 msg->impl->currentItem = msgItem;
366
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 insertItem(msgItem);
367 }
368 }
369 else { // reset
370 3 msg->impl->announced = false;
371 3 msgItem = msg->impl->currentItem;
372
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (msgItem) {
373
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 auto now {QDateTime::currentDateTime()};
374
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 msgItem->resetTime = now.toMSecsSinceEpoch() * 1000000U;
375
376 // notify views
377
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 int row = messageItemList.indexOf(msgItem);
378 #if PD_DEBUG_MESSAGE_MODEL
379
4/8
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 14 not taken.
3 qDebug() << __func__ << "reset row" << row;
380 #endif
381
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (row >= 0) {
382
1/2
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 QModelIndex idx0 = parent->index(row, 0);
383
1/2
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 QModelIndex idx1 = parent->index(row, 2);
384
1/2
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 emit parent->dataChanged(idx0, idx1);
385 }
386
387 3 msg->impl->currentItem = nullptr;
388
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (msgItem == announcedMessageItem) {
389
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 announce();
390 }
391 }
392 }
393 8 }
394
395 /****************************************************************************/
396
397 25 void MessageModel::Impl::processMessage(PdCom::Message message)
398 {
399 #if PD_DEBUG_MESSAGE_MODEL
400
1/2
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 auto path = QString::fromStdString(message.path);
401
1/2
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 auto text = QString::fromStdString(message.text);
402
2/4
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 25 times.
✗ Branch 8 not taken.
25 qDebug() << __func__;
403
5/10
✓ Branch 3 taken 25 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 25 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 25 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 25 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 25 times.
✗ Branch 16 not taken.
50 qDebug() << "seqNo" << message.seqNo << "level" << (int) message.level
404
5/10
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 25 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 25 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 25 times.
✗ Branch 15 not taken.
25 << "path" << path << "time" << message.time.count() << "index"
405
3/6
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 25 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 25 times.
✗ Branch 9 not taken.
50 << message.index << "text" << text;
406 #endif
407
408
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
25 addProcessMessage(message);
409 25 }
410
411 /****************************************************************************/
412
413 11 void MessageModel::Impl::getMessageReply(PdCom::Message message)
414 {
415
3/4
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 2 times.
20 auto path = QString::fromStdString(message.path);
416
417 #if PD_DEBUG_MESSAGE_MODEL
418
3/4
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 2 times.
20 auto text = QString::fromStdString(message.text);
419
2/4
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
11 qDebug() << __func__;
420
5/10
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 11 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 11 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 11 times.
✗ Branch 16 not taken.
22 qDebug() << "seqNo" << message.seqNo << "level" << (int) message.level
421
5/10
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 11 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 11 times.
✗ Branch 15 not taken.
11 << "path" << path << "time" << message.time.count() << "index"
422
3/6
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 11 times.
✗ Branch 9 not taken.
22 << message.index << "text" << text;
423 #endif
424
425
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9 times.
11 if (path.isEmpty()) {
426 // EOF marker - no more messages from process
427 2 return;
428 }
429
430 9 historicSeqNo = message.seqNo;
431
432 9 canFetchMore = message.level != PdCom::LogLevel::Reset;
433 #if PD_DEBUG_MESSAGE_MODEL
434
4/8
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 9 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 9 times.
✗ Branch 14 not taken.
9 qDebug() << __func__ << "setting canFetchMore to" << canFetchMore;
435 #endif
436
437 9 bool stillActive {false};
438
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 if (canFetchMore) {
439 // found a message that was set in the past. try to find the reset.
440 #if PD_DEBUG_MESSAGE_MODEL
441 6 bool found {false};
442
3/6
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
12 qDebug() << __func__ << "reset msg list size is"
443
1/2
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
12 << resetMessagesList.size();
444 #endif
445
3/6
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
6 for (auto r = resetMessagesList.begin(); r != resetMessagesList.end();
446 r++) {
447
5/10
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
6 if (r->path == message.path and r->index == message.index) {
448
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 addHistoricMessage(message, *r);
449
1/2
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 resetMessagesList.erase(r);
450 #if PD_DEBUG_MESSAGE_MODEL
451 6 found = true;
452 #endif
453 6 break;
454 }
455 }
456 #if PD_DEBUG_MESSAGE_MODEL
457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!found) {
458 ✗ qDebug() << __func__ << "reset message not found for"
459 ✗ << message.seqNo;
460 // found a message that seems to be still active. Go on with
461 // reading, otherwise views won't ask for more data
462 ✗ stillActive = true;
463 }
464 #endif
465 }
466 else {
467
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 resetMessagesList.append(message);
468 }
469
470
4/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
9 if ((!canFetchMore or stillActive) and historicSeqNo) {
471
3/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 2 times.
5 getHistoryMessage();
472 }
473 }
474
475 /****************************************************************************/
476
477 4 void MessageModel::Impl::activeMessagesReply(
478 std::vector<PdCom::Message> messageList)
479 {
480 4 quint32 maxSeqNo {0};
481
482 #if PD_DEBUG_MESSAGE_MODEL
483
5/10
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 4 times.
✗ Branch 19 not taken.
4 qDebug().nospace() << __func__ << "(" << messageList.size() << ")";
484 #endif
485
3/4
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
8 for (auto message : messageList) {
486 #if PD_DEBUG_MESSAGE_MODEL
487
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 auto path = QString::fromStdString(message.path);
488
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 auto text = QString::fromStdString(message.text);
489
5/10
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
8 qDebug() << "seqNo" << message.seqNo << "level" << (int) message.level
490
4/8
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
4 << "path" << path << "time" << message.time.count()
491
4/8
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
8 << "index" << message.index << "text" << text;
492 #endif
493
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (message.level != PdCom::LogLevel::Reset) {
494
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 addProcessMessage(message);
495 }
496 else {
497 // one entry in the list of active messages can be a reset
498 // message, to announce the current sequence number
499
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 resetMessagesList.append(message);
500 }
501
502
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (message.seqNo > maxSeqNo) {
503 4 maxSeqNo = message.seqNo;
504 }
505 }
506
507
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (maxSeqNo > 0) {
508 // now fetch one historic message
509 4 historicSeqNo = maxSeqNo;
510 4 getHistoryMessage();
511 }
512 4 }
513
514 /****************************************************************************/
515
516 36 void MessageModel::Impl::processReset()
517 {
518 #if PD_DEBUG_MESSAGE_MODEL
519
2/4
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 36 times.
✗ Branch 8 not taken.
36 qDebug() << __func__;
520 #endif
521
522 36 canFetchMore = false;
523 36 historicSeqNo = 0;
524 36 resetMessagesList.clear();
525
526 36 parent->beginResetModel();
527 36 qDeleteAll(messageItemList);
528 36 messageItemList.clear();
529 36 parent->endResetModel();
530
531 // reset current item pointers
532
6/10
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 36 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 13 times.
✓ Branch 10 taken 36 times.
✓ Branch 14 taken 13 times.
✗ Branch 15 not taken.
✓ Branch 18 taken 13 times.
✗ Branch 19 not taken.
49 for (auto hash : messageMap) {
533
6/10
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 13 times.
✓ Branch 10 taken 13 times.
✓ Branch 12 taken 13 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 13 times.
✗ Branch 16 not taken.
26 for (auto msg : hash) {
534
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 12 times.
13 if (msg->impl->currentItem) {
535 1 msg->impl->currentItem = nullptr;
536 }
537 }
538 }
539
540
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 if (announcedMessageItem) {
541 1 announcedMessageItem = nullptr;
542 #if PD_DEBUG_MESSAGE_MODEL
543
3/6
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
1 qDebug() << __func__ << "currentMessage null";
544 #endif
545 1 emit parent->currentMessage(nullptr);
546 }
547 36 }
548
549 /****************************************************************************/
550
551 5 void MessageModel::Impl::reloadActiveMessages()
552 {
553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!messageManager) {
554 ✗ return;
555 }
556
557
1/2
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 messageManager->activeMessages(this, &Impl::activeMessagesReply);
558 }
559
560 /****************************************************************************/
561