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