mirror of https://github.com/SeanOMik/libki.git
protocol: Implement a DML-based Session
This commit is contained in:
parent
70679afed1
commit
e62f3e7647
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue