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