File indexing completed on 2024-12-15 05:02:05
0001 /* 0002 SPDX-FileCopyrightText: 2018 Ivan Čukić <ivan.cukic(at)kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef BLADE_CONTROLLER_MESSAGE_H 0008 #define BLADE_CONTROLLER_MESSAGE_H 0009 0010 #include <variant> 0011 0012 #include <QString> 0013 #include <QByteArray> 0014 #include <QDebug> 0015 0016 namespace blade { 0017 0018 struct PingMessage {}; 0019 0020 inline 0021 QDebug operator<< (QDebug out, const PingMessage& msg) 0022 { 0023 return out.nospace() << "PingMessage{}"; 0024 } 0025 0026 0027 0028 struct QueryMessage { 0029 std::uint64_t id; 0030 QString text; 0031 }; 0032 0033 inline 0034 QDebug operator<< (QDebug out, const QueryMessage& msg) 0035 { 0036 return out.nospace() << "QueryMessage{" << msg.id << ", " << msg.text << "}"; 0037 } 0038 0039 0040 0041 struct ErrorMessage { 0042 std::uint16_t code; 0043 QByteArray message; 0044 }; 0045 0046 inline 0047 QDebug operator<< (QDebug out, const ErrorMessage& msg) 0048 { 0049 return out.nospace() << "ErrorMessage{" << msg.code << ", " << msg.message << "}"; 0050 } 0051 0052 0053 0054 struct ControllerMessage { 0055 QByteArray host; 0056 QByteArray controller; 0057 0058 std::variant< 0059 PingMessage, 0060 QueryMessage, 0061 ErrorMessage 0062 > message; 0063 }; 0064 0065 inline 0066 QDebug operator<< (QDebug out, const ControllerMessage& cm) 0067 { 0068 out.nospace() << "ControllerMessage{" << cm.host << ", " << cm.controller << "}::"; 0069 std::visit([&] (const auto &cm) { 0070 out.nospace() << cm; 0071 }, cm.message); 0072 return out; 0073 } 0074 0075 0076 0077 } // namespace blade 0078 0079 #endif // include guard 0080