QtPdCom  1.3.3
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 
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 
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  {
84  createWatcher<std::vector<PdCom::Message>>(obj, callback)
85  .setFuture(activeMessagesQt());
86  }
87 
88  template <class Object, typename Callback>
89  void getMessage(uint32_t seqNo, Object *obj, Callback &&callback)
90  {
91  createWatcher<PdCom::Message>(obj, callback)
92  .setFuture(getMessageQt(seqNo));
93  }
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 /****************************************************************************/
Definition: MessageManager.h:48
QFutureInterface< PdCom::Message > MessageFutureInterface
Definition: MessageManager.h:43
QFuture< std::vector< PdCom::Message > > MessageListFuture
Definition: MessageManager.h:44
void getMessageReply(PdCom::Message message) override
Definition: MessageManager.cpp:72
Definition: BroadcastModel.h:32
QFuture< PdCom::Message > MessageFuture
Definition: MessageManager.h:42
QFutureInterface< std::vector< PdCom::Message > > MessageListFutureInterface
Definition: MessageManager.h:45
MessageListFuture activeMessagesQt()
Definition: MessageManager.cpp:86
void activeMessagesReply(std::vector< PdCom::Message > messageList) override
Definition: MessageManager.cpp:97
void activeMessages(Object *obj, Callback &&callback)
Definition: MessageManager.h:82
MessageFuture getMessageQt(uint32_t seqNo)
Definition: MessageManager.cpp:61
void getMessage(uint32_t seqNo, Object *obj, Callback &&callback)
Definition: MessageManager.h:89
QQueue< MessageFutureInterface > getMessageQueue
Definition: MessageManager.h:105
QQueue< MessageListFutureInterface > activeMessageQueue
Definition: MessageManager.h:106
Definition: MessageManager.h:66
virtual ~MessageManager()
Definition: MessageManager.cpp:36
void processMessage(PdCom::Message message) override
Definition: MessageManager.cpp:54
Definition: MessageManager.h:57
Definition: MessageManager.h:36
MessageManager()
Definition: MessageManager.cpp:30
void processMessageSignal(PdCom::Message message)
void reset()
Definition: MessageManager.cpp:43