protocol: Implement a DML-based Session

This commit is contained in:
Joshua Scott 2018-04-11 00:35:16 +01:00
parent 70679afed1
commit e62f3e7647
3 changed files with 54 additions and 0 deletions

View File

@ -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;
};
}
}
}

View File

@ -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

View File

@ -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;
}
}
}
}