From e62f3e7647e45927c1e52fe8a96eba85a043f33f Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Wed, 11 Apr 2018 00:35:16 +0100 Subject: [PATCH] protocol: Implement a DML-based Session --- include/ki/protocol/dml/Session.h | 26 ++++++++++++++++++++++++++ src/protocol/CMakeLists.txt | 1 + src/protocol/dml/Session.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 include/ki/protocol/dml/Session.h create mode 100644 src/protocol/dml/Session.cpp diff --git a/include/ki/protocol/dml/Session.h b/include/ki/protocol/dml/Session.h new file mode 100644 index 0000000..a48120e --- /dev/null +++ b/include/ki/protocol/dml/Session.h @@ -0,0 +1,26 @@ +#pragma once +#include "../net/Session.h" +#include "MessageManager.h" + +namespace ki +{ +namespace protocol +{ +namespace dml +{ + class Session : public net::Session + { + public: + Session(net::ParticipantType type, uint16_t id, + const MessageManager &manager); + ~Session() = default; + protected: + void on_application_message(const net::PacketHeader& header) override; + virtual void on_message(const Message &message) {} + virtual void on_invalid_message() {} + private: + const MessageManager &m_manager; + }; +} +} +} \ No newline at end of file diff --git a/src/protocol/CMakeLists.txt b/src/protocol/CMakeLists.txt index e59aea3..660ab30 100644 --- a/src/protocol/CMakeLists.txt +++ b/src/protocol/CMakeLists.txt @@ -8,6 +8,7 @@ target_sources(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/src/protocol/dml/MessageManager.cpp ${PROJECT_SOURCE_DIR}/src/protocol/dml/MessageModule.cpp ${PROJECT_SOURCE_DIR}/src/protocol/dml/MessageTemplate.cpp + ${PROJECT_SOURCE_DIR}/src/protocol/dml/Session.cpp ${PROJECT_SOURCE_DIR}/src/protocol/net/PacketHeader.cpp ${PROJECT_SOURCE_DIR}/src/protocol/net/Participant.cpp ${PROJECT_SOURCE_DIR}/src/protocol/net/Session.cpp diff --git a/src/protocol/dml/Session.cpp b/src/protocol/dml/Session.cpp new file mode 100644 index 0000000..fc513b6 --- /dev/null +++ b/src/protocol/dml/Session.cpp @@ -0,0 +1,27 @@ +#include "ki/protocol/dml/Session.h" + +namespace ki +{ +namespace protocol +{ +namespace dml +{ + Session::Session(const net::ParticipantType type, const uint16_t id, + const MessageManager& manager) + : net::Session(type, id), m_manager(manager) {} + + void Session::on_application_message(const net::PacketHeader& header) + { + const auto *message = m_manager.message_from_binary(m_data_stream); + if (!message) + { + on_invalid_message(); + return; + } + + on_message(*message); + delete message; + } +} +} +} \ No newline at end of file