cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ExtraInfoMessage.h
1//
2// Copyright 2016 - 2024 (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
22#include <cassert>
23#include <tuple>
24
25#include <QtCore/QString>
26#include <QtCore/QJsonObject>
27#include <QtCore/QJsonDocument>
28#include <QtCore/QByteArray>
29
30#include "comms/comms.h"
31#include "property/field.h"
32#include "ProtocolMessageBase.h"
33#include "cc_tools_qt.h"
34
35namespace cc_tools_qt
36{
37
38namespace details
39{
40
41template <typename TFieldBase>
42struct ExtraInfoMessageData : public comms::field::String<TFieldBase>
43{
44 bool valid() const
45 {
46 using Base = comms::field::String<TFieldBase>;
47
48 auto& val = Base::value();
49 if (val.empty()) {
50 return true;
51 }
52
53 auto doc = QJsonDocument::fromJson(QByteArray(val.c_str(), static_cast<int>(val.size())));
54 return doc.isObject();
55 }
56};
57
58template <typename TMsgBase>
59class ExtraInfoMessageImpl : public
60 comms::MessageBase<
61 TMsgBase,
62 comms::option::NoIdImpl,
63 comms::option::FieldsImpl<std::tuple<ExtraInfoMessageData<typename TMsgBase::Field> > >,
64 comms::option::MsgType<ExtraInfoMessageImpl<TMsgBase> >
65 >
66{
67
68};
69
70} // namespace details
71
72template <typename TMsgBase>
73class ExtraInfoMessage : public
74 ProtocolMessageBase<
75 details::ExtraInfoMessageImpl<TMsgBase>,
76 ExtraInfoMessage<TMsgBase>
77 >
78{
79public:
80 virtual ~ExtraInfoMessage() noexcept = default;
81
82protected:
83 virtual const char*
84 nameImpl() const override
85 {
86 static const char* Str = "Generic Extra Info Message";
87 return Str;
88 }
89
91 virtual const QVariantList& extraTransportFieldsPropertiesImpl() const override
92 {
93 static const QVariantList List;
94 return List;
95 }
96
97 virtual const QVariantList& fieldsPropertiesImpl() const override
98 {
99 static const QVariantList Props = createFieldsProperties();
100 return Props;
101 }
102
103 virtual QString idAsStringImpl() const override
104 {
105 [[maybe_unused]] static constexpr bool Must_not_be_called = false;
106 assert(Must_not_be_called);
107 return QString();
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::Message& 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
123private:
124
125 static QVariantList createFieldsProperties()
126 {
127 QVariantList props;
128 props.append(
129 property::field::String().serialisedHidden().asMap());
130 return props;
131 }
132};
133
134} // namespace cc_tools_qt
135
136
137
Single "include all" file.
Main interface class used by CommsChampion Tools to display and manipulate messages.
Definition Message.h:41
Main namespace for all classes / functions of the shared library.