cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsProtocol.h
1//
2// Copyright 2014 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7// This file is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20#pragma once
21
22#include "cc_tools_qt/ToolsApi.h"
23#include "cc_tools_qt/ToolsDataInfo.h"
24#include "cc_tools_qt/ToolsFrame.h"
25#include "cc_tools_qt/ToolsMessage.h"
26#include "cc_tools_qt/version.h"
27
28#include <QtCore/QObject>
29#include <QtCore/QMetaType>
30#include <QtCore/QString>
31
32#include <cstdint>
33#include <cstddef>
34#include <list>
35#include <memory>
36
37namespace cc_tools_qt
38{
39
44
45class CC_TOOLS_API ToolsProtocol : public QObject
46{
47 Q_OBJECT
48public:
50 using DataInfosList = std::list<ToolsDataInfoPtr>;
51
54
56 enum class UpdateStatus
57 {
58 NoChange,
59 Changed
60 };
61
63 virtual ~ToolsProtocol() noexcept;
64
67 const QString& name() const;
68
73 ToolsMessagesList read(const ToolsDataInfo& dataInfo, bool final = false);
74
80
82 ToolsMessagesList createAllMessages();
83
88 ToolsMessagePtr createMessage(const QString& idAsString, unsigned idx = 0);
89
92 UpdateStatus updateMessage(ToolsMessage& msg);
93
96 ToolsMessagePtr cloneMessage(const ToolsMessage& msg);
97
99 ToolsMessagePtr createInvalidMessage(const MsgDataSeq& data);
100
104 void socketConnectionReport(bool connected);
105
109 void messageReceivedReport(ToolsMessagePtr msg);
110
114 void messageSentReport(ToolsMessagePtr msg);
115
121 void applyInterPluginConfig(const QVariantMap& props);
122
125 void setDebugOutputLevel(unsigned level = 0U);
126
127signals:
130 void sigSendMessageReport(ToolsMessagePtr msg);
131
134 void sigErrorReport(const QString& str);
135
138 void sigInterPluginConfigReport(const QVariantMap& props);
139
140protected:
141 explicit ToolsProtocol(ToolsFramePtr frame);
142
145 virtual const QString& nameImpl() const = 0;
146
150 virtual void socketConnectionReportImpl(bool connected);
151
155 virtual void messageReceivedReportImpl(ToolsMessagePtr msg);
156
160 virtual void messageSentReportImpl(ToolsMessagePtr msg);
161
165 virtual void applyInterPluginConfigImpl(const QVariantMap& props);
166
168 unsigned getDebugOutputLevel() const;
169
172 static void setTransportToMessageProperties(ToolsMessagePtr transportMsg, ToolsMessage& msg);
173
176 static void setRawDataToMessageProperties(ToolsMessagePtr rawDataMsg, ToolsMessage& msg);
177
180 static void setExtraInfoMsgToMessageProperties(ToolsMessagePtr extraInfoMsg, ToolsMessage& msg);
181
184 static ToolsMessagePtr getExtraInfoMsgToMessageProperties(const ToolsMessage& msg);
185
187 static QVariantMap getExtraInfoFromMessageProperties(const ToolsMessage& msg);
188
190 static void setExtraInfoToMessageProperties(const QVariantMap& extraInfo, ToolsMessage& msg);
191
193 static void mergeExtraInfoToMessageProperties(const QVariantMap& extraInfo, ToolsMessage& msg);
194
196 static void setForceExtraInfoExistenceToMessageProperties(ToolsMessage& msg);
197
199 static bool getForceExtraInfoExistenceFromMessageProperties(const ToolsMessage& msg);
200
201protected slots:
204 void setNameToMessageProperties(ToolsMessage& msg);
205
211 void reportError(const QString& str);
212
218 void sendMessageRequest(ToolsMessagePtr msg);
219
227 void reportInterPluginConfig(const QVariantMap& props);
228
229private:
230 struct InnerState;
231 std::unique_ptr<InnerState> m_state;
232};
233
235using ToolsProtocolPtr = std::shared_ptr<ToolsProtocol>;
236
237} // namespace cc_tools_qt
238
239Q_DECLARE_METATYPE(cc_tools_qt::ToolsProtocolPtr);
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition ToolsMessage.h:46
std::vector< std::uint8_t > DataSeq
Type for sequence of raw bytes.
Definition ToolsMessage.h:53
Main polymorphic interface class for protocols.
Definition ToolsProtocol.h:46
ToolsMessage::DataSeq MsgDataSeq
Type used to contain raw bytes seqence.
Definition ToolsProtocol.h:53
virtual ~ToolsProtocol() noexcept
Destructor.
std::list< ToolsDataInfoPtr > DataInfosList
List of raw data buffers.
Definition ToolsProtocol.h:50
UpdateStatus
Status of message "update" operation.
Definition ToolsProtocol.h:57
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsDataInfo > ToolsDataInfoPtr
Pointer to ToolsDataInfo.
Definition ToolsDataInfo.h:59
std::shared_ptr< ToolsProtocol > ToolsProtocolPtr
Pointer to ToolsProtocol object.
Definition ToolsProtocol.h:235
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:165
Information about incomming or outdoing data.
Definition ToolsDataInfo.h:39