first commit
This commit is contained in:
61
include/sp/protocol/Dispatcher.h
Normal file
61
include/sp/protocol/Dispatcher.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* \file PacketDispatcher.h
|
||||
* \brief File containing the sp::protocol::PacketDispatcher class
|
||||
*/
|
||||
|
||||
#include <sp/common/NonCopyable.h>
|
||||
#include <sp/protocol/packet/Packets.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace sp {
|
||||
namespace protocol {
|
||||
|
||||
/**
|
||||
* \class Dispatcher
|
||||
* \brief Class used to dispatch things
|
||||
*/
|
||||
template <typename T_Enum, typename T_Handler, typename T>
|
||||
class Dispatcher : private NonCopyable {
|
||||
private:
|
||||
std::map<T_Enum, std::vector<T_Handler*>> m_Handlers;
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Constructor
|
||||
*/
|
||||
Dispatcher() {}
|
||||
|
||||
/**
|
||||
* \brief Dispatch a packet
|
||||
* \param packet The packet to dispatch
|
||||
*/
|
||||
void Dispatch(const T& packet);
|
||||
|
||||
/**
|
||||
* \brief Register a packet handler
|
||||
* \param type The packet type
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void RegisterHandler(T_Enum type, T_Handler& handler);
|
||||
|
||||
/**
|
||||
* \brief Unregister a packet handler
|
||||
* \param type The packet type
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void UnregisterHandler(T_Enum type, T_Handler& handler);
|
||||
|
||||
/**
|
||||
* \brief Unregister a packet handler
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void UnregisterHandler(T_Handler& handler);
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace sp
|
||||
|
||||
#include "Dispatcher.inl"
|
||||
Reference in New Issue
Block a user