add MessageDispatcher
This commit is contained in:
54
include/sp/protocol/MessageDispatcher.h
Normal file
54
include/sp/protocol/MessageDispatcher.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* \file MessageDispatcher.h
|
||||
* \brief File containing the sp::MessageDispatcher class
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace sp {
|
||||
|
||||
/**
|
||||
* \class MessageDispatcher
|
||||
* \brief Class used to dispatch messages
|
||||
*/
|
||||
template <typename MessageIdType, typename MessageBase, typename MessageHandler>
|
||||
class MessageDispatcher {
|
||||
private:
|
||||
std::map<MessageIdType, std::vector<std::shared_ptr<MessageHandler>>> m_Handlers;
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Constructor
|
||||
*/
|
||||
MessageDispatcher() {}
|
||||
|
||||
/**
|
||||
* \brief Dispatch a packet
|
||||
* \param packet The packet to dispatch
|
||||
*/
|
||||
void Dispatch(const MessageBase& a_Message);
|
||||
|
||||
/**
|
||||
* \brief Register a packet handler
|
||||
* \param type The packet type
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void RegisterHandler(MessageIdType a_MessageType, const std::shared_ptr<MessageHandler>& a_Handler);
|
||||
/**
|
||||
* \brief Unregister a packet handler
|
||||
* \param type The packet type
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void UnregisterHandler(MessageIdType a_MessageType, const std::shared_ptr<MessageHandler>& a_Handler);
|
||||
/**
|
||||
* \brief Unregister a packet handler
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void UnregisterHandler(const std::shared_ptr<MessageHandler>& a_Handler);
|
||||
};
|
||||
|
||||
#include <sp/protocol/message/MessageDispatcherImpl.inl>
|
||||
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user