1 /*! 2 * \brief Base of all messages of JSON API. 3 * 4 * \copyright Copyright (c) 2016-2021 Governikus GmbH & Co. KG, Germany 5 */ 6 7 #pragma once 8 9 #include "MsgTypes.h" 10 #include "SmartCardDefinitions.h" 11 12 #include <QJsonObject> 13 14 namespace governikus 15 { 16 class MsgHandler 17 { 18 private: 19 const MsgType mType; 20 bool mVoid; 21 22 MsgHandler(); 23 24 protected: 25 QJsonObject mJsonObject; 26 27 explicit MsgHandler(MsgType pType); 28 explicit MsgHandler(MsgType pType, const char* const pKey, const QString& pValue); 29 explicit MsgHandler(MsgType pType, const char* const pKey, const QLatin1String pValue); 30 31 void setValue(const QLatin1String pKey, const QString& pValue); 32 void setValue(const char* const pKey, const QString& pValue); 33 void setValue(const QLatin1String pKey, const QLatin1String pValue); 34 void setValue(const char* const pKey, const QLatin1String pValue); 35 36 void setVoid(bool pVoid = true); 37 38 public: 39 static const MsgHandler Void; 40 static const MsgLevel DEFAULT_MSG_LEVEL; 41 static MsgType getStateMsgType(const QString& pState, PacePasswordId pPasswordId); 42 43 [[nodiscard]] QByteArray toJson() const; 44 [[nodiscard]] QByteArray getOutput() const; 45 [[nodiscard]] bool isVoid() const; 46 [[nodiscard]] MsgType getType() const; 47 48 void setRequest(const QJsonObject& pRequest); 49 }; 50 51 inline QDebug operator<<(QDebug pDbg, const MsgHandler& pMsg) 52 { 53 QDebugStateSaver saver(pDbg); 54 pDbg << pMsg.getType(); 55 return pDbg.space(); 56 } 57 58 59 } // namespace governikus 60