GCC Code Coverage Report


Directory: ./
File: src/MessageManager.h
Date: 2024-01-26 10:40:55
Exec Total Coverage
Lines: 6 8 75.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 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 #ifndef QTPDCOM_MESSAGE_MANAGER_H
23 #define QTPDCOM_MESSAGE_MANAGER_H
24
25 #include <pdcom5/MessageManagerBase.h>
26 #include "FutureWatchers.h"
27
28 #include <QObject>
29 #include <QFuture>
30 #include <QFutureInterface>
31 #include <QFutureWatcher>
32 #include <QQueue>
33
34 /****************************************************************************/
35
36 namespace PdCom {
37 class Process;
38 }
39
40 namespace QtPdCom {
41
42 using MessageFuture = QFuture<PdCom::Message>;
43 using MessageFutureInterface = QFutureInterface<PdCom::Message>;
44 using MessageListFuture = QFuture<std::vector<PdCom::Message>>;
45 using MessageListFutureInterface = QFutureInterface<std::vector<PdCom::Message>>;
46
47
48 class MessageWatcher : public QFutureWatcher<PdCom::Message>
49 {
50 Q_OBJECT
51
52 public:
53
54 using QFutureWatcher<PdCom::Message>::QFutureWatcher;
55 };
56
57 class MessageListWatcher : public QFutureWatcher<std::vector<PdCom::Message>>
58 {
59 Q_OBJECT
60
61 public:
62
63 using QFutureWatcher<std::vector<PdCom::Message>>::QFutureWatcher;
64 };
65
66 class MessageManager:
67 public QObject,
68 public PdCom::MessageManagerBase
69 {
70 Q_OBJECT
71
72 public:
73 MessageManager();
74 virtual ~MessageManager();
75
76 void reset();
77
78 MessageListFuture activeMessagesQt();
79 MessageFuture getMessageQt(uint32_t seqNo);
80
81 template <class Object, typename Callback>
82 5 void activeMessages(Object *obj, Callback &&callback)
83 {
84
1/2
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 createWatcher<std::vector<PdCom::Message>>(obj, callback)
85 .setFuture(activeMessagesQt());
86 5 }
87
88 template <class Object, typename Callback>
89 13 void getMessage(uint32_t seqNo, Object *obj, Callback &&callback)
90 {
91
1/2
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
13 createWatcher<PdCom::Message>(obj, callback)
92 .setFuture(getMessageQt(seqNo));
93 13 }
94
95
96 signals:
97 void processMessageSignal(PdCom::Message message);
98 void processResetSignal();
99
100 private:
101 void processMessage(PdCom::Message message) override;
102 void getMessageReply(PdCom::Message message) override;
103 void activeMessagesReply(std::vector<PdCom::Message> messageList) override;
104
105 QQueue<MessageFutureInterface> getMessageQueue;
106 QQueue<MessageListFutureInterface> activeMessageQueue;
107 };
108
109 }
110
111 #endif
112
113 /****************************************************************************/
114