Files
Simple-Protocol-Lib/include/sp/protocol/Dispatcher.h
2025-02-04 19:11:03 +01:00

61 lines
1.2 KiB
C++

#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"