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 [[nodiscard]] const QString& name() const;
68
73 [[nodiscard]] ToolsMessagesList read(const ToolsDataInfo& dataInfo, bool final = false);
74
79 [[nodiscard]] ToolsDataInfoPtr write(ToolsMessage& msg);
80
82 [[nodiscard]] ToolsMessagesList createAllMessages();
83
88 [[nodiscard]] ToolsMessagePtr createMessage(const QString& idAsString, unsigned idx = 0);
89
93
96 [[nodiscard]] ToolsMessagePtr cloneMessage(const ToolsMessage& msg);
97
99 [[nodiscard]] ToolsMessagePtr createInvalidMessage(const MsgDataSeq& data);
100
104 void socketConnectionReport(bool connected);
105
110
115
121 void applyInterPluginConfig(const QVariantMap& props);
122
125 void setDebugOutputLevel(unsigned level = 0U);
126
127signals:
131
134 void sigErrorReport(const QString& str);
135
138 void sigInterPluginConfigReport(const QVariantMap& props);
139
140protected:
141 explicit ToolsProtocol(ToolsFramePtr frame);
142
145 [[nodiscard]] virtual const QString& nameImpl() const = 0;
146
150 virtual void socketConnectionReportImpl(bool connected);
151
156
160 virtual void messageSentReportImpl(ToolsMessagePtr msg);
161
165 virtual void applyInterPluginConfigImpl(const QVariantMap& props);
166
168 [[nodiscard]] unsigned getDebugOutputLevel() const;
169
172 static void setTransportToMessageProperties(ToolsMessagePtr transportMsg, ToolsMessage& msg);
173
176 static void setRawDataToMessageProperties(ToolsMessagePtr rawDataMsg, ToolsMessage& msg);
177
181
184 [[nodiscard]] static ToolsMessagePtr getExtraInfoMsgToMessageProperties(const ToolsMessage& msg);
185
187 [[nodiscard]] 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
197
200
201protected slots:
205
211 void reportError(const QString& str);
212
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
void sigSendMessageReport(ToolsMessagePtr msg)
Signal used to report new protocol message to be sent out.
static void mergeExtraInfoToMessageProperties(const QVariantMap &extraInfo, ToolsMessage &msg)
Helper function to merge existing "extra info" and provided one.
Definition ToolsProtocol.cpp:404
void socketConnectionReport(bool connected)
Make the protocol aware about socket connection status.
Definition ToolsProtocol.cpp:319
void sigErrorReport(const QString &str)
Signal used to report error.
static bool getForceExtraInfoExistenceFromMessageProperties(const ToolsMessage &msg)
Helper function to check whether "extra info" existence is force.
Definition ToolsProtocol.cpp:420
static void setTransportToMessageProperties(ToolsMessagePtr transportMsg, ToolsMessage &msg)
Helper function to assign "tranport message" object as a property of application message object.
Definition ToolsProtocol.cpp:372
ToolsMessage::DataSeq MsgDataSeq
Type used to contain raw bytes seqence.
Definition ToolsProtocol.h:53
virtual void messageSentReportImpl(ToolsMessagePtr msg)
Make the protocol aware that the message has been sent out to the remote end.
Definition ToolsProtocol.cpp:359
void applyInterPluginConfig(const QVariantMap &props)
Apply inter-plugin configuration.
Definition ToolsProtocol.cpp:334
void reportError(const QString &str)
Report operation error.
Definition ToolsProtocol.cpp:430
static void setExtraInfoToMessageProperties(const QVariantMap &extraInfo, ToolsMessage &msg)
Helper function to set "extra info" to message properties.
Definition ToolsProtocol.cpp:397
const QString & name() const
Retrieve name of the protocol.
Definition ToolsProtocol.cpp:80
virtual void socketConnectionReportImpl(bool connected)
Polymorphic processing of the socket connection report.
Definition ToolsProtocol.cpp:351
virtual const QString & nameImpl() const =0
Polymorphic protocol name retrieval.
ToolsMessagePtr createMessage(const QString &idAsString, unsigned idx=0)
Create message object given string representation of the message ID.
Definition ToolsProtocol.cpp:191
static ToolsMessagePtr getExtraInfoMsgToMessageProperties(const ToolsMessage &msg)
Helper function to retrieve "extra info message" object from properties of the application message ob...
Definition ToolsProtocol.cpp:387
void setNameToMessageProperties(ToolsMessage &msg)
Helper function to assign protocol name to message properties.
Definition ToolsProtocol.cpp:425
static void setForceExtraInfoExistenceToMessageProperties(ToolsMessage &msg)
Helper function to force "extra info" existence.
Definition ToolsProtocol.cpp:415
void sendMessageRequest(ToolsMessagePtr msg)
Request a protocol message to be sent out.
Definition ToolsProtocol.cpp:435
void reportInterPluginConfig(const QVariantMap &props)
Report inter-plugin configuration.
Definition ToolsProtocol.cpp:440
virtual void applyInterPluginConfigImpl(const QVariantMap &props)
Polymorphic inter-plugin configuration application.
Definition ToolsProtocol.cpp:363
virtual void messageReceivedReportImpl(ToolsMessagePtr msg)
Polymorphic processing of the message reception report.
Definition ToolsProtocol.cpp:355
static void setRawDataToMessageProperties(ToolsMessagePtr rawDataMsg, ToolsMessage &msg)
Helper function to assign "raw data message" object as a property of application message object.
Definition ToolsProtocol.cpp:377
virtual ~ToolsProtocol() noexcept
Destructor.
static void setExtraInfoMsgToMessageProperties(ToolsMessagePtr extraInfoMsg, ToolsMessage &msg)
Helper function to assign "extra info message" object as a property of application message object.
Definition ToolsProtocol.cpp:382
ToolsMessagesList createAllMessages()
Create all messages supported by the protocol.
Definition ToolsProtocol.cpp:167
UpdateStatus updateMessage(ToolsMessage &msg)
Update (or refresh) message contents.
Definition ToolsProtocol.cpp:201
ToolsMessagesList read(const ToolsDataInfo &dataInfo, bool final=false)
Read the received data input.
Definition ToolsProtocol.cpp:85
std::list< ToolsDataInfoPtr > DataInfosList
List of raw data buffers.
Definition ToolsProtocol.h:50
ToolsMessagePtr createInvalidMessage(const MsgDataSeq &data)
Create dummy message containing invalid input.
Definition ToolsProtocol.cpp:297
void messageReceivedReport(ToolsMessagePtr msg)
Make the protocol aware that the message has been received from remote end.
Definition ToolsProtocol.cpp:324
static QVariantMap getExtraInfoFromMessageProperties(const ToolsMessage &msg)
Helper function to retrieve "extra info" from message properties.
Definition ToolsProtocol.cpp:392
ToolsDataInfoPtr write(ToolsMessage &msg)
Serialise message.
Definition ToolsProtocol.cpp:121
ToolsMessagePtr cloneMessage(const ToolsMessage &msg)
Clone the message object.
Definition ToolsProtocol.cpp:247
void messageSentReport(ToolsMessagePtr msg)
Make the protocol aware that the message has been sent out to the remote end.
Definition ToolsProtocol.cpp:329
void sigInterPluginConfigReport(const QVariantMap &props)
Signal to report inter-plugin configuration.
unsigned getDebugOutputLevel() const
Get current debug output level.
Definition ToolsProtocol.cpp:367
UpdateStatus
Status of message "update" operation.
Definition ToolsProtocol.h:57
void setDebugOutputLevel(unsigned level=0U)
Set debug output level.
Definition ToolsProtocol.cpp:339
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:165
std::shared_ptr< ToolsProtocol > ToolsProtocolPtr
Pointer to ToolsProtocol object.
Definition ToolsProtocol.h:235
std::shared_ptr< ToolsDataInfo > ToolsDataInfoPtr
Pointer to ToolsDataInfo.
Definition ToolsDataInfo.h:59
Information about incomming or outdoing data.
Definition ToolsDataInfo.h:39