cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
Message.h
1//
2// Copyright 2014 - 2024 (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 <vector>
22#include <cstdint>
23#include <memory>
24
25#include <QtCore/QObject>
26#include <QtCore/QVariantList>
27#include <QtCore/QVariantMap>
28
29#include "Api.h"
30
31namespace cc_tools_qt
32{
33
34class MessageHandler;
35class MessageWidget;
36
40class CC_API Message : public QObject
41{
42 using Base = QObject;
43public:
45 using DataSeq = std::vector<std::uint8_t>;
46
48 enum class Type {
49 Invalid,
50 Received,
51 Sent,
52 NumOfValues
53 };
54
57 virtual ~Message() noexcept;
58
61 const char* name() const;
62
65 const QVariantList& extraTransportFieldsProperties() const;
66
69 const QVariantList& fieldsProperties() const;
70
73 void dispatch(MessageHandler& handler);
74
79 bool refreshMsg();
80
83 QString idAsString() const;
84
86 void reset();
87
91 bool assign(const Message& other);
92
95 bool isValid() const;
96
99 DataSeq encodeData() const;
100
103 bool decodeData(const DataSeq& data);
104
105protected:
106
109 virtual const char* nameImpl() const = 0;
110
115 virtual const QVariantList& extraTransportFieldsPropertiesImpl() const;
116
121 virtual const QVariantList& fieldsPropertiesImpl() const;
122
125 virtual void dispatchImpl(MessageHandler& handler) = 0;
126
129 virtual bool refreshMsgImpl() = 0;
130
133 virtual QString idAsStringImpl() const = 0;
134
137 virtual void resetImpl() = 0;
138
141 virtual bool assignImpl(const Message& other) = 0;
142
145 virtual bool isValidImpl() const = 0;
146
149 virtual DataSeq encodeDataImpl() const = 0;
150
153 virtual bool decodeDataImpl(const DataSeq& data) = 0;
154};
155
157using MessagePtr = std::shared_ptr<Message>;
158
159} // namespace cc_tools_qt
160
161Q_DECLARE_METATYPE(cc_tools_qt::MessagePtr);
162Q_DECLARE_METATYPE(cc_tools_qt::Message::DataSeq);
Generic message handler used by CommsChampion Tools.
Definition MessageHandler.h:36
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition Message.h:41
Type
Type of the message.
Definition Message.h:48
virtual ~Message() noexcept
Destructor.
std::vector< std::uint8_t > DataSeq
Type for sequence of raw bytes.
Definition Message.h:45
Main namespace for all classes / functions of the shared library.
std::shared_ptr< Message > MessagePtr
Smart pointer to Message.
Definition Message.h:157