cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsMessage.h
1//
2// Copyright 2014 - 2025 (C). Alex Robenko. All rights reserved.
3//
4
5// This file is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
19#pragma once
20
21#include "cc_tools_qt/ToolsApi.h"
22#include "cc_tools_qt/ToolsField.h"
23#include "cc_tools_qt/version.h"
24
25#include "comms/ErrorStatus.h"
26
27#include <QtCore/QObject>
28#include <QtCore/QVariantList>
29#include <QtCore/QVariantMap>
30
31#include <cstdint>
32#include <list>
33#include <memory>
34#include <vector>
35
36namespace cc_tools_qt
37{
38
39class ToolsFrame;
40
44class CC_TOOLS_API ToolsMessage : public QObject
45{
46 using Base = QObject;
47public:
49 using Ptr = std::unique_ptr<ToolsMessage>;
50
52 using DataSeq = std::vector<std::uint8_t>;
53
54 using FieldsList = std::vector<ToolsFieldPtr>;
55
57 enum class Type {
58 Invalid,
59 Received,
60 Sent,
61 NumOfValues
62 };
63
66 virtual ~ToolsMessage() noexcept;
67
70 const char* name() const;
71
76 bool refreshMsg();
77
80 QString idAsString() const;
81
82 qlonglong numericId() const;
83
85 void reset();
86
90 bool assign(const ToolsMessage& other);
91
94 bool isValid() const;
95
98 DataSeq encodeData() const;
99
102 bool decodeData(const DataSeq& data);
103
104 Ptr clone() const;
105
106 void assignProtMessage(void* protMsg);
107
108 DataSeq encodeFramed(ToolsFrame& frame) const;
109
110 FieldsList transportFields();
111 FieldsList payloadFields();
112
113protected:
114
115 ToolsMessage();
116
119 virtual const char* nameImpl() const = 0;
120
123 virtual bool refreshMsgImpl() = 0;
124
127 virtual qlonglong numericIdImpl() const = 0;
128
131 virtual QString idAsStringImpl() const;
132
135 virtual void resetImpl() = 0;
136
139 virtual bool assignImpl(const ToolsMessage& other) = 0;
140
143 virtual bool isValidImpl() const = 0;
144
147 virtual DataSeq encodeDataImpl() const = 0;
148
151 virtual bool decodeDataImpl(const DataSeq& data) = 0;
152
153 virtual Ptr cloneImpl() const = 0;
154
155 virtual void assignProtMessageImpl(void* protMsg) = 0;
156
157 virtual DataSeq encodeFramedImpl(ToolsFrame& frame) const = 0;
158
159 virtual FieldsList transportFieldsImpl() = 0;
160 virtual FieldsList payloadFieldsImpl() = 0;
161};
162
164using ToolsMessagePtr = std::shared_ptr<ToolsMessage>;
165using ToolsMessagesList = std::list<ToolsMessagePtr>;
166
167} // namespace cc_tools_qt
168
169Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessagePtr);
170Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessagesList);
171Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessage::DataSeq);
172Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessage::Type);
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition ToolsMessage.h:45
virtual ~ToolsMessage() noexcept
Destructor.
std::unique_ptr< ToolsMessage > Ptr
Pointer to message object.
Definition ToolsMessage.h:49
std::vector< std::uint8_t > DataSeq
Type for sequence of raw bytes.
Definition ToolsMessage.h:52
Type
Type of the message.
Definition ToolsMessage.h:57
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:164