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