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