/** * @RDE_HEADER@ * LTS web socket server - Abstract Reply Message and Reply Handler * $Id$ * $HeadURL$ * $Author$ * Created by Philipp Dassow, SLST, 2017-11-28 */ #pragma once #include #include #include #include namespace LtsWebSocket { /** * @brief Base class for reply messages */ class LTSWEBSOCKETCOMMON_EXPORT ReplyMessage { public: /** * @brief ~ReplyMessage Destructor */ virtual ~ReplyMessage() = default; /** * @brief toJsonString Converts this message into a valid JSON string * @return QString JSON representation of this class */ virtual QString toJsonString() const; QJsonObject json() const { return m_jsonRepresentation; } protected: // methods ReplyMessage() = default; ReplyMessage(const QString &type, const int typeId, const QString &uuid); protected: // attributes QJsonObject m_jsonRepresentation; }; // class ReplyMessage /** * @brief The ReplyHandler Interface offers an extremely lightweight API for a class to just write textmessages to */ class LTSWEBSOCKETCOMMON_EXPORT ReplyHandler { public: virtual ~ReplyHandler() = default; /** * @brief addReply Method to write a textmessage via this MessageTransmitter * @param message Message to send */ virtual void addReply(ReplyMessage *message) = 0; }; // class ReplyHandler // #################### basic error messages #################### /** * @brief The ErrorMessage class is sent when any data from a client could not be processed */ class LTSWEBSOCKETCOMMON_EXPORT ErrorMessage final : public ReplyMessage { public: /** * @brief The ErrorData struct represents the data part of an ErrorMessage object */ struct ErrorData { int errorClass = 0; QString uuid; QString errorMessage; }; /** * @brief ErrorMessage Constructor * @param data Data part of an ErrorMessage object */ explicit ErrorMessage(const ErrorData &data); }; // class ErrorMessage } // namespace LtsWebSocket