GCC Code Coverage Report


Directory: ./
File: pdcom5/include/pdcom5/MessageManagerBase.h
Date: 2024-11-17 04:08:36
Exec Total Coverage
Lines: 2 2 100.0%
Branches: 1 2 50.0%

Line Branch Exec Source
1 /*****************************************************************************
2 * vim:tw=78
3 *
4 * Copyright (C) 2022 Richard Hacker (lerichi at gmx dot net),
5 * Bjarne von Horn (vh at igh dot de).
6 *
7 * This file is part of the PdCom library.
8 *
9 * The PdCom library is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * The PdCom library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *****************************************************************************/
23
24 /** @file */
25
26 #ifndef PDCOM5_MESSAGEMANAGERBASE_H
27 #define PDCOM5_MESSAGEMANAGERBASE_H
28
29 #include <chrono>
30 #include <cstdint>
31 #include <memory>
32 #include <pdcom5_export.h>
33 #include <string>
34 #include <vector>
35
36 namespace PdCom {
37 namespace impl {
38 class Process;
39 }
40
41 enum class LogLevel : int {
42 Reset = -1, /**< Message is reset */
43 Emergency = 0, /**< Emergency log level */
44 Alert = 1, /**< Alert log level */
45 Critical = 2, /**< Critical log level */
46 Error = 3, /**< Error log level */
47 Warn = 4, /**< Warn log level */
48 Info = 6, /**< Info log level */
49 Debug = 7, /**< Debug log level */
50 Trace = 8, /**< Trace log level */
51 };
52
53 /** Message structure */
54
1/2
✓ Branch 17 taken 9 times.
✗ Branch 18 not taken.
282 struct Message
55 {
56 uint32_t seqNo; /**< sequence number. Note that seqNo
57 wraps naturally */
58 LogLevel level; /**< severity */
59 std::string path; /**< event's path */
60 std::chrono::nanoseconds time; /**< event time in nanoseconds since epoch */
61 std::string text; /**< Text of message */
62 int index; /**< -1 for scalar;
63 index in case of a vector */
64 };
65
66 109 class PDCOM5_PUBLIC MessageManagerBase
67 {
68 public:
69 MessageManagerBase();
70 MessageManagerBase(MessageManagerBase &&) noexcept;
71 MessageManagerBase(MessageManagerBase const &) = delete;
72 MessageManagerBase &operator=(MessageManagerBase &&) noexcept;
73 MessageManagerBase &operator=(MessageManagerBase const &) = delete;
74
75 protected:
76 /** Request specific message from history
77 *
78 * The message is received in getMessageReply().
79 *
80 * If the seqNo is not available, getMessageReply()
81 * is called with null \p path and requested seqNo.
82 *
83 * @param seqNo sequence number of message
84 */
85 void getMessage(uint32_t seqNo) const;
86
87 /** Request a list of all active messages.
88 *
89 * This will return a list of active process messages as well as
90 * the last message in activeMessagesReply() if its state is
91 * Reset.
92 */
93 void activeMessages() const;
94
95 virtual ~MessageManagerBase();
96
97 private:
98 friend impl::Process;
99 std::weak_ptr<impl::Process> process_;
100
101 /** Message event from process
102 *
103 * This method is called whenever a message event is generated by
104 * the process.
105 *
106 * Reimplement this method to receive them.
107 *
108 * @param message
109 */
110 virtual void processMessage(Message message);
111
112 /** Reply to getMessage()
113 *
114 * Reimplement this method to receive responses to getMessage().
115 *
116 * @param message
117 */
118 virtual void getMessageReply(Message message);
119
120 /** Reply to activeMessages()
121 *
122 * Reimplement this method to receive the message list.
123 *
124 * The process messages received in processMessage() has strictly
125 * increasing sequence numbers and time.
126 *
127 * @param messageList
128 */
129 virtual void activeMessagesReply(std::vector<Message> messageList);
130 };
131 } // namespace PdCom
132
133
134 #endif // PDCOM5_MESSAGEMANAGERBASE_H
135