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