diff options
Diffstat (limited to 'server-v1/source/EpistmoolServer/Protocol/Command.hpp')
-rw-r--r-- | server-v1/source/EpistmoolServer/Protocol/Command.hpp | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/server-v1/source/EpistmoolServer/Protocol/Command.hpp b/server-v1/source/EpistmoolServer/Protocol/Command.hpp new file mode 100644 index 0000000..9ec9786 --- /dev/null +++ b/server-v1/source/EpistmoolServer/Protocol/Command.hpp @@ -0,0 +1,124 @@ +#pragma once + +#include "all_fwd.hpp" + +#include <QLatin1String> +#include <QVersionNumber> +#include <cstddef> +#include <memory> + +class QJsonObject; + +namespace Epistmool::Server { + +// Note: not all message kinds have a corresponding reply format. In such case the Kind enum is prefixed with 'Notification'. +class ProtocolMessage +{ + Q_GADGET + +public: + struct KindTrait + { + bool isC2S; + bool hasReply; + }; + + enum Kind + { + SessionAuth, + SessionDestroy, + + WorkspaceCreate, + WorkspaceOpen, + WorkspaceFetchIndex, + + WorkspaceFetchKnowledge, + WorkspaceUpdateKnowledge, + WorkspaceCreateKnowledge, + WorkspaceDeleteKnowledge, + + WorkspaceFetchKeyword, + WorkspaceUpdateKeyword, + WorkspaceCreateKeyword, + WorkspaceDeleteKeyword, + + NotificationWorkspaceUpdated, + NotificationKnowledgeUpdated, + + KindCOUNT, + }; + Q_ENUM(Kind) + + static std::unique_ptr<ProtocolRequest> createRequest(Kind kind); + static std::unique_ptr<ProtocolReply> createReply(Kind kind); + static const KindTrait& getKindTrait(Kind kind); + + enum Variant + { + RequestVariant, + ReplyVariant, + }; + Q_ENUM(Variant) + +public: + Kind kind; + Variant variant; + +public: + ProtocolMessage(Kind kind, Variant variant); + virtual ~ProtocolMessage() = default; + +protected: + virtual void serializeFields(QJsonObject& object) const = 0; + virtual void deserializeFields(const QJsonObject& object) = 0; +}; + +struct ProtocolRequest : public ProtocolMessage +{ + ProtocolRequest(Kind kind); + static QJsonObject serialize(const ProtocolRequest& msg); + static std::unique_ptr<ProtocolRequest> deserialize(const QJsonObject& object); +}; + +struct ProtocolReply : public ProtocolMessage +{ + int sequence; + + ProtocolReply(Kind kind); + static QJsonObject serialize(const ProtocolReply& msg); + static std::unique_ptr<ProtocolReply> deserialize(const QJsonObject& object); +}; + +// =========================== +// Individual messages classes + +struct ProtocolRequest_SessionAuth : public ProtocolRequest +{ + int theSession; + bool createIfInvalid; + + ProtocolRequest_SessionAuth(); + +protected: + virtual void serializeFields(QJsonObject& object) const override; + virtual void deserializeFields(const QJsonObject& object) override; +}; + +struct ProtocolReply_SessionAuth : public ProtocolReply +{ + /// The same value as provided in the request message. + /// If \l ProcotolCommandSessionAuth::createIfValid is set and the given session is invalid, a new session is created and written here instead of the original value. + int theSession; + + ProtocolReply_SessionAuth(); + +protected: + virtual void serializeFields(QJsonObject& object) const override; + virtual void deserializeFields(const QJsonObject& object) override; +}; + +struct ProtocolNotification_WorkspaceUpdate : public ProtocolRequest +{ +}; + +} // namespace Epistmool::Server |