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