1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef MESSAGE_H
5#define MESSAGE_H
6
7#include <QtCore/qglobal.h>
8#include <QtCore/qlist.h>
9
10#include <QtCore/qbytearray.h>
11
12QT_BEGIN_NAMESPACE
13
14class QIODevice;
15
16using MessageId = QByteArrayView;
17
18struct Message
19{
20 enum class Type { Invalid, Uniforms, Filenames };
21
22 using MessagePtr = std::shared_ptr<Message>;
23
24 virtual ~Message();
25 // NOTE! These functions assume the device is open and read/writeable when called!
26 virtual bool read(QDataStream &device) = 0;
27 virtual bool write(QDataStream &device) const = 0;
28 virtual Type type() const = 0;
29
30 static Message::MessagePtr getMessage(QIODevice &device);
31 static bool postMessage(QIODevice &device, const Message &message);
32
33 friend QDataStream &operator>>(QDataStream &stream, Message &message) { message.read(device&: stream); return stream; }
34 friend QDataStream &operator<<(QDataStream &stream, const Message &message) { message.write(device&: stream); return stream; }
35};
36
37struct UniformsMessage : Message
38{
39 static constexpr MessageId id { "UM" };
40
41 using Uniform = std::pair<QByteArray /* type */, QByteArray /* name */>;
42 using UniformList = QList<Uniform>;
43 UniformList uniforms;
44
45 UniformsMessage() = default;
46 UniformsMessage(UniformList list) : uniforms(list) {}
47 ~UniformsMessage() override;
48
49 bool read(QDataStream &stream) final;
50 bool write(QDataStream &stream) const final;
51 Type type() const final { return Type::Uniforms; }
52};
53
54struct FilenamesMessage : Message
55{
56 static constexpr MessageId id { "FM" };
57
58 ~FilenamesMessage() override;
59 bool read(QDataStream &stream) final;
60 bool write(QDataStream &stream) const final;
61 Type type() const final { return Type::Filenames; }
62 QByteArray vertFilename;
63 QByteArray fragFilename;
64};
65
66QT_END_NAMESPACE
67
68#endif // MESSAGE_H
69

source code of qtquick3d/tools/materialeditor/message.h