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
24#include "comms/ErrorStatus.h"
25
26#include <QtCore/QObject>
27#include <QtCore/QVariantList>
28#include <QtCore/QVariantMap>
29
30#include <cstdint>
31#include <list>
32#include <memory>
33#include <vector>
34
35namespace cc_tools_qt
36{
37
38class ToolsFrame;
39
43class CC_TOOLS_API ToolsMessage : public QObject
44{
45 using Base = QObject;
46public:
48 using Ptr = std::unique_ptr<ToolsMessage>;
49
51 using DataSeq = std::vector<std::uint8_t>;
52
53 using FieldsList = std::vector<ToolsFieldPtr>;
54
56 enum class Type {
57 Invalid,
58 Received,
59 Sent,
60 NumOfValues
61 };
62
65 virtual ~ToolsMessage() noexcept;
66
69 const char* name() const;
70
75 bool refreshMsg();
76
79 QString idAsString() const;
80
81 qlonglong numericId() const;
82
84 void reset();
85
89 bool assign(const ToolsMessage& other);
90
93 bool isValid() const;
94
97 DataSeq encodeData() const;
98
101 bool decodeData(const DataSeq& data);
102
103 Ptr clone() const;
104
105 void assignProtMessage(void* protMsg);
106
107 DataSeq encodeFramed(ToolsFrame& frame) const;
108
109 FieldsList transportFields();
110 FieldsList payloadFields();
111
112protected:
113
114 ToolsMessage();
115
118 virtual const char* nameImpl() const = 0;
119
122 virtual bool refreshMsgImpl() = 0;
123
126 virtual qlonglong numericIdImpl() const = 0;
127
130 virtual QString idAsStringImpl() const;
131
134 virtual void resetImpl() = 0;
135
138 virtual bool assignImpl(const ToolsMessage& other) = 0;
139
142 virtual bool isValidImpl() const = 0;
143
146 virtual DataSeq encodeDataImpl() const = 0;
147
150 virtual bool decodeDataImpl(const DataSeq& data) = 0;
151
152 virtual Ptr cloneImpl() const = 0;
153
154 virtual void assignProtMessageImpl(void* protMsg) = 0;
155
156 virtual DataSeq encodeFramedImpl(ToolsFrame& frame) const = 0;
157
158 virtual FieldsList transportFieldsImpl() = 0;
159 virtual FieldsList payloadFieldsImpl() = 0;
160};
161
163using ToolsMessagePtr = std::shared_ptr<ToolsMessage>;
164using ToolsMessagesList = std::list<ToolsMessagePtr>;
165
166} // namespace cc_tools_qt
167
168Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessagePtr);
169Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessagesList);
170Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessage::DataSeq);
171Q_DECLARE_METATYPE(cc_tools_qt::ToolsMessage::Type);
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition ToolsMessage.h:44
virtual ~ToolsMessage() noexcept
Destructor.
std::unique_ptr< ToolsMessage > Ptr
Pointer to message object.
Definition ToolsMessage.h:48
std::vector< std::uint8_t > DataSeq
Type for sequence of raw bytes.
Definition ToolsMessage.h:51
Type
Type of the message.
Definition ToolsMessage.h:56
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:163