aboutsummaryrefslogtreecommitdiff
path: root/server-v1/source/EpistmoolServer/Protocol/Command.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-27 00:13:08 +0000
committerrtk0c <[email protected]>2022-06-27 00:13:08 +0000
commit8a23aa89a58d3a90d5851b449b5552e1fcdcaded (patch)
tree86a527705eafe1ba36d6d5744afeddad196c0eeb /server-v1/source/EpistmoolServer/Protocol/Command.hpp
parent9ad9af9f2596b91e1dd65e71543f75b0644e8283 (diff)
(From git) Initial server setup
git-svn-id: file:///home/arch/svn/epistmool/trunk@4 71f44415-077c-4ad7-a976-72ddbf76608f
Diffstat (limited to 'server-v1/source/EpistmoolServer/Protocol/Command.hpp')
-rw-r--r--server-v1/source/EpistmoolServer/Protocol/Command.hpp124
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