QtPdCom  1.5.2
MessageManager.h
Go to the documentation of this file.
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
36namespace PdCom {
37 class Process;
38}
39
40namespace QtPdCom {
41
42using MessageFuture = QFuture<PdCom::Message>;
43using MessageFutureInterface = QFutureInterface<PdCom::Message>;
44using MessageListFuture = QFuture<std::vector<PdCom::Message>>;
45using MessageListFutureInterface = QFutureInterface<std::vector<PdCom::Message>>;
46
47
48class MessageWatcher : public QFutureWatcher<PdCom::Message>
49{
50 Q_OBJECT
51
52 public:
53
54 using QFutureWatcher<PdCom::Message>::QFutureWatcher;
55};
56
57class 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
67 public QObject,
68 public PdCom::MessageManagerBase
69{
70 Q_OBJECT
71
72 public:
74 virtual ~MessageManager();
75
76 void reset();
77
79 MessageFuture getMessageQt(uint32_t seqNo);
80
81 template <class Object, typename Callback>
82 void activeMessages(Object *obj, Callback &&callback)
83 {
85 .setFuture(activeMessagesQt());
86 }
87
88 template <class Object, typename Callback>
89 void getMessage(uint32_t seqNo, Object *obj, Callback &&callback)
90 {
92 .setFuture(getMessageQt(seqNo));
93 }
94
95
96 signals:
97 void processMessageSignal(PdCom::Message message);
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/****************************************************************************/
MessageManager()
Definition MessageManager.cpp:30
Definition MessageManager.h:58
MessageListFuture activeMessagesQt()
Definition MessageManager.cpp:86
virtual ~MessageManager()
Definition MessageManager.cpp:36
QQueue< MessageFutureInterface > getMessageQueue
Definition MessageManager.h:105
void activeMessages(Object *obj, Callback &&callback)
Definition MessageManager.h:82
void processMessage(PdCom::Message message) override
Definition MessageManager.cpp:54
void activeMessagesReply(std::vector< PdCom::Message > messageList) override
Definition MessageManager.cpp:97
QQueue< MessageListFutureInterface > activeMessageQueue
Definition MessageManager.h:106
void getMessageReply(PdCom::Message message) override
Definition MessageManager.cpp:72
void getMessage(uint32_t seqNo, Object *obj, Callback &&callback)
Definition MessageManager.h:89
void reset()
Definition MessageManager.cpp:43
void processMessageSignal(PdCom::Message message)
MessageManager()
Definition MessageManager.cpp:30
MessageFuture getMessageQt(uint32_t seqNo)
Definition MessageManager.cpp:61
Definition MessageManager.h:49
Definition MessageManager.h:36
Definition BroadcastModel.h:32
QFutureWatcher< Result > & createWatcher(Object *obj, Callback &&callback)
Definition FutureWatchers.h:100
QFutureInterface< std::vector< PdCom::Message > > MessageListFutureInterface
Definition MessageManager.h:45
QFuture< std::vector< PdCom::Message > > MessageListFuture
Definition MessageManager.h:44
QFuture< PdCom::Message > MessageFuture
Definition MessageManager.h:42
QFutureInterface< PdCom::Message > MessageFutureInterface
Definition MessageManager.h:43