cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsInvalidMessage.h
1//
2// Copyright 2016 - 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/ToolsMessageBase.h"
23#include "cc_tools_qt/ToolsProtMsgInterface.h"
24#include "cc_tools_qt/property/message.h"
25#include "cc_tools_qt/version.h"
26
27#include <QtCore/QString>
28
29#include <cassert>
30#include <tuple>
31
32namespace cc_tools_qt
33{
34
35namespace details
36{
37
38template <typename TMsgBase, typename... TOpts>
39class ToolInvalidMessageImpl : public
40 comms::MessageBase<
41 TMsgBase,
42 comms::option::def::NoIdImpl,
43 comms::option::def::ZeroFieldsImpl,
44 comms::option::def::MsgType<ToolInvalidMessageImpl<TMsgBase, TOpts...>>
45 >
46{
47};
48
49} // namespace details
50
51template<typename TBase>
52class ToolsInvalidMessage : public
54 TBase,
55 details::ToolInvalidMessageImpl,
56 ToolsInvalidMessage<TBase>
57 >
58{
59 using Base =
61 TBase,
62 details::ToolInvalidMessageImpl,
63 ToolsInvalidMessage<TBase>
64 >;
65public:
66 using DataSeq = typename Base::DataSeq;
67 using FieldsList = typename Base::FieldsList;
68 virtual ~ToolsInvalidMessage() noexcept = default;
69
70protected:
71 virtual const char* nameImpl() const override
72 {
73 if (property::message::ToolsMsgTransportMsg().getFrom(*this)) {
74 static const char* InvalidMsgStr = "???";
75 return InvalidMsgStr;
76 }
77
78 static const char* GarbageStr = "-#-";
79 return GarbageStr;
80 }
81
82 virtual bool isValidImpl() const override
83 {
84 return false;
85 }
86
87 virtual qlonglong numericIdImpl() const override
88 {
89 return 0;
90 }
91
92 virtual void resetImpl() override
93 {
94 [[maybe_unused]] static constexpr bool Must_not_be_called = false;
95 assert(Must_not_be_called);
96 }
97
98 virtual bool assignImpl([[maybe_unused]] const cc_tools_qt::ToolsMessage& other) override
99 {
100 [[maybe_unused]] static constexpr bool Must_not_be_called = false;
101 assert(Must_not_be_called);
102 return false;
103 }
104
105 virtual DataSeq encodeDataImpl() const override
106 {
107 ToolsMessagePtr rawDataMsg = property::message::ToolsMsgRawDataMsg().getFrom(*this);
108 if (!rawDataMsg) {
109 assert(false);
110 return DataSeq();
111 }
112
113 return rawDataMsg->encodeData();
114 }
115
116 virtual DataSeq encodeFramedImpl([[maybe_unused]] ToolsFrame& frame) const override
117 {
118 return encodeDataImpl();
119 }
120
121 virtual typename Base::Ptr cloneImpl() const override
122 {
123 ToolsMessagePtr rawDataMsg = property::message::ToolsMsgRawDataMsg().getFrom(*this);
124 auto ptr = Base::cloneImpl();
125 if (ptr && rawDataMsg) {
126 ToolsMessagePtr p = rawDataMsg->clone();
127 property::message::ToolsMsgRawDataMsg().setTo(std::move(p), *ptr);
128 }
129
130 return ptr;
131 }
132
133 virtual FieldsList transportFieldsImpl() override
134 {
135 return FieldsList();
136 }
137};
138
139} // namespace cc_tools_qt
140
Helper class used to define protocol message class in CommsChampion Tools plugin environment.
Definition ToolsMessageBase.h:47
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition ToolsMessage.h:46
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:165