cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsProtocol.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/ToolsDataInfo.h"
23#include "cc_tools_qt/ToolsFrame.h"
24#include "cc_tools_qt/ToolsMessage.h"
25
26#include <QtCore/QObject>
27#include <QtCore/QMetaType>
28#include <QtCore/QString>
29
30#include <cstdint>
31#include <cstddef>
32#include <list>
33#include <memory>
34
35namespace cc_tools_qt
36{
37
42
43class CC_TOOLS_API ToolsProtocol : public QObject
44{
45 Q_OBJECT
46public:
48 using DataInfosList = std::list<ToolsDataInfoPtr>;
49
52
54 enum class UpdateStatus
55 {
56 NoChange,
57 Changed
58 };
59
61 virtual ~ToolsProtocol() noexcept;
62
65 const QString& name() const;
66
71 ToolsMessagesList read(const ToolsDataInfo& dataInfo, bool final = false);
72
78
80 ToolsMessagesList createAllMessages();
81
86 ToolsMessagePtr createMessage(const QString& idAsString, unsigned idx = 0);
87
90 UpdateStatus updateMessage(ToolsMessage& msg);
91
94 ToolsMessagePtr cloneMessage(const ToolsMessage& msg);
95
97 ToolsMessagePtr createInvalidMessage(const MsgDataSeq& data);
98
102 void socketConnectionReport(bool connected);
103
107 void messageReceivedReport(ToolsMessagePtr msg);
108
112 void messageSentReport(ToolsMessagePtr msg);
113
119 void applyInterPluginConfig(const QVariantMap& props);
120
123 void setDebugOutputLevel(unsigned level = 0U);
124
125signals:
128 void sigSendMessageReport(ToolsMessagePtr msg);
129
132 void sigErrorReport(const QString& str);
133
136 void sigInterPluginConfigReport(const QVariantMap& props);
137
138protected:
139 explicit ToolsProtocol(ToolsFramePtr frame);
140
143 virtual const QString& nameImpl() const = 0;
144
148 virtual void socketConnectionReportImpl(bool connected);
149
153 virtual void messageReceivedReportImpl(ToolsMessagePtr msg);
154
158 virtual void messageSentReportImpl(ToolsMessagePtr msg);
159
163 virtual void applyInterPluginConfigImpl(const QVariantMap& props);
164
167 void setNameToMessageProperties(ToolsMessage& msg);
168
174 void reportError(const QString& str);
175
181 void sendMessageRequest(ToolsMessagePtr msg);
182
190 void reportInterPluginConfig(const QVariantMap& props);
191
193 unsigned getDebugOutputLevel() const;
194
197 static void setTransportToMessageProperties(ToolsMessagePtr transportMsg, ToolsMessage& msg);
198
201 static void setRawDataToMessageProperties(ToolsMessagePtr rawDataMsg, ToolsMessage& msg);
202
205 static void setExtraInfoMsgToMessageProperties(ToolsMessagePtr extraInfoMsg, ToolsMessage& msg);
206
209 static ToolsMessagePtr getExtraInfoMsgToMessageProperties(const ToolsMessage& msg);
210
212 static QVariantMap getExtraInfoFromMessageProperties(const ToolsMessage& msg);
213
215 static void setExtraInfoToMessageProperties(const QVariantMap& extraInfo, ToolsMessage& msg);
216
218 static void mergeExtraInfoToMessageProperties(const QVariantMap& extraInfo, ToolsMessage& msg);
219
221 static void setForceExtraInfoExistenceToMessageProperties(ToolsMessage& msg);
222
224 static bool getForceExtraInfoExistenceFromMessageProperties(const ToolsMessage& msg);
225
226private:
227 struct InnerState;
228 std::unique_ptr<InnerState> m_state;
229};
230
232using ToolsProtocolPtr = std::shared_ptr<ToolsProtocol>;
233
234} // namespace cc_tools_qt
235
236Q_DECLARE_METATYPE(cc_tools_qt::ToolsProtocolPtr);
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition ToolsMessage.h:44
std::vector< std::uint8_t > DataSeq
Type for sequence of raw bytes.
Definition ToolsMessage.h:51
Main polymorphic interface class for protocols.
Definition ToolsProtocol.h:44
ToolsMessage::DataSeq MsgDataSeq
Type used to contain raw bytes seqence.
Definition ToolsProtocol.h:51
virtual ~ToolsProtocol() noexcept
Destructor.
std::list< ToolsDataInfoPtr > DataInfosList
List of raw data buffers.
Definition ToolsProtocol.h:48
UpdateStatus
Status of message "update" operation.
Definition ToolsProtocol.h:55
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsDataInfo > ToolsDataInfoPtr
Pointer to ToolsDataInfo.
Definition ToolsDataInfo.h:57
std::shared_ptr< ToolsProtocol > ToolsProtocolPtr
Pointer to ToolsProtocol object.
Definition ToolsProtocol.h:232
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:163
Information about incomming or outdoing data.
Definition ToolsDataInfo.h:37