cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsExtraInfoMessage.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
24#include "comms/field/String.h"
25
26#include <QtCore/QString>
27#include <QtCore/QJsonObject>
28#include <QtCore/QJsonDocument>
29#include <QtCore/QByteArray>
30
31#include <cassert>
32#include <tuple>
33
34
35namespace cc_tools_qt
36{
37
38namespace details
39{
40
41template <typename TFieldBase>
42class ToolsExtraInfoMessageData : public
43 comms::field::String<
44 TFieldBase,
45 comms::option::def::HasName
46 >
47{
48 using Base =
49 comms::field::String<
50 TFieldBase,
51 comms::option::def::HasName
52 >;
53public:
54 static const char* name()
55 {
56 return "";
57 }
58
59 bool valid() const
60 {
61 auto& val = Base::value();
62 if (val.empty()) {
63 return true;
64 }
65
66 auto doc = QJsonDocument::fromJson(QByteArray(val.c_str(), static_cast<int>(val.size())));
67 return doc.isObject();
68 }
69};
70
71template <typename TMsgBase, typename...>
72class ToolsExtraInfoMessageImpl : public
73 comms::MessageBase<
74 TMsgBase,
75 comms::option::NoIdImpl,
76 comms::option::FieldsImpl<std::tuple<ToolsExtraInfoMessageData<typename TMsgBase::Field>>>,
77 comms::option::MsgType<ToolsExtraInfoMessageImpl<TMsgBase>>
78 >
79{
80
81};
82
83} // namespace details
84
85template<typename TBase>
86class ToolsExtraInfoMessage : public
88 TBase,
89 details::ToolsExtraInfoMessageImpl,
90 ToolsExtraInfoMessage<TBase>
91 >
92{
93 using Base =
95 TBase,
96 details::ToolsExtraInfoMessageImpl,
97 ToolsExtraInfoMessage<TBase>
98 >;
99public:
100 using FieldsList = typename Base::FieldsList;
101
102 virtual ~ToolsExtraInfoMessage() noexcept = default;
103
104protected:
105 virtual const char* nameImpl() const override
106 {
107 static const char* Str = "Generic Extra Info Message";
108 return Str;
109 }
110
111 virtual void resetImpl() override
112 {
113 [[maybe_unused]] static constexpr bool Must_not_be_called = false;
114 assert(Must_not_be_called);
115 }
116
117 virtual bool assignImpl([[maybe_unused]] const cc_tools_qt::ToolsMessage& other) override
118 {
119 [[maybe_unused]] static constexpr bool Must_not_be_called = false;
120 assert(Must_not_be_called);
121 return false;
122 }
123
124 virtual FieldsList transportFieldsImpl() override
125 {
126 return FieldsList();
127 }
128
129 virtual FieldsList payloadFieldsImpl() override
130 {
131 auto fields = Base::payloadFieldsImpl();
132 for (auto& f : fields) {
133 f->forceHiddenSerialization();
134 }
135 return fields;
136 }
137
138private:
139};
140
141} // namespace cc_tools_qt
142
143
144
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.