GCC Code Coverage Report


Directory: ./
File: src/MessageModelImpl.cpp
Date: 2024-01-26 10:40:55
Exec Total Coverage
Lines: 216 239 90.4%
Branches: 304 610 49.8%

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