cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsMessage.h
1//
2// Copyright 2014 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7// This file is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20#pragma once
21
22#include "cc_tools_qt/ToolsApi.h"
23#include "cc_tools_qt/ToolsField.h"
24#include "cc_tools_qt/version.h"
25
26#include "comms/ErrorStatus.h"
27
28#include <QtCore/QObject>
29#include <QtCore/QVariantList>
30#include <QtCore/QVariantMap>
31
32#include <cstdint>
33#include <list>
34#include <memory>
35#include <vector>
36
37namespace cc_tools_qt
38{
39
40class ToolsFrame;
41
45class CC_TOOLS_API ToolsMessage : public QObject
46{
47 using Base = QObject;
48public:
50 using Ptr = std::unique_ptr<ToolsMessage>;
51
53 using DataSeq = std::vector<std::uint8_t>;
54
55 using FieldsList = std::vector<ToolsFieldPtr>;
56
58 enum class Type {
59 Invalid,
60 Received,
61 Sent,
62 NumOfValues
63 };
64
67 virtual ~ToolsMessage() noexcept;
68
71 [[nodiscard]] const char* name() const;
72
77 bool refreshMsg();
78
81 [[nodiscard]] QString idAsString() const;
82
83 [[nodiscard]] qlonglong numericId() const;
84
86 void reset();
87
91 bool assign(const ToolsMessage& other);
92
95 [[nodiscard]] bool isValid() const;
96
99 [[nodiscard]] DataSeq encodeData() const;
100
103 [[nodiscard]] bool decodeData(const DataSeq& data);
104
105 [[nodiscard]] Ptr clone() const;
106
107 void assignProtMessage(void* protMsg);
108
109 [[nodiscard]] DataSeq encodeFramed(ToolsFrame& frame) const;
110
111 [[nodiscard]] FieldsList transportFields();
112 [[nodiscard]] FieldsList payloadFields();
113
114protected:
115
116 ToolsMessage();
117
120 virtual const char* nameImpl() const = 0;
121
124 virtual bool refreshMsgImpl() = 0;
125
128 virtual qlonglong numericIdImpl() const = 0;
129
132 virtual QString idAsStringImpl() const;
133
136 virtual void resetImpl() = 0;
137
140 virtual bool assignImpl(const ToolsMessage& other) = 0;
141
144 virtual bool isValidImpl() const = 0;
145
148 virtual DataSeq encodeDataImpl() const = 0;
149
152 virtual bool decodeDataImpl(const DataSeq& data) = 0;
153
154 virtual Ptr cloneImpl() const = 0;
155
156 virtual void assignProtMessageImpl(void* protMsg) = 0;
157
158 virtual DataSeq encodeFramedImpl(ToolsFrame& frame) const = 0;
159
160 virtual FieldsList transportFieldsImpl() = 0;
161 virtual FieldsList payloadFieldsImpl() = 0;
162};
163
165using ToolsMessagePtr = std::shared_ptr<ToolsMessage>;
166using ToolsMessagesList = std::list<ToolsMessagePtr>;
167
168} // namespace cc_tools_qt
169
170Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessagePtr);
171Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessagesList);
172Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessage::DataSeq);
173Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessage::Type);
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition ToolsMessage.h:46
QString idAsString() const
Get string representation of message ID.
Definition ToolsMessage.cpp:64
bool isValid() const
Check the message contents are valid.
Definition ToolsMessage.cpp:84
virtual bool decodeDataImpl(const DataSeq &data)=0
Polymorphic deserialisation functionality.
virtual const char * nameImpl() const =0
Polymorphic name retrieval functionality.
virtual QString idAsStringImpl() const
Polymophic functionality to get string representation of message ID.
Definition ToolsMessage.cpp:133
virtual ~ToolsMessage() noexcept
Destructor.
virtual bool assignImpl(const ToolsMessage &other)=0
Polymophic assignment functionality.
bool refreshMsg()
Refresh message contents.
Definition ToolsMessage.cpp:59
virtual bool refreshMsgImpl()=0
Polymorphic refresh functionality.
virtual bool isValidImpl() const =0
Polymorphic validity check functionality.
bool decodeData(const DataSeq &data)
Decode (or deserialise) message contents.
Definition ToolsMessage.cpp:94
bool assign(const ToolsMessage &other)
Assign contents of other message to this ones.
Definition ToolsMessage.cpp:79
void reset()
Reset message contents to default constructed values.
Definition ToolsMessage.cpp:74
virtual DataSeq encodeDataImpl() const =0
Polymorphic serialisation functionality.
virtual qlonglong numericIdImpl() const =0
Polymophic functionality to get numeric message ID.
std::unique_ptr< ToolsMessage > Ptr
Pointer to message object.
Definition ToolsMessage.h:50
virtual void resetImpl()=0
Polymorphic reset functionality.
std::vector< std::uint8_t > DataSeq
Type for sequence of raw bytes.
Definition ToolsMessage.h:53
DataSeq encodeData() const
Encode (or serialise) message contents.
Definition ToolsMessage.cpp:89
const char * name() const
Get message name.
Definition ToolsMessage.cpp:54
Type
Type of the message.
Definition ToolsMessage.h:58
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:165