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#include "cc_tools_qt/version.h"
26
27#include <QtCore/QObject>
28#include <QtCore/QMetaType>
29#include <QtCore/QString>
30
31#include <cstdint>
32#include <cstddef>
33#include <list>
34#include <memory>
35
36namespace cc_tools_qt
37{
38
43
44class CC_TOOLS_API ToolsProtocol : public QObject
45{
46 Q_OBJECT
47public:
49 using DataInfosList = std::list<ToolsDataInfoPtr>;
50
53
55 enum class UpdateStatus
56 {
57 NoChange,
58 Changed
59 };
60
62 virtual ~ToolsProtocol() noexcept;
63
66 const QString& name() const;
67
72 ToolsMessagesList read(const ToolsDataInfo& dataInfo, bool final = false);
73
79
81 ToolsMessagesList createAllMessages();
82
87 ToolsMessagePtr createMessage(const QString& idAsString, unsigned idx = 0);
88
91 UpdateStatus updateMessage(ToolsMessage& msg);
92
95 ToolsMessagePtr cloneMessage(const ToolsMessage& msg);
96
98 ToolsMessagePtr createInvalidMessage(const MsgDataSeq& data);
99
103 void socketConnectionReport(bool connected);
104
108 void messageReceivedReport(ToolsMessagePtr msg);
109
113 void messageSentReport(ToolsMessagePtr msg);
114
120 void applyInterPluginConfig(const QVariantMap& props);
121
124 void setDebugOutputLevel(unsigned level = 0U);
125
126signals:
129 void sigSendMessageReport(ToolsMessagePtr msg);
130
133 void sigErrorReport(const QString& str);
134
137 void sigInterPluginConfigReport(const QVariantMap& props);
138
139protected:
140 explicit ToolsProtocol(ToolsFramePtr frame);
141
144 virtual const QString& nameImpl() const = 0;
145
149 virtual void socketConnectionReportImpl(bool connected);
150
154 virtual void messageReceivedReportImpl(ToolsMessagePtr msg);
155
159 virtual void messageSentReportImpl(ToolsMessagePtr msg);
160
164 virtual void applyInterPluginConfigImpl(const QVariantMap& props);
165
167 unsigned getDebugOutputLevel() const;
168
171 static void setTransportToMessageProperties(ToolsMessagePtr transportMsg, ToolsMessage& msg);
172
175 static void setRawDataToMessageProperties(ToolsMessagePtr rawDataMsg, ToolsMessage& msg);
176
179 static void setExtraInfoMsgToMessageProperties(ToolsMessagePtr extraInfoMsg, ToolsMessage& msg);
180
183 static ToolsMessagePtr getExtraInfoMsgToMessageProperties(const ToolsMessage& msg);
184
186 static QVariantMap getExtraInfoFromMessageProperties(const ToolsMessage& msg);
187
189 static void setExtraInfoToMessageProperties(const QVariantMap& extraInfo, ToolsMessage& msg);
190
192 static void mergeExtraInfoToMessageProperties(const QVariantMap& extraInfo, ToolsMessage& msg);
193
195 static void setForceExtraInfoExistenceToMessageProperties(ToolsMessage& msg);
196
198 static bool getForceExtraInfoExistenceFromMessageProperties(const ToolsMessage& msg);
199
200protected slots:
203 void setNameToMessageProperties(ToolsMessage& msg);
204
210 void reportError(const QString& str);
211
217 void sendMessageRequest(ToolsMessagePtr msg);
218
226 void reportInterPluginConfig(const QVariantMap& props);
227
228private:
229 struct InnerState;
230 std::unique_ptr<InnerState> m_state;
231};
232
234using ToolsProtocolPtr = std::shared_ptr<ToolsProtocol>;
235
236} // namespace cc_tools_qt
237
238Q_DECLARE_METATYPE(cc_tools_qt::ToolsProtocolPtr);
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition ToolsMessage.h:45
std::vector< std::uint8_t > DataSeq
Type for sequence of raw bytes.
Definition ToolsMessage.h:52
Main polymorphic interface class for protocols.
Definition ToolsProtocol.h:45
ToolsMessage::DataSeq MsgDataSeq
Type used to contain raw bytes seqence.
Definition ToolsProtocol.h:52
virtual ~ToolsProtocol() noexcept
Destructor.
std::list< ToolsDataInfoPtr > DataInfosList
List of raw data buffers.
Definition ToolsProtocol.h:49
UpdateStatus
Status of message "update" operation.
Definition ToolsProtocol.h:56
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsDataInfo > ToolsDataInfoPtr
Pointer to ToolsDataInfo.
Definition ToolsDataInfo.h:58
std::shared_ptr< ToolsProtocol > ToolsProtocolPtr
Pointer to ToolsProtocol object.
Definition ToolsProtocol.h:234
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:164
Information about incomming or outdoing data.
Definition ToolsDataInfo.h:38